Fossil SCM

Improved process debugging for "fossil ui" and "fossil server". Sanely close the open database connection upon receiving SIGPIPE.

drh 2018-07-13 21:36 trunk
Commit 83b171bcd10a713c260ec3a74e8a4fce32d035943e1e0b61eda539f6d0ae6bb5
+4
--- src/cgi.c
+++ src/cgi.c
@@ -1936,10 +1936,14 @@
19361936
if( nchildren ){
19371937
while(1){
19381938
int iStatus = 0;
19391939
pid_t x = waitpid(-1, &iStatus, WNOHANG);
19401940
if( x<=0 ) break;
1941
+ if( WIFSIGNALED(iStatus) && g.fAnyTrace ){
1942
+ fprintf(stderr, "/***** Child %d exited on signal %d (%s) *****/\n",
1943
+ x, WTERMSIG(iStatus), strsignal(WTERMSIG(iStatus)));
1944
+ }
19411945
nchildren--;
19421946
}
19431947
}
19441948
}
19451949
/* NOT REACHED */
19461950
--- src/cgi.c
+++ src/cgi.c
@@ -1936,10 +1936,14 @@
1936 if( nchildren ){
1937 while(1){
1938 int iStatus = 0;
1939 pid_t x = waitpid(-1, &iStatus, WNOHANG);
1940 if( x<=0 ) break;
 
 
 
 
1941 nchildren--;
1942 }
1943 }
1944 }
1945 /* NOT REACHED */
1946
--- src/cgi.c
+++ src/cgi.c
@@ -1936,10 +1936,14 @@
1936 if( nchildren ){
1937 while(1){
1938 int iStatus = 0;
1939 pid_t x = waitpid(-1, &iStatus, WNOHANG);
1940 if( x<=0 ) break;
1941 if( WIFSIGNALED(iStatus) && g.fAnyTrace ){
1942 fprintf(stderr, "/***** Child %d exited on signal %d (%s) *****/\n",
1943 x, WTERMSIG(iStatus), strsignal(WTERMSIG(iStatus)));
1944 }
1945 nchildren--;
1946 }
1947 }
1948 }
1949 /* NOT REACHED */
1950
+25 -2
--- src/main.c
+++ src/main.c
@@ -1418,10 +1418,23 @@
14181418
*/
14191419
void sigsegv_handler(int x){
14201420
fossil_errorlog("Segfault");
14211421
exit(1);
14221422
}
1423
+
1424
+/*
1425
+** Called if a server gets a SIGPIPE. This often happens when a client
1426
+** webbrowser opens a connection but never sends the HTTP request
1427
+*/
1428
+void sigpipe_handler(int x){
1429
+#ifndef _WIN32
1430
+ if( g.fAnyTrace ){
1431
+ fprintf(stderr, "-- sigpipe received by subprocess %d --\n", getpid());
1432
+ }
1433
+#endif
1434
+ fossil_exit(1);
1435
+}
14231436
14241437
/*
14251438
** Preconditions:
14261439
**
14271440
** * Environment variables are set up according to the CGI standard.
@@ -2664,12 +2677,18 @@
26642677
signal(SIGALRM, sigalrm_handler);
26652678
alarm(atoi(zMaxLatency));
26662679
}
26672680
g.httpIn = stdin;
26682681
g.httpOut = stdout;
2669
- if( g.fHttpTrace || g.fSqlTrace ){
2670
- fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
2682
+
2683
+#if !defined(_WIN32)
2684
+ signal(SIGSEGV, sigsegv_handler);
2685
+ signal(SIGPIPE, sigpipe_handler);
2686
+#endif
2687
+
2688
+ if( g.fAnyTrace ){
2689
+ fprintf(stderr, "/***** Subprocess %d *****/\n", getpid());
26712690
}
26722691
g.cgiOutput = 1;
26732692
find_server_repository(2, 0);
26742693
if( fossil_strcmp(g.zRepositoryName,"/")==0 ){
26752694
allowRepoList = 1;
@@ -2680,10 +2699,14 @@
26802699
cgi_handle_scgi_request();
26812700
}else{
26822701
cgi_handle_http_request(0);
26832702
}
26842703
process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
2704
+ if( g.fAnyTrace ){
2705
+ fprintf(stderr, "/***** Webpage finished in subprocess %d *****/\n",
2706
+ getpid());
2707
+ }
26852708
#else
26862709
/* Win32 implementation */
26872710
if( isUiCmd ){
26882711
zBrowser = db_get("web-browser", "start");
26892712
if( zIpAddr==0 ){
26902713
--- src/main.c
+++ src/main.c
@@ -1418,10 +1418,23 @@
1418 */
1419 void sigsegv_handler(int x){
1420 fossil_errorlog("Segfault");
1421 exit(1);
1422 }
 
 
 
 
 
 
 
 
 
 
 
 
 
1423
1424 /*
1425 ** Preconditions:
1426 **
1427 ** * Environment variables are set up according to the CGI standard.
@@ -2664,12 +2677,18 @@
2664 signal(SIGALRM, sigalrm_handler);
2665 alarm(atoi(zMaxLatency));
2666 }
2667 g.httpIn = stdin;
2668 g.httpOut = stdout;
2669 if( g.fHttpTrace || g.fSqlTrace ){
2670 fprintf(stderr, "====== SERVER pid %d =======\n", getpid());
 
 
 
 
 
 
2671 }
2672 g.cgiOutput = 1;
2673 find_server_repository(2, 0);
2674 if( fossil_strcmp(g.zRepositoryName,"/")==0 ){
2675 allowRepoList = 1;
@@ -2680,10 +2699,14 @@
2680 cgi_handle_scgi_request();
2681 }else{
2682 cgi_handle_http_request(0);
2683 }
2684 process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
 
 
 
 
2685 #else
2686 /* Win32 implementation */
2687 if( isUiCmd ){
2688 zBrowser = db_get("web-browser", "start");
2689 if( zIpAddr==0 ){
2690
--- src/main.c
+++ src/main.c
@@ -1418,10 +1418,23 @@
1418 */
1419 void sigsegv_handler(int x){
1420 fossil_errorlog("Segfault");
1421 exit(1);
1422 }
1423
1424 /*
1425 ** Called if a server gets a SIGPIPE. This often happens when a client
1426 ** webbrowser opens a connection but never sends the HTTP request
1427 */
1428 void sigpipe_handler(int x){
1429 #ifndef _WIN32
1430 if( g.fAnyTrace ){
1431 fprintf(stderr, "-- sigpipe received by subprocess %d --\n", getpid());
1432 }
1433 #endif
1434 fossil_exit(1);
1435 }
1436
1437 /*
1438 ** Preconditions:
1439 **
1440 ** * Environment variables are set up according to the CGI standard.
@@ -2664,12 +2677,18 @@
2677 signal(SIGALRM, sigalrm_handler);
2678 alarm(atoi(zMaxLatency));
2679 }
2680 g.httpIn = stdin;
2681 g.httpOut = stdout;
2682
2683 #if !defined(_WIN32)
2684 signal(SIGSEGV, sigsegv_handler);
2685 signal(SIGPIPE, sigpipe_handler);
2686 #endif
2687
2688 if( g.fAnyTrace ){
2689 fprintf(stderr, "/***** Subprocess %d *****/\n", getpid());
2690 }
2691 g.cgiOutput = 1;
2692 find_server_repository(2, 0);
2693 if( fossil_strcmp(g.zRepositoryName,"/")==0 ){
2694 allowRepoList = 1;
@@ -2680,10 +2699,14 @@
2699 cgi_handle_scgi_request();
2700 }else{
2701 cgi_handle_http_request(0);
2702 }
2703 process_one_web_page(zNotFound, glob_create(zFileGlob), allowRepoList);
2704 if( g.fAnyTrace ){
2705 fprintf(stderr, "/***** Webpage finished in subprocess %d *****/\n",
2706 getpid());
2707 }
2708 #else
2709 /* Win32 implementation */
2710 if( isUiCmd ){
2711 zBrowser = db_get("web-browser", "start");
2712 if( zIpAddr==0 ){
2713
+6
--- src/util.c
+++ src/util.c
@@ -41,10 +41,16 @@
4141
/*
4242
** Exit. Take care to close the database first.
4343
*/
4444
NORETURN void fossil_exit(int rc){
4545
db_close(1);
46
+#ifndef _WIN32
47
+ if( g.fAnyTrace ){
48
+ fprintf(stderr, "/***** Subprocess %d exit(%d) *****/\n", getpid(), rc);
49
+ fflush(stderr);
50
+ }
51
+#endif
4652
exit(rc);
4753
}
4854
4955
/*
5056
** Malloc and free routines that cannot fail
5157
--- src/util.c
+++ src/util.c
@@ -41,10 +41,16 @@
41 /*
42 ** Exit. Take care to close the database first.
43 */
44 NORETURN void fossil_exit(int rc){
45 db_close(1);
 
 
 
 
 
 
46 exit(rc);
47 }
48
49 /*
50 ** Malloc and free routines that cannot fail
51
--- src/util.c
+++ src/util.c
@@ -41,10 +41,16 @@
41 /*
42 ** Exit. Take care to close the database first.
43 */
44 NORETURN void fossil_exit(int rc){
45 db_close(1);
46 #ifndef _WIN32
47 if( g.fAnyTrace ){
48 fprintf(stderr, "/***** Subprocess %d exit(%d) *****/\n", getpid(), rc);
49 fflush(stderr);
50 }
51 #endif
52 exit(rc);
53 }
54
55 /*
56 ** Malloc and free routines that cannot fail
57

Keyboard Shortcuts

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