Fossil SCM
In the backoffice process, close the 0, 1, and 2 file descriptiors and reopen them as /dev/null, on unix.
Commit
6865fb72cf5c8acb78be7e67a0638795093d206e86b18f4f356bf12b6b5eb974
Parent
918e1ddd8e56654…
3 files changed
+8
-2
+1
+12
+8
-2
| --- src/backoffice.c | ||
| +++ src/backoffice.c | ||
| @@ -709,11 +709,13 @@ | ||
| 709 | 709 | GETPID(), GetProcessId((HANDLE)x)); |
| 710 | 710 | if( x>=0 ) return; |
| 711 | 711 | } |
| 712 | 712 | #else /* unix */ |
| 713 | 713 | { |
| 714 | - pid_t pid = fork(); | |
| 714 | + pid_t pid; | |
| 715 | + if( g.fdDevNull<0 ) return; | |
| 716 | + pid = fork(); | |
| 715 | 717 | if( pid>0 ){ |
| 716 | 718 | /* This is the parent in a successful fork(). Return immediately. */ |
| 717 | 719 | backofficeTrace( |
| 718 | 720 | "/***** Subprocess %d creates backoffice child %d *****/\n", |
| 719 | 721 | GETPID(), (int)pid); |
| @@ -721,11 +723,15 @@ | ||
| 721 | 723 | } |
| 722 | 724 | if( pid==0 ){ |
| 723 | 725 | /* This is the child of a successful fork(). Run backoffice. */ |
| 724 | 726 | int i; |
| 725 | 727 | setsid(); |
| 726 | - for(i=3; close(i)==0 || i<10; i++){} | |
| 728 | + for(i=0; i<=2; i++){ | |
| 729 | + close(i); | |
| 730 | + dup(g.fdDevNull); | |
| 731 | + } | |
| 732 | + for(i=3; i<100; i++){ close(i); } | |
| 727 | 733 | db_open_repository(backofficeDb); |
| 728 | 734 | backofficeDb = "x"; |
| 729 | 735 | backoffice_thread(); |
| 730 | 736 | db_close(1); |
| 731 | 737 | backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID()); |
| 732 | 738 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -709,11 +709,13 @@ | |
| 709 | GETPID(), GetProcessId((HANDLE)x)); |
| 710 | if( x>=0 ) return; |
| 711 | } |
| 712 | #else /* unix */ |
| 713 | { |
| 714 | pid_t pid = fork(); |
| 715 | if( pid>0 ){ |
| 716 | /* This is the parent in a successful fork(). Return immediately. */ |
| 717 | backofficeTrace( |
| 718 | "/***** Subprocess %d creates backoffice child %d *****/\n", |
| 719 | GETPID(), (int)pid); |
| @@ -721,11 +723,15 @@ | |
| 721 | } |
| 722 | if( pid==0 ){ |
| 723 | /* This is the child of a successful fork(). Run backoffice. */ |
| 724 | int i; |
| 725 | setsid(); |
| 726 | for(i=3; close(i)==0 || i<10; i++){} |
| 727 | db_open_repository(backofficeDb); |
| 728 | backofficeDb = "x"; |
| 729 | backoffice_thread(); |
| 730 | db_close(1); |
| 731 | backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID()); |
| 732 |
| --- src/backoffice.c | |
| +++ src/backoffice.c | |
| @@ -709,11 +709,13 @@ | |
| 709 | GETPID(), GetProcessId((HANDLE)x)); |
| 710 | if( x>=0 ) return; |
| 711 | } |
| 712 | #else /* unix */ |
| 713 | { |
| 714 | pid_t pid; |
| 715 | if( g.fdDevNull<0 ) return; |
| 716 | pid = fork(); |
| 717 | if( pid>0 ){ |
| 718 | /* This is the parent in a successful fork(). Return immediately. */ |
| 719 | backofficeTrace( |
| 720 | "/***** Subprocess %d creates backoffice child %d *****/\n", |
| 721 | GETPID(), (int)pid); |
| @@ -721,11 +723,15 @@ | |
| 723 | } |
| 724 | if( pid==0 ){ |
| 725 | /* This is the child of a successful fork(). Run backoffice. */ |
| 726 | int i; |
| 727 | setsid(); |
| 728 | for(i=0; i<=2; i++){ |
| 729 | close(i); |
| 730 | dup(g.fdDevNull); |
| 731 | } |
| 732 | for(i=3; i<100; i++){ close(i); } |
| 733 | db_open_repository(backofficeDb); |
| 734 | backofficeDb = "x"; |
| 735 | backoffice_thread(); |
| 736 | db_close(1); |
| 737 | backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID()); |
| 738 |
+1
| --- src/main.c | ||
| +++ src/main.c | ||
| @@ -133,10 +133,11 @@ | ||
| 133 | 133 | int argc; char **argv; /* Command-line arguments to the program */ |
| 134 | 134 | char *nameOfExe; /* Full path of executable. */ |
| 135 | 135 | const char *zErrlog; /* Log errors to this file, if not NULL */ |
| 136 | 136 | int isConst; /* True if the output is unchanging & cacheable */ |
| 137 | 137 | const char *zVfsName; /* The VFS to use for database connections */ |
| 138 | + int fdDevNull; /* /dev/null file descriptor */ | |
| 138 | 139 | sqlite3 *db; /* The connection to the databases */ |
| 139 | 140 | sqlite3 *dbConfig; /* Separate connection for global_config table */ |
| 140 | 141 | char *zAuxSchema; /* Main repository aux-schema */ |
| 141 | 142 | int dbIgnoreErrors; /* Ignore database errors if true */ |
| 142 | 143 | const char *zConfigDbName;/* Path of the config database. NULL if not open */ |
| 143 | 144 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -133,10 +133,11 @@ | |
| 133 | int argc; char **argv; /* Command-line arguments to the program */ |
| 134 | char *nameOfExe; /* Full path of executable. */ |
| 135 | const char *zErrlog; /* Log errors to this file, if not NULL */ |
| 136 | int isConst; /* True if the output is unchanging & cacheable */ |
| 137 | const char *zVfsName; /* The VFS to use for database connections */ |
| 138 | sqlite3 *db; /* The connection to the databases */ |
| 139 | sqlite3 *dbConfig; /* Separate connection for global_config table */ |
| 140 | char *zAuxSchema; /* Main repository aux-schema */ |
| 141 | int dbIgnoreErrors; /* Ignore database errors if true */ |
| 142 | const char *zConfigDbName;/* Path of the config database. NULL if not open */ |
| 143 |
| --- src/main.c | |
| +++ src/main.c | |
| @@ -133,10 +133,11 @@ | |
| 133 | int argc; char **argv; /* Command-line arguments to the program */ |
| 134 | char *nameOfExe; /* Full path of executable. */ |
| 135 | const char *zErrlog; /* Log errors to this file, if not NULL */ |
| 136 | int isConst; /* True if the output is unchanging & cacheable */ |
| 137 | const char *zVfsName; /* The VFS to use for database connections */ |
| 138 | int fdDevNull; /* /dev/null file descriptor */ |
| 139 | sqlite3 *db; /* The connection to the databases */ |
| 140 | sqlite3 *dbConfig; /* Separate connection for global_config table */ |
| 141 | char *zAuxSchema; /* Main repository aux-schema */ |
| 142 | int dbIgnoreErrors; /* Ignore database errors if true */ |
| 143 | const char *zConfigDbName;/* Path of the config database. NULL if not open */ |
| 144 |
+12
| --- src/style.c | ||
| +++ src/style.c | ||
| @@ -19,10 +19,15 @@ | ||
| 19 | 19 | ** |
| 20 | 20 | */ |
| 21 | 21 | #include "VERSION.h" |
| 22 | 22 | #include "config.h" |
| 23 | 23 | #include "style.h" |
| 24 | +#ifndef _WIN32 | |
| 25 | +# include <sys/types.h> | |
| 26 | +# include <sys/stat.h> | |
| 27 | +# include <fcntl.h># | |
| 28 | +#endif | |
| 24 | 29 | |
| 25 | 30 | |
| 26 | 31 | /* |
| 27 | 32 | ** Elements of the submenu are collected into the following |
| 28 | 33 | ** structure and displayed below the main menu. |
| @@ -438,10 +443,17 @@ | ||
| 438 | 443 | if( g.perm.Debug && P("showqp") ){ |
| 439 | 444 | @ <div class="debug"> |
| 440 | 445 | cgi_print_all(0, 0); |
| 441 | 446 | @ </div> |
| 442 | 447 | } |
| 448 | +#ifndef _WIN32 | |
| 449 | + g.fdDevNull = open("/dev/null", O_RDWR); | |
| 450 | + if( g.fdDevNull<0 ){ | |
| 451 | + fossil_warning("cannot open /dev/null"); | |
| 452 | + webpage_error("Cannot open /dev/null"); | |
| 453 | + } | |
| 454 | +#endif | |
| 443 | 455 | } |
| 444 | 456 | |
| 445 | 457 | #if INTERFACE |
| 446 | 458 | /* Allowed parameters for style_adunit() */ |
| 447 | 459 | #define ADUNIT_OFF 0x0001 /* Do not allow ads on this page */ |
| 448 | 460 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -19,10 +19,15 @@ | |
| 19 | ** |
| 20 | */ |
| 21 | #include "VERSION.h" |
| 22 | #include "config.h" |
| 23 | #include "style.h" |
| 24 | |
| 25 | |
| 26 | /* |
| 27 | ** Elements of the submenu are collected into the following |
| 28 | ** structure and displayed below the main menu. |
| @@ -438,10 +443,17 @@ | |
| 438 | if( g.perm.Debug && P("showqp") ){ |
| 439 | @ <div class="debug"> |
| 440 | cgi_print_all(0, 0); |
| 441 | @ </div> |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | #if INTERFACE |
| 446 | /* Allowed parameters for style_adunit() */ |
| 447 | #define ADUNIT_OFF 0x0001 /* Do not allow ads on this page */ |
| 448 |
| --- src/style.c | |
| +++ src/style.c | |
| @@ -19,10 +19,15 @@ | |
| 19 | ** |
| 20 | */ |
| 21 | #include "VERSION.h" |
| 22 | #include "config.h" |
| 23 | #include "style.h" |
| 24 | #ifndef _WIN32 |
| 25 | # include <sys/types.h> |
| 26 | # include <sys/stat.h> |
| 27 | # include <fcntl.h># |
| 28 | #endif |
| 29 | |
| 30 | |
| 31 | /* |
| 32 | ** Elements of the submenu are collected into the following |
| 33 | ** structure and displayed below the main menu. |
| @@ -438,10 +443,17 @@ | |
| 443 | if( g.perm.Debug && P("showqp") ){ |
| 444 | @ <div class="debug"> |
| 445 | cgi_print_all(0, 0); |
| 446 | @ </div> |
| 447 | } |
| 448 | #ifndef _WIN32 |
| 449 | g.fdDevNull = open("/dev/null", O_RDWR); |
| 450 | if( g.fdDevNull<0 ){ |
| 451 | fossil_warning("cannot open /dev/null"); |
| 452 | webpage_error("Cannot open /dev/null"); |
| 453 | } |
| 454 | #endif |
| 455 | } |
| 456 | |
| 457 | #if INTERFACE |
| 458 | /* Allowed parameters for style_adunit() */ |
| 459 | #define ADUNIT_OFF 0x0001 /* Do not allow ads on this page */ |
| 460 |