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