shutdown.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 #include <sys/types.h>
00003 #include <sys/wait.h>
00004 #include "dbmi.h"
00005 
00012 /* closedown the driver, and free the driver structure */
00013 /* NOTE: the management of the memory for the driver structure
00014  * probably should be handled differently.
00015  *
00016  * db_start_driver() could take a pointer to driver structure as
00017  * an argument, instead of returning the pointer to allocated
00018  * then there would be no hidden free required
00019  */
00020 db_shutdown_driver (driver)
00021     dbDriver *driver;
00022 {
00023     int pid;
00024     int status;
00025 
00026 /* close the communication FILEs */
00027     fclose (driver->send);
00028     fclose (driver->recv);
00029 
00030     driver->send = NULL;
00031     driver->recv = NULL;
00032 
00033 /* wait for the driver to finish */
00034     status = -1;
00035     while ((pid = wait(&status)) > 0 && pid != driver->pid)
00036          {}
00037 
00038     driver->pid = 0;
00039 
00040 /* free the driver structure. THIS IS GOOFY */
00041     free (driver);
00042 
00043     return status;
00044 }

Generated on Mon Jan 1 19:49:05 2007 for GRASS by  doxygen 1.5.1