Fossil SCM

The parent process now handles SIGTERM with an explicit exit(3) call when its PID is 1, as when it's running as "fossil server" in a Docker container. Without this, the container host's shutdown process takes a long time because it's waiting on PID 1 to die and eventually has to time out and kill it.

wyoung 2022-08-14 17:59 trunk
Commit 1d09e607398c1f8663f2b1a706355a422c490f3972d3c5d4e1868ef2c65a448a
1 file changed +9
+9
--- src/main.c
+++ src/main.c
@@ -3323,10 +3323,19 @@
33233323
}
33243324
g.httpIn = stdin;
33253325
g.httpOut = stdout;
33263326
signal(SIGSEGV, sigsegv_handler);
33273327
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, exit);
3336
+ }
33283337
if( g.fAnyTrace ){
33293338
fprintf(stderr, "/***** Subprocess %d *****/\n", getpid());
33303339
}
33313340
g.cgiOutput = 1;
33323341
find_server_repository(2, 0);
33333342
--- src/main.c
+++ src/main.c
@@ -3323,10 +3323,19 @@
3323 }
3324 g.httpIn = stdin;
3325 g.httpOut = stdout;
3326 signal(SIGSEGV, sigsegv_handler);
3327 signal(SIGPIPE, sigpipe_handler);
 
 
 
 
 
 
 
 
 
3328 if( g.fAnyTrace ){
3329 fprintf(stderr, "/***** Subprocess %d *****/\n", getpid());
3330 }
3331 g.cgiOutput = 1;
3332 find_server_repository(2, 0);
3333
--- src/main.c
+++ src/main.c
@@ -3323,10 +3323,19 @@
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, 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

Keyboard Shortcuts

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