shutdown.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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
  28. an argument, instead of returning the pointer to allocated
  29. then there would be no hidden free required
  30. \param driver db driver
  31. \return status (?)
  32. */
  33. int db_shutdown_driver(dbDriver * driver)
  34. {
  35. int status;
  36. #ifdef __MINGW32__
  37. db__set_protocol_fds(driver->send, driver->recv);
  38. DB_START_PROCEDURE_CALL(DB_PROC_SHUTDOWN_DRIVER);
  39. #endif
  40. /* close the communication FILEs */
  41. fclose(driver->send);
  42. fclose(driver->recv);
  43. driver->send = NULL;
  44. driver->recv = NULL;
  45. /* wait for the driver to finish */
  46. status = -1;
  47. /* convert status according to return code of G_wait() */
  48. status = G_wait(driver->pid) == -1 ? -1 : 0;
  49. driver->pid = 0;
  50. /* free the driver structure. THIS IS GOOFY */
  51. db_free(driver);
  52. return status;
  53. }