shutdown.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*!
  2. * \file db/dbmi_client/shutdown.c
  3. *
  4. * \brief DBMI Library (client) - shutdown database connection
  5. *
  6. * (C) 1999-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. * \author Joel Jones (CERL/UIUC), Radim Blazek
  13. */
  14. #include <stdlib.h>
  15. #ifdef __MINGW32__
  16. #include <process.h>
  17. #else
  18. #include <sys/wait.h>
  19. #endif
  20. #include <grass/dbmi.h>
  21. #include <grass/spawn.h>
  22. #include "macros.h"
  23. /*!
  24. \brief Closedown the driver, and free the driver structure
  25. <b>Note:</b> the management of the memory for the driver structure
  26. probably should be handled differently.
  27. db_start_driver() could take a pointer to driver structure as an
  28. argument, instead of returning the pointer to allocated then there
  29. would be no hidden free required
  30. \param driver pointer to dbDriver to be freed
  31. \return 0 on sucess
  32. \return -1 on error
  33. */
  34. int db_shutdown_driver(dbDriver * driver)
  35. {
  36. int status;
  37. #ifdef __MINGW32__
  38. db__set_protocol_fds(driver->send, driver->recv);
  39. DB_START_PROCEDURE_CALL(DB_PROC_SHUTDOWN_DRIVER);
  40. #endif
  41. /* close the communication FILEs */
  42. fclose(driver->send);
  43. fclose(driver->recv);
  44. driver->send = NULL;
  45. driver->recv = NULL;
  46. /* wait for the driver to finish */
  47. status = -1;
  48. /* convert status according to return code of G_wait() */
  49. status = G_wait(driver->pid) == -1 ? -1 : 0;
  50. driver->pid = 0;
  51. /* free the driver structure. THIS IS GOOFY */
  52. db_free(driver);
  53. return status;
  54. }