PostGIS  2.3.8dev-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 #if POSTGIS_GEOS_VERSION >= 34
66  GEOS_interruptRegisterCallback(interruptCallback);
67 #endif
68  lwgeom_register_interrupt_callback(interruptCallback);
69 #endif
70 
71 #if 0
72  /* Define custom GUC variables. */
73  DefineCustomIntVariable(
74  "postgis.debug.level", /* name */
75  "Sets the debugging level of PostGIS.", /* short_desc */
76  "This is an experimental configuration.", /* long_desc */
77  &postgis_debug_level, /* valueAddr */
78  0, 8, /* min-max */
79  0, /* bootValue */
80  PGC_SUSET, /* GucContext context */
81  GUC_UNIT_MS, /* int flags */
82 #if POSTGIS_PGSQL_VERSION >= 91
83  NULL, /* GucStringCheckHook check_hook */
84 #endif
85  NULL, /* GucStringAssignHook assign_hook */
86  NULL /* GucShowHook show_hook */
87  );
88 #endif
89 
90 #if 0
91  /* Define custom GUC variables. */
92  DefineCustomStringVariable(
93  "postgis.greeting.string", /* name */
94  "Sets the greeting string used on postgis module load.", /* short_desc */
95  "This is an experimental configuration.", /* long_desc */
96  &greeting, /* valueAddr */
97  "Welcome to PostGIS " POSTGIS_VERSION, /* bootValue */
98  PGC_SUSET, /* GucContext context */
99  GUC_UNIT_MS, /* int flags */
100 #if POSTGIS_PGSQL_VERSION >= 91
101  NULL, /* GucStringCheckHook check_hook */
102 #endif
103  NULL, /* GucStringAssignHook assign_hook */
104  NULL /* GucShowHook show_hook */
105  );
106 #endif
107 
108  /* install PostgreSQL handlers */
109  pg_install_lwgeom_handlers();
110 
111  /* initialize geometry backend */
113 }
114 
115 /*
116  * Module unload callback
117  */
118 void _PG_fini(void);
119 void
120 _PG_fini(void)
121 {
122  elog(NOTICE, "Goodbye from PostGIS %s", POSTGIS_VERSION);
123  pqsignal(SIGINT, coreIntHandler);
124 }
125 
126 
127 static void
129 {
130  /* NOTE: printf here would be dangerous, see
131  * https://trac.osgeo.org/postgis/ticket/3644
132  *
133  * TODO: block interrupts during execution, to fix the problem
134  */
135  /* printf("Interrupt requested\n"); fflush(stdout); */
136 
137 #if POSTGIS_GEOS_VERSION >= 34
138  GEOS_interruptRequest();
139 #endif
140 
141  /* request interruption of liblwgeom as well */
143 
144  if ( coreIntHandler ) {
145  (*coreIntHandler)(sig);
146  }
147 }
static pqsigfunc coreIntHandler
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:837
void _PG_fini(void)
void lwgeom_init_backend()
#define POSTGIS_PGSQL_VERSION
Definition: sqldefines.h:9
void _PG_init(void)
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:847
PG_MODULE_MAGIC
static void handleInterrupt(int sig)