shutdown.c

Go to the documentation of this file.
00001 
00015 #include <stdlib.h>
00016 
00017 #ifdef __MINGW32__
00018 #include <process.h>
00019 #else
00020 #include <sys/wait.h>
00021 #endif
00022 #include <grass/dbmi.h>
00023 #include "macros.h"
00024 
00039 int db_shutdown_driver(dbDriver * driver)
00040 {
00041 #ifndef __MINGW32__
00042     int pid;
00043 #endif
00044     int status;
00045 
00046 #ifdef __MINGW32__
00047     db__set_protocol_fds(driver->send, driver->recv);
00048     DB_START_PROCEDURE_CALL(DB_PROC_SHUTDOWN_DRIVER);
00049 #endif
00050 
00051     /* close the communication FILEs */
00052     fclose(driver->send);
00053     fclose(driver->recv);
00054 
00055     driver->send = NULL;
00056     driver->recv = NULL;
00057 
00058     /* wait for the driver to finish */
00059     status = -1;
00060 
00061 #ifdef __MINGW32__
00062     /* TODO: convert status to something like from wait? */
00063     _cwait(&status, driver->pid, WAIT_CHILD);
00064 #else
00065     /* TODO: Should not be here waitpid() ? */
00066     while ((pid = wait(&status)) > 0 && pid != driver->pid) {
00067     }
00068 #endif
00069 
00070     driver->pid = 0;
00071 
00072     /* free the driver structure. THIS IS GOOFY */
00073     free(driver);
00074 
00075     return status;
00076 }

Generated on Sat Oct 24 03:24:24 2009 for GRASS Programmer's Manual by  doxygen 1.6.1