Fossil SCM

In the backoffice process, close the 0, 1, and 2 file descriptiors and reopen them as /dev/null, on unix.

drh 2018-08-08 17:57 UTC trunk
Commit 6865fb72cf5c8acb78be7e67a0638795093d206e86b18f4f356bf12b6b5eb974
--- src/backoffice.c
+++ src/backoffice.c
@@ -709,11 +709,13 @@
709709
GETPID(), GetProcessId((HANDLE)x));
710710
if( x>=0 ) return;
711711
}
712712
#else /* unix */
713713
{
714
- pid_t pid = fork();
714
+ pid_t pid;
715
+ if( g.fdDevNull<0 ) return;
716
+ pid = fork();
715717
if( pid>0 ){
716718
/* This is the parent in a successful fork(). Return immediately. */
717719
backofficeTrace(
718720
"/***** Subprocess %d creates backoffice child %d *****/\n",
719721
GETPID(), (int)pid);
@@ -721,11 +723,15 @@
721723
}
722724
if( pid==0 ){
723725
/* This is the child of a successful fork(). Run backoffice. */
724726
int i;
725727
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); }
727733
db_open_repository(backofficeDb);
728734
backofficeDb = "x";
729735
backoffice_thread();
730736
db_close(1);
731737
backofficeTrace("/***** Backoffice Child %d exits *****/\n", GETPID());
732738
--- 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 @@
133133
int argc; char **argv; /* Command-line arguments to the program */
134134
char *nameOfExe; /* Full path of executable. */
135135
const char *zErrlog; /* Log errors to this file, if not NULL */
136136
int isConst; /* True if the output is unchanging & cacheable */
137137
const char *zVfsName; /* The VFS to use for database connections */
138
+ int fdDevNull; /* /dev/null file descriptor */
138139
sqlite3 *db; /* The connection to the databases */
139140
sqlite3 *dbConfig; /* Separate connection for global_config table */
140141
char *zAuxSchema; /* Main repository aux-schema */
141142
int dbIgnoreErrors; /* Ignore database errors if true */
142143
const char *zConfigDbName;/* Path of the config database. NULL if not open */
143144
--- 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 @@
1919
**
2020
*/
2121
#include "VERSION.h"
2222
#include "config.h"
2323
#include "style.h"
24
+#ifndef _WIN32
25
+# include <sys/types.h>
26
+# include <sys/stat.h>
27
+# include <fcntl.h>#
28
+#endif
2429
2530
2631
/*
2732
** Elements of the submenu are collected into the following
2833
** structure and displayed below the main menu.
@@ -438,10 +443,17 @@
438443
if( g.perm.Debug && P("showqp") ){
439444
@ <div class="debug">
440445
cgi_print_all(0, 0);
441446
@ </div>
442447
}
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
443455
}
444456
445457
#if INTERFACE
446458
/* Allowed parameters for style_adunit() */
447459
#define ADUNIT_OFF 0x0001 /* Do not allow ads on this page */
448460
--- 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

Keyboard Shortcuts

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