billbarker 2003/06/20 21:23:55 Modified: daemon/src/native/unix/native arguments.c arguments.h jsvc-unix.c Log: As discussed, adding a call to 'setsid' on platforms that support it, redirect stdin to /dev/null, and make in configurable where to redirect stdout and stderr. Revision Changes Path 1.7 +16 -2 jakarta-commons-sandbox/daemon/src/native/unix/native/arguments.c Index: arguments.c =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/unix/native/arguments.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- arguments.c 10 Jun 2003 15:42:11 -0000 1.6 +++ arguments.c 21 Jun 2003 04:23:55 -0000 1.7 @@ -93,6 +93,8 @@ args->opts=(char **)malloc(argc*sizeof(char *)); args->clas=NULL; /* No class predefined */ args->anum=0; /* Zero class specific arguments but make room*/ + args->outfile="/dev/null"; /* Swallow by default */ + args->errfile="/dev/null"; /* Swallow by default */ args->args=(char **)malloc(argc*sizeof(char *)); /* Set up the command name */ @@ -176,7 +178,19 @@ return(NULL); } - } else if (strstr(argv[x],"-verbose")==argv[x]) { + } else if(strcmp(argv[x],"-outfile") == 0) { + args->outfile=optional(argc, argv, x++); + if(args->outfile == NULL) { + log_error("Invalid Output File specified"); + return(NULL); + } + } else if(strcmp(argv[x],"-errfile") == 0) { + args->errfile=optional(argc, argv, x++); + if(args->errfile == NULL) { + log_error("Invalid Error File specified"); + return(NULL); + } + }else if (strstr(argv[x],"-verbose")==argv[x]) { args->opts[args->onum++]=strdup(argv[x]); } else if (strcmp(argv[x],"-D")==0) { 1.5 +5 -1 jakarta-commons-sandbox/daemon/src/native/unix/native/arguments.h Index: arguments.h =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/unix/native/arguments.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- arguments.h 10 Jun 2003 15:42:11 -0000 1.4 +++ arguments.h 21 Jun 2003 04:23:55 -0000 1.5 @@ -99,6 +99,10 @@ bool remove; /** Run as a service (win32) */ bool service; + /** Destination for stdout */ + char *outfile; + /** Destination for stderr */ + char *errfile; } arg_data; /** 1.6 +32 -1 jakarta-commons-sandbox/daemon/src/native/unix/native/jsvc-unix.c Index: jsvc-unix.c =================================================================== RCS file: /home/cvs/jakarta-commons-sandbox/daemon/src/native/unix/native/jsvc-unix.c,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- jsvc-unix.c 10 Jun 2003 15:42:11 -0000 1.5 +++ jsvc-unix.c 21 Jun 2003 04:23:55 -0000 1.6 @@ -364,6 +364,32 @@ return(ret); } +/** + * Redirect stdin, stdout, stderr. + */ +static void set_output(char *outfile, char *errfile) { + freopen("/dev/null", "r", stdin); + + /* Handle malicious case here */ + if(strcmp(outfile, "&2") == 0 && strcmp(errfile,"&1") == 0) { + outfile="/dev/null"; + } + if(strcmp(outfile, "&2") != 0) { + freopen(outfile, "w", stdout); + } + + if(strcmp(errfile,"&1") != 0) { + freopen(errfile, "w", stderr); + } else { + close(2); + dup(1); + } + if(strcmp(outfile, "&2") == 0) { + close(1); + dup(2); + } +} + int main(int argc, char *argv[]) { arg_data *args=NULL; home_data *data=NULL; @@ -435,7 +461,12 @@ } /* If we're in the parent process, we siply quit */ if (pid!=0) return(0); +#ifndef NO_SETSID + setsid(); +#endif } + + set_output(args->outfile, args->errfile); /* We have to fork: this process will become the controller and the other will be the child */
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]