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