Fossil SCM

Moved the SIGTERM handler up before the "fossil server" HTTP hit handler. We had it clustered with the other signal() calls, but those are to handle signals intended to occur only during CGI processing. This one will normally occur while we're blocked, waiting for the HTTP hit to occur, so it had no useful effect where it was.

wyoung 2022-08-14 18:48 trunk
Commit d3c55fe02466006331fb82aacfafb7ccd2a2bdb92fa90844944d0676359e876c
1 file changed +13 -9
+13 -9
--- src/main.c
+++ src/main.c
@@ -3295,10 +3295,23 @@
32953295
return;
32963296
}
32973297
if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
32983298
if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
32993299
db_close(1);
3300
+ if( getpid()==1 ){
3301
+ /* Modern kernels suppress SIGTERM to PID 1 to prevent root from
3302
+ ** rebooting the system by nuking the init system. The only way
3303
+ ** Fossil becomes that PID 1 is when it's running solo in a Linux
3304
+ ** container or similar, so we do want to exit immediately, to
3305
+ ** allow the container to shut down quickly.
3306
+ **
3307
+ ** This has to happen ahead of the other signal() calls below.
3308
+ ** They apply after the HTTP hit is handled, but this one needs
3309
+ ** to be registered while we're waiting for that to occur.
3310
+ **/
3311
+ signal(SIGTERM, fossil_exit);
3312
+ }
33003313
33013314
/* Start up an HTTP server
33023315
*/
33033316
fossil_setenv("SERVER_SOFTWARE", "fossil version " RELEASE_VERSION
33043317
" " MANIFEST_VERSION " " MANIFEST_DATE);
@@ -3323,19 +3336,10 @@
33233336
}
33243337
g.httpIn = stdin;
33253338
g.httpOut = stdout;
33263339
signal(SIGSEGV, sigsegv_handler);
33273340
signal(SIGPIPE, sigpipe_handler);
3328
- if( getpid()==1 ){
3329
- /* Modern kernels suppress SIGTERM to PID 1 to prevent root from
3330
- ** rebooting the system by nuking the init system. The only way
3331
- ** Fossil becomes that PID 1 is when it's running solo in a Linux
3332
- ** container or similar, so we do want to exit immediately, to
3333
- ** allow the container to shut down quickly.
3334
- **/
3335
- signal(SIGTERM, fossil_exit);
3336
- }
33373341
if( g.fAnyTrace ){
33383342
fprintf(stderr, "/***** Subprocess %d *****/\n", getpid());
33393343
}
33403344
g.cgiOutput = 1;
33413345
find_server_repository(2, 0);
33423346
--- src/main.c
+++ src/main.c
@@ -3295,10 +3295,23 @@
3295 return;
3296 }
3297 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
3298 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
3299 db_close(1);
 
 
 
 
 
 
 
 
 
 
 
 
 
3300
3301 /* Start up an HTTP server
3302 */
3303 fossil_setenv("SERVER_SOFTWARE", "fossil version " RELEASE_VERSION
3304 " " MANIFEST_VERSION " " MANIFEST_DATE);
@@ -3323,19 +3336,10 @@
3323 }
3324 g.httpIn = stdin;
3325 g.httpOut = stdout;
3326 signal(SIGSEGV, sigsegv_handler);
3327 signal(SIGPIPE, sigpipe_handler);
3328 if( getpid()==1 ){
3329 /* Modern kernels suppress SIGTERM to PID 1 to prevent root from
3330 ** rebooting the system by nuking the init system. The only way
3331 ** Fossil becomes that PID 1 is when it's running solo in a Linux
3332 ** container or similar, so we do want to exit immediately, to
3333 ** allow the container to shut down quickly.
3334 **/
3335 signal(SIGTERM, fossil_exit);
3336 }
3337 if( g.fAnyTrace ){
3338 fprintf(stderr, "/***** Subprocess %d *****/\n", getpid());
3339 }
3340 g.cgiOutput = 1;
3341 find_server_repository(2, 0);
3342
--- src/main.c
+++ src/main.c
@@ -3295,10 +3295,23 @@
3295 return;
3296 }
3297 if( g.repositoryOpen ) flags |= HTTP_SERVER_HAD_REPOSITORY;
3298 if( g.localOpen ) flags |= HTTP_SERVER_HAD_CHECKOUT;
3299 db_close(1);
3300 if( getpid()==1 ){
3301 /* Modern kernels suppress SIGTERM to PID 1 to prevent root from
3302 ** rebooting the system by nuking the init system. The only way
3303 ** Fossil becomes that PID 1 is when it's running solo in a Linux
3304 ** container or similar, so we do want to exit immediately, to
3305 ** allow the container to shut down quickly.
3306 **
3307 ** This has to happen ahead of the other signal() calls below.
3308 ** They apply after the HTTP hit is handled, but this one needs
3309 ** to be registered while we're waiting for that to occur.
3310 **/
3311 signal(SIGTERM, fossil_exit);
3312 }
3313
3314 /* Start up an HTTP server
3315 */
3316 fossil_setenv("SERVER_SOFTWARE", "fossil version " RELEASE_VERSION
3317 " " MANIFEST_VERSION " " MANIFEST_DATE);
@@ -3323,19 +3336,10 @@
3336 }
3337 g.httpIn = stdin;
3338 g.httpOut = stdout;
3339 signal(SIGSEGV, sigsegv_handler);
3340 signal(SIGPIPE, sigpipe_handler);
 
 
 
 
 
 
 
 
 
3341 if( g.fAnyTrace ){
3342 fprintf(stderr, "/***** Subprocess %d *****/\n", getpid());
3343 }
3344 g.cgiOutput = 1;
3345 find_server_repository(2, 0);
3346

Keyboard Shortcuts

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