PostGIS  2.5.7dev-r@@SVN_REVISION@@
postgis_module.c
Go to the documentation of this file.
1 /**********************************************************************
2  *
3  * PostGIS - Spatial Types for PostgreSQL
4  * http://postgis.net
5  *
6  * PostGIS is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * PostGIS is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with PostGIS. If not, see <http://www.gnu.org/licenses/>.
18  *
19  **********************************************************************
20  *
21  * Copyright (C) 2011 OpenGeo.org
22  *
23  **********************************************************************/
24 
25 
26 #include "postgres.h"
27 #include "fmgr.h"
28 #include "utils/elog.h"
29 #include "utils/guc.h"
30 #include "libpq/pqsignal.h"
31 
32 #include "../postgis_config.h"
33 
34 #include "lwgeom_log.h"
35 #include "lwgeom_pg.h"
36 #include "geos_c.h"
37 #include "lwgeom_backend_api.h"
38 
39 /*
40  * This is required for builds against pgsql
41  */
43 
44 static pqsigfunc coreIntHandler = 0;
45 static void handleInterrupt(int sig);
46 
47 #ifdef WIN32
48 static void interruptCallback() {
49  if (UNBLOCKED_SIGNAL_QUEUE())
50  pgwin32_dispatch_queued_signals();
51 }
52 #endif
53 
54 /*
55  * Module load callback
56  */
57 void _PG_init(void);
58 void
59 _PG_init(void)
60 {
61 
62  coreIntHandler = pqsignal(SIGINT, handleInterrupt);
63 
64 #ifdef WIN32
65  GEOS_interruptRegisterCallback(interruptCallback);
66  lwgeom_register_interrupt_callback(interruptCallback);
67 #endif
68 
69  /* install PostgreSQL handlers */
70  pg_install_lwgeom_handlers();
71 
72  /* initialize geometry backend */
74 }
75 
76 /*
77  * Module unload callback
78  */
79 void _PG_fini(void);
80 void
81 _PG_fini(void)
82 {
83  elog(NOTICE, "Goodbye from PostGIS %s", POSTGIS_VERSION);
84  pqsignal(SIGINT, coreIntHandler);
85 }
86 
87 
88 static void
90 {
91  /* NOTE: printf here would be dangerous, see
92  * https://trac.osgeo.org/postgis/ticket/3644
93  *
94  * TODO: block interrupts during execution, to fix the problem
95  */
96  /* printf("Interrupt requested\n"); fflush(stdout); */
97 
98  GEOS_interruptRequest();
99 
100  /* request interruption of liblwgeom as well */
102 
103  if ( coreIntHandler ) {
104  (*coreIntHandler)(sig);
105  }
106 }
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:728
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:738
void lwgeom_init_backend()
static void handleInterrupt(int sig)
void _PG_init(void)
PG_MODULE_MAGIC
void _PG_fini(void)
static pqsigfunc coreIntHandler