shutdown.c

Go to the documentation of this file.
00001 #include <stdlib.h>
00002 
00003 #ifdef __MINGW32__
00004 #include <process.h>
00005 #else
00006 #include <sys/wait.h>
00007 #endif
00008 #include <grass/dbmi.h>
00009 #include "macros.h"
00010 
00017 /* closedown the driver, and free the driver structure */
00018 /* NOTE: the management of the memory for the driver structure
00019  * probably should be handled differently.
00020  *
00021  * db_start_driver() could take a pointer to driver structure as
00022  * an argument, instead of returning the pointer to allocated
00023  * then there would be no hidden free required
00024  */
00025 db_shutdown_driver  (dbDriver *driver)
00026 
00027 {
00028     int pid;
00029     int status;
00030 
00031 #ifdef __MINGW32__
00032     db__set_protocol_fds (driver->send, driver->recv);
00033     DB_START_PROCEDURE_CALL (DB_PROC_SHUTDOWN_DRIVER);
00034 #endif
00035 
00036 /* close the communication FILEs */
00037     fclose (driver->send);
00038     fclose (driver->recv);
00039 
00040     driver->send = NULL;
00041     driver->recv = NULL;
00042 
00043 /* wait for the driver to finish */
00044     status = -1;
00045 
00046 #ifdef __MINGW32__
00047     /* TODO: convert status to something like from wait? */
00048     _cwait( &status, driver->pid, WAIT_CHILD ); 
00049 #else
00050     /* TODO: Should not be here waitpid() ? */
00051     while ((pid = wait(&status)) > 0 && pid != driver->pid)
00052          {}
00053 #endif
00054 
00055     driver->pid = 0;
00056 
00057 /* free the driver structure. THIS IS GOOFY */
00058     free (driver);
00059 
00060     return status;
00061 }

Generated on Sun Apr 6 17:31:38 2008 for GRASS by  doxygen 1.5.5