GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-d6dec75dd4
shutdown.c
Go to the documentation of this file.
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 
15 #include <stdlib.h>
16 
17 #include <grass/dbmi.h>
18 #include <grass/spawn.h>
19 #include "macros.h"
20 
21 /*!
22  \brief Closedown the driver, and free the driver structure
23 
24  <b>Note:</b> the management of the memory for the driver structure
25  probably should be handled differently.
26 
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 
31  \param driver pointer to dbDriver to be freed
32 
33  \return 0 on success
34  \return -1 on error
35  */
37 {
38  int status;
39 
40  db__set_protocol_fds(driver->send, driver->recv);
42 
43  /* close the communication FILEs */
44  fclose(driver->send);
45  fclose(driver->recv);
46 
47  driver->send = NULL;
48  driver->recv = NULL;
49 
50  /* wait for the driver to finish */
51  status = -1;
52 
53  /* convert status according to return code of G_wait() */
54  status = G_wait(driver->pid) == -1 ? -1 : 0;
55 
56  driver->pid = 0;
57 
58  /* remove also error handler if defined */
60 
61  /* free the driver structure. THIS IS GOOFY */
62  db_free(driver);
63 
64  return status;
65 }
#define NULL
Definition: ccmath.h:32
#define DB_PROC_SHUTDOWN_DRIVER
Definition: dbmi.h:35
void db_free(void *)
Free allocated memory.
void db__set_protocol_fds(FILE *, FILE *)
?
void db_unset_error_handler_driver(dbDriver *)
Remove error handler before closing the driver.
int G_wait(int i_pid)
Definition: spawn.c:949
#define DB_START_PROCEDURE_CALL(x)
Definition: macros.h:2
int db_shutdown_driver(dbDriver *driver)
Closedown the driver, and free the driver structure.
Definition: shutdown.c:36
Definition: driver.h:21