jfclere     2003/09/26 13:52:12

  Modified:    daemon/src/native/unix/native jsvc-unix.c
  Log:
  PR 23241.
  Test the file creation via fopen() before freopen(). It is better to go on
  writting to stdout/stderr that to loose the output.
  
  Revision  Changes    Path
  1.6       +21 -3     jakarta-commons/daemon/src/native/unix/native/jsvc-unix.c
  
  Index: jsvc-unix.c
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/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       26 Sep 2003 19:03:10 -0000      1.5
  +++ jsvc-unix.c       26 Sep 2003 20:52:12 -0000      1.6
  @@ -368,11 +368,29 @@
       return(ret);
   }
   
  +/*
  + * freopen close the file first and then open the new file
  + * that is not very good if we are try to trace the output
  + * note the code assumes that the errors are configuration errors.
  + */
  +static FILE *loc_freopen(char *outfile, char *mode, FILE *stream)
  +{
  +    FILE *ftest;
  +    ftest = fopen(outfile,mode);
  +    if (ftest == NULL) {
  +      fprintf(stderr,"Unable to redirect to %s\n", outfile);
  +      return(stream);
  +    }
  +    fclose(ftest);
  +    return(freopen(outfile,mode,stream));
  +}
  +
   /**
    *  Redirect stdin, stdout, stderr.
    */
   static void set_output(char *outfile, char *errfile) {
       freopen("/dev/null", "r", stdin); 
  +    log_debug("redirecting stdout to %s and stderr to %s",outfile,errfile);
   
       /* make sure the debug goes out */
       if (log_debug_flag==true && strcmp(errfile,"/dev/null") == 0)
  @@ -383,11 +401,11 @@
         outfile="/dev/null";
       }
       if(strcmp(outfile, "&2") != 0) {
  -      freopen(outfile, "a", stdout);
  +      loc_freopen(outfile, "a", stdout);
       }
   
       if(strcmp(errfile,"&1") != 0) {
  -      freopen(errfile, "a", stderr);
  +      loc_freopen(errfile, "a", stderr);
       } else {
         close(2);
         dup(1);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to