Fossil SCM

Backoffice processing improvements: Set a timer on the backoffice to prevent it from running too long. Report errors on failed attempts to open /dev/null. Use "NUL" instead of "/dev/null" on Windows.

drh 2018-07-30 13:25 trunk
Commit 07356e44c1a8cf7bee5617dfb692bb3f9149899ffe8ea7dbcaf2f9df259b8514
--- src/backoffice.c
+++ src/backoffice.c
@@ -42,10 +42,11 @@
4242
#include "backoffice.h"
4343
#include <time.h>
4444
#if defined(_WIN32)
4545
# include <windows.h>
4646
#else
47
+# include <unistd.h>
4748
# include <sys/types.h>
4849
# include <signal.h>
4950
#endif
5051
5152
/*
@@ -164,10 +165,28 @@
164165
return (sqlite3_uint64)GetCurrentProcessId();
165166
#else
166167
return (sqlite3_uint64)getpid();
167168
#endif
168169
}
170
+
171
+/*
172
+** Set an alarm to cause the process to exit after "x" seconds. This
173
+** prevents any kind of bug from keeping a backoffice process running
174
+** indefinitely.
175
+*/
176
+#if !defined(_WIN32)
177
+static void backofficeSigalrmHandler(int x){
178
+ fossil_panic("backoffice timeout");
179
+}
180
+#endif
181
+static void backofficeTimeout(int x){
182
+#if !defined(_WIN32)
183
+ signal(SIGALRM, backofficeSigalrmHandler);
184
+ alarm(x);
185
+#endif
186
+}
187
+
169188
170189
/*
171190
** COMMAND: test-process-id
172191
**
173192
** Usage: %fossil [--sleep N] PROCESS-ID ...
@@ -214,10 +233,11 @@
214233
}
215234
if( db_transaction_nesting_depth()!=0 ){
216235
fossil_panic("transaction %s not closed prior to backoffice processing",
217236
db_transaction_start_point());
218237
}
238
+ backofficeTimeout(BKOFCE_LEASE_TIME*2);
219239
idSelf = backofficeProcessId();
220240
while(1){
221241
tmNow = time(0);
222242
db_begin_write();
223243
backofficeReadLease(&x);
@@ -257,10 +277,13 @@
257277
** to expire before continuing. */
258278
x.idNext = idSelf;
259279
x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
260280
backofficeWriteLease(&x);
261281
db_end_transaction(0);
282
+ if( g.fAnyTrace ){
283
+ fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid());
284
+ }
262285
if( x.tmCurrent >= tmNow ){
263286
sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1));
264287
}else{
265288
if( lastWarning+warningDelay < tmNow ){
266289
fossil_warning(
267290
--- src/backoffice.c
+++ src/backoffice.c
@@ -42,10 +42,11 @@
42 #include "backoffice.h"
43 #include <time.h>
44 #if defined(_WIN32)
45 # include <windows.h>
46 #else
 
47 # include <sys/types.h>
48 # include <signal.h>
49 #endif
50
51 /*
@@ -164,10 +165,28 @@
164 return (sqlite3_uint64)GetCurrentProcessId();
165 #else
166 return (sqlite3_uint64)getpid();
167 #endif
168 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
170 /*
171 ** COMMAND: test-process-id
172 **
173 ** Usage: %fossil [--sleep N] PROCESS-ID ...
@@ -214,10 +233,11 @@
214 }
215 if( db_transaction_nesting_depth()!=0 ){
216 fossil_panic("transaction %s not closed prior to backoffice processing",
217 db_transaction_start_point());
218 }
 
219 idSelf = backofficeProcessId();
220 while(1){
221 tmNow = time(0);
222 db_begin_write();
223 backofficeReadLease(&x);
@@ -257,10 +277,13 @@
257 ** to expire before continuing. */
258 x.idNext = idSelf;
259 x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
260 backofficeWriteLease(&x);
261 db_end_transaction(0);
 
 
 
262 if( x.tmCurrent >= tmNow ){
263 sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1));
264 }else{
265 if( lastWarning+warningDelay < tmNow ){
266 fossil_warning(
267
--- src/backoffice.c
+++ src/backoffice.c
@@ -42,10 +42,11 @@
42 #include "backoffice.h"
43 #include <time.h>
44 #if defined(_WIN32)
45 # include <windows.h>
46 #else
47 # include <unistd.h>
48 # include <sys/types.h>
49 # include <signal.h>
50 #endif
51
52 /*
@@ -164,10 +165,28 @@
165 return (sqlite3_uint64)GetCurrentProcessId();
166 #else
167 return (sqlite3_uint64)getpid();
168 #endif
169 }
170
171 /*
172 ** Set an alarm to cause the process to exit after "x" seconds. This
173 ** prevents any kind of bug from keeping a backoffice process running
174 ** indefinitely.
175 */
176 #if !defined(_WIN32)
177 static void backofficeSigalrmHandler(int x){
178 fossil_panic("backoffice timeout");
179 }
180 #endif
181 static void backofficeTimeout(int x){
182 #if !defined(_WIN32)
183 signal(SIGALRM, backofficeSigalrmHandler);
184 alarm(x);
185 #endif
186 }
187
188
189 /*
190 ** COMMAND: test-process-id
191 **
192 ** Usage: %fossil [--sleep N] PROCESS-ID ...
@@ -214,10 +233,11 @@
233 }
234 if( db_transaction_nesting_depth()!=0 ){
235 fossil_panic("transaction %s not closed prior to backoffice processing",
236 db_transaction_start_point());
237 }
238 backofficeTimeout(BKOFCE_LEASE_TIME*2);
239 idSelf = backofficeProcessId();
240 while(1){
241 tmNow = time(0);
242 db_begin_write();
243 backofficeReadLease(&x);
@@ -257,10 +277,13 @@
277 ** to expire before continuing. */
278 x.idNext = idSelf;
279 x.tmNext = (tmNow>x.tmCurrent ? tmNow : x.tmCurrent) + BKOFCE_LEASE_TIME;
280 backofficeWriteLease(&x);
281 db_end_transaction(0);
282 if( g.fAnyTrace ){
283 fprintf(stderr, "/***** Backoffice On-deck %d *****/\n", getpid());
284 }
285 if( x.tmCurrent >= tmNow ){
286 sqlite3_sleep(1000*(x.tmCurrent - tmNow + 1));
287 }else{
288 if( lastWarning+warningDelay < tmNow ){
289 fossil_warning(
290
+9 -1
--- src/cgi.c
+++ src/cgi.c
@@ -346,12 +346,20 @@
346346
** processing.
347347
*/
348348
g.cgiOutput = 2;
349349
if( g.db!=0 && iReplyStatus==200 ){
350350
fclose(g.httpOut);
351
+#ifdef _WIN32
352
+ g.httpOut = fossil_fopen("NUL", "wb");
353
+#else
351354
g.httpOut = fossil_fopen("/dev/null", "wb");
352
- backoffice_run();
355
+#endif
356
+ if( g.httpOut==0 ){
357
+ fossil_warning("failed ot open /dev/null");
358
+ }else{
359
+ backoffice_run();
360
+ }
353361
}
354362
}
355363
356364
/*
357365
** Do a redirect request to the URL given in the argument.
358366
--- src/cgi.c
+++ src/cgi.c
@@ -346,12 +346,20 @@
346 ** processing.
347 */
348 g.cgiOutput = 2;
349 if( g.db!=0 && iReplyStatus==200 ){
350 fclose(g.httpOut);
 
 
 
351 g.httpOut = fossil_fopen("/dev/null", "wb");
352 backoffice_run();
 
 
 
 
 
353 }
354 }
355
356 /*
357 ** Do a redirect request to the URL given in the argument.
358
--- src/cgi.c
+++ src/cgi.c
@@ -346,12 +346,20 @@
346 ** processing.
347 */
348 g.cgiOutput = 2;
349 if( g.db!=0 && iReplyStatus==200 ){
350 fclose(g.httpOut);
351 #ifdef _WIN32
352 g.httpOut = fossil_fopen("NUL", "wb");
353 #else
354 g.httpOut = fossil_fopen("/dev/null", "wb");
355 #endif
356 if( g.httpOut==0 ){
357 fossil_warning("failed ot open /dev/null");
358 }else{
359 backoffice_run();
360 }
361 }
362 }
363
364 /*
365 ** Do a redirect request to the URL given in the argument.
366
+1 -3
--- src/main.c
+++ src/main.c
@@ -2482,13 +2482,11 @@
24822482
24832483
/*
24842484
** Send a time-out reply
24852485
*/
24862486
void sigalrm_handler(int x){
2487
- printf("TIMEOUT\n");
2488
- fflush(stdout);
2489
- exit(1);
2487
+ fossil_panic("TIMEOUT");
24902488
}
24912489
24922490
/*
24932491
** COMMAND: server*
24942492
** COMMAND: ui
24952493
--- src/main.c
+++ src/main.c
@@ -2482,13 +2482,11 @@
2482
2483 /*
2484 ** Send a time-out reply
2485 */
2486 void sigalrm_handler(int x){
2487 printf("TIMEOUT\n");
2488 fflush(stdout);
2489 exit(1);
2490 }
2491
2492 /*
2493 ** COMMAND: server*
2494 ** COMMAND: ui
2495
--- src/main.c
+++ src/main.c
@@ -2482,13 +2482,11 @@
2482
2483 /*
2484 ** Send a time-out reply
2485 */
2486 void sigalrm_handler(int x){
2487 fossil_panic("TIMEOUT");
 
 
2488 }
2489
2490 /*
2491 ** COMMAND: server*
2492 ** COMMAND: ui
2493

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button