PostGIS  3.4.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 "executor/executor.h"
29 #include "utils/elog.h"
30 #include "utils/guc.h"
31 #include "libpq/pqsignal.h"
32 
33 #include "../postgis_config.h"
34 
35 #include "lwgeom_log.h"
36 #include "lwgeom_pg.h"
37 #include "geos_c.h"
38 
39 #ifdef HAVE_LIBPROTOBUF
40 #include "lwgeom_wagyu.h"
41 #endif
42 
43 /*
44  * This is required for builds against pgsql
45  */
47 
48 static pqsigfunc coreIntHandler = 0;
49 static void handleInterrupt(int sig);
50 
51 #ifdef WIN32
52 static void interruptCallback() {
53  if (UNBLOCKED_SIGNAL_QUEUE())
54  pgwin32_dispatch_queued_signals();
55 }
56 #endif
57 
58 static ExecutorStart_hook_type onExecutorStartPrev = NULL;
59 static void onExecutorStart(QueryDesc *queryDesc, int eflags);
60 
61 /*
62 * Pass proj error message out via the PostgreSQL logging
63 * system instead of letting them default into the
64 * stderr.
65 */
66 #if POSTGIS_PROJ_VERSION > 60
67 #include "proj.h"
68 
69 static void
70 pjLogFunction(void* data, int logLevel, const char* message)
71 {
72  elog(DEBUG1, "libproj threw an exception (%d): %s", logLevel, message);
73 }
74 #endif
75 
76 /*
77  * Module load callback
78  */
79 void _PG_init(void);
80 void
81 _PG_init(void)
82 {
83  coreIntHandler = pqsignal(SIGINT, handleInterrupt);
84 
85 #ifdef WIN32
86  GEOS_interruptRegisterCallback(interruptCallback);
87  lwgeom_register_interrupt_callback(interruptCallback);
88 #endif
89 
90  /* install PostgreSQL handlers */
91  pg_install_lwgeom_handlers();
92 
93  /* pass proj messages through the pgsql error handler */
94 #if POSTGIS_PROJ_VERSION > 60
95  proj_log_func(NULL, NULL, pjLogFunction);
96 #endif
97 
98  /* setup hooks */
99  onExecutorStartPrev = ExecutorStart_hook;
100  ExecutorStart_hook = onExecutorStart;
101 }
102 
103 /*
104  * Module unload callback
105  */
106 void _PG_fini(void);
107 void
108 _PG_fini(void)
109 {
110  elog(NOTICE, "Goodbye from PostGIS %s", POSTGIS_VERSION);
111  pqsignal(SIGINT, coreIntHandler);
112 
113  /* restore original hooks */
114  ExecutorStart_hook = onExecutorStartPrev;
115 }
116 
117 
118 static void
120 {
121  /* NOTE: printf here would be dangerous, see
122  * https://trac.osgeo.org/postgis/ticket/3644
123  *
124  * TODO: block interrupts during execution, to fix the problem
125  */
126  /* printf("Interrupt requested\n"); fflush(stdout); */
127 
128  GEOS_interruptRequest();
129 
130 #ifdef HAVE_LIBPROTOBUF
131  /* Taking out per #5385 crash */
132  //lwgeom_wagyu_interruptRequest();
133 #endif
134 
135  /* request interruption of liblwgeom as well */
137 
138  if ( coreIntHandler ) {
139  (*coreIntHandler)(sig);
140  }
141 }
142 
143 static void onExecutorStart(QueryDesc *queryDesc, int eflags) {
144  /* cancel interrupt requests */
145 
146  GEOS_interruptCancel();
147 
148 #ifdef HAVE_LIBPROTOBUF
149  /* Taking out per #5385 crash */
150  //lwgeom_wagyu_interruptReset();
151 #endif
152 
154 
155  if (onExecutorStartPrev) {
156  (*onExecutorStartPrev)(queryDesc, eflags);
157  } else {
158  standard_ExecutorStart(queryDesc, eflags);
159  }
160 }
void lwgeom_request_interrupt(void)
Request interruption of any running code.
Definition: lwgeom_api.c:663
void lwgeom_cancel_interrupt(void)
Cancel any interruption request.
Definition: lwgeom_api.c:667
lwinterrupt_callback * lwgeom_register_interrupt_callback(lwinterrupt_callback *)
Definition: lwgeom_api.c:673
data
Definition: ovdump.py:104
static ExecutorStart_hook_type onExecutorStartPrev
static void handleInterrupt(int sig)
void _PG_init(void)
PG_MODULE_MAGIC
void _PG_fini(void)
static pqsigfunc coreIntHandler
static void onExecutorStart(QueryDesc *queryDesc, int eflags)
static void pjLogFunction(void *data, int logLevel, const char *message)