Fossil

Check-in [83b171bc]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Improved process debugging for "fossil ui" and "fossil server". Sanely close the open database connection upon receiving SIGPIPE.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 83b171bcd10a713c260ec3a74e8a4fce32d035943e1e0b61eda539f6d0ae6bb5
User & Date: drh 2018-07-13 21:36:12
Context
2018-07-14
00:54
Do not allow people to subscribe to notifications for which they do not have read permission. check-in: 6e6e3c8b user: drh tags: trunk
2018-07-13
21:36
Improved process debugging for "fossil ui" and "fossil server". Sanely close the open database connection upon receiving SIGPIPE. check-in: 83b171bc user: drh tags: trunk
20:36
An early attempt at the /setup_smtp page. Partly working. check-in: 1e799919 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/cgi.c.

  1934   1934       }
  1935   1935       /* Bury dead children */
  1936   1936       if( nchildren ){
  1937   1937         while(1){
  1938   1938           int iStatus = 0;
  1939   1939           pid_t x = waitpid(-1, &iStatus, WNOHANG);
  1940   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  +        }
  1941   1945           nchildren--;
  1942   1946         }
  1943   1947       }  
  1944   1948     }
  1945   1949     /* NOT REACHED */
  1946   1950     fossil_exit(1);
  1947   1951   #endif

Changes to src/main.c.

  1416   1416   /*
  1417   1417   ** Called whenever a crash is encountered while processing a webpage.
  1418   1418   */
  1419   1419   void sigsegv_handler(int x){
  1420   1420     fossil_errorlog("Segfault");
  1421   1421     exit(1);
  1422   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  +}
  1423   1436   
  1424   1437   /*
  1425   1438   ** Preconditions:
  1426   1439   **
  1427   1440   **  * Environment variables are set up according to the CGI standard.
  1428   1441   **
  1429   1442   ** If the repository is known, it has already been opened.  If unknown,
................................................................................
  2662   2675     }
  2663   2676     if( zMaxLatency ){
  2664   2677       signal(SIGALRM, sigalrm_handler);
  2665   2678       alarm(atoi(zMaxLatency));
  2666   2679     }
  2667   2680     g.httpIn = stdin;
  2668   2681     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());
  2671   2690     }
  2672   2691     g.cgiOutput = 1;
  2673   2692     find_server_repository(2, 0);
  2674   2693     if( fossil_strcmp(g.zRepositoryName,"/")==0 ){
  2675   2694       allowRepoList = 1;
  2676   2695     }else{
  2677   2696       g.zRepositoryName = enter_chroot_jail(g.zRepositoryName, noJail);
................................................................................
  2678   2697     }
  2679   2698     if( flags & HTTP_SERVER_SCGI ){
  2680   2699       cgi_handle_scgi_request();
  2681   2700     }else{
  2682   2701       cgi_handle_http_request(0);
  2683   2702     }
  2684   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  +  }
  2685   2708   #else
  2686   2709     /* Win32 implementation */
  2687   2710     if( isUiCmd ){
  2688   2711       zBrowser = db_get("web-browser", "start");
  2689   2712       if( zIpAddr==0 ){
  2690   2713         zBrowserCmd = mprintf("%s http://localhost:%%d/%s &",
  2691   2714                               zBrowser, zInitPage);

Changes to src/util.c.

    39     39   
    40     40   
    41     41   /*
    42     42   ** Exit.  Take care to close the database first.
    43     43   */
    44     44   NORETURN void fossil_exit(int rc){
    45     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
    46     52     exit(rc);
    47     53   }
    48     54   
    49     55   /*
    50     56   ** Malloc and free routines that cannot fail
    51     57   */
    52     58   void *fossil_malloc(size_t n){