shutdown.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #include <grass/dbmi.h>
  16. #include <grass/spawn.h>
  17. #include "macros.h"
  18. /*!
  19. \brief Closedown the driver, and free the driver structure
  20. <b>Note:</b> the management of the memory for the driver structure
  21. probably should be handled differently.
  22. db_start_driver() could take a pointer to driver structure as an
  23. argument, instead of returning the pointer to allocated then there
  24. would be no hidden free required
  25. \param driver pointer to dbDriver to be freed
  26. \return 0 on success
  27. \return -1 on error
  28. */
  29. int db_shutdown_driver(dbDriver * driver)
  30. {
  31. int status;
  32. db__set_protocol_fds(driver->send, driver->recv);
  33. DB_START_PROCEDURE_CALL(DB_PROC_SHUTDOWN_DRIVER);
  34. /* close the communication FILEs */
  35. fclose(driver->send);
  36. fclose(driver->recv);
  37. driver->send = NULL;
  38. driver->recv = NULL;
  39. /* wait for the driver to finish */
  40. status = -1;
  41. /* convert status according to return code of G_wait() */
  42. status = G_wait(driver->pid) == -1 ? -1 : 0;
  43. driver->pid = 0;
  44. /* remove also error handler if defined */
  45. db_unset_error_handler_driver(driver);
  46. /* free the driver structure. THIS IS GOOFY */
  47. db_free(driver);
  48. return status;
  49. }