stoddard    00/02/17 11:03:52

  Modified:    src/main http_log.c
               src/lib/apr/file_io/win32 filedup.c
  Log:
  Update Windows ap_filedup() call to recognise when it is asked to dup2
  a standard i/o handle. Return error if the dup2 handle is not one of the
  standard i/o handles (because Windows does not support a dup2 style function
  to operate on native file handles)
  
  Revision  Changes    Path
  1.30      +4 -8      apache-2.0/src/main/http_log.c
  
  Index: http_log.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/main/http_log.c,v
  retrieving revision 1.29
  retrieving revision 1.30
  diff -u -r1.29 -r1.30
  --- http_log.c        2000/02/15 22:51:23     1.29
  +++ http_log.c        2000/02/17 19:03:52     1.30
  @@ -264,18 +264,15 @@
   
       replace_stderr = 1;
       if (s_main->error_log) {
  +        /* replace stderr with this new log */
   #ifdef WIN32
  +        /* ToDo: Create ap_fflush() */
           HANDLE hFile;
           ap_get_os_file(&hFile, s_main->error_log);
           FlushFileBuffers(hFile);
  -        if (!SetStdHandle(STD_ERROR_HANDLE, hFile)) {
  -            ap_log_error(APLOG_MARK, APLOG_CRIT, GetLastError(), s_main,
  -                         "unable to replace stderr with error_log");
  -        }
  -        replace_stderr = 0;
   #else
  -        /* replace stderr with this new log */
  -        fflush(stderr); /* ToDo: replace this with an APR call... */
  +        fflush(stderr);
  +#endif
           ap_open_stderr(&errfile, p);        
           if ((rc = ap_dupfile(&errfile, s_main->error_log)) != APR_SUCCESS) {
               ap_log_error(APLOG_MARK, APLOG_CRIT, rc, s_main,
  @@ -283,7 +280,6 @@
           } else {
               replace_stderr = 0;
           }
  -#endif
       }
       /* note that stderr may still need to be replaced with something
        * because it points to the old error log, or back to the tty
  
  
  
  1.8       +23 -13    apache-2.0/src/lib/apr/file_io/win32/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/file_io/win32/filedup.c,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- filedup.c 2000/02/15 22:38:27     1.7
  +++ filedup.c 2000/02/17 19:03:52     1.8
  @@ -61,33 +61,42 @@
   
   ap_status_t ap_dupfile(struct file_t **new_file, struct file_t *old_file)
   {
  -    int have_file = 0;
       HANDLE hCurrentProcess = GetCurrentProcess();
   
       if ((*new_file) == NULL) {
  -        (*new_file) = (struct file_t *)ap_pcalloc(old_file->cntxt,
  -                                                  sizeof(struct file_t));
  +        (*new_file) = (struct file_t *) ap_pcalloc(old_file->cntxt,
  +                                                   sizeof(struct file_t));
           if ((*new_file) == NULL) {
               return APR_ENOMEM;
           }
  -    } else {
  -        have_file = 1;
  -    }
  -
  -    (*new_file)->cntxt = old_file->cntxt;
  -    if (have_file) {
  -        /* dup2 is not supported with native Windows handles */
  -        return APR_ENOTIMPL;
  -    }
  -    else {
           if (!DuplicateHandle(hCurrentProcess, old_file->filehand, 
                                hCurrentProcess,
                                &(*new_file)->filehand, 0, FALSE, 
                                DUPLICATE_SAME_ACCESS)) {
               return GetLastError();
           }
  +    } else {
  +        HANDLE hFile = (*new_file)->filehand;
  +        /* dup2 is not supported with native Windows handles. We 
  +         * can, however, emulate dup2 for the standard i/o handles.
  +         */
  +        if (hFile == GetStdHandle(STD_ERROR_HANDLE)) {
  +            if (!SetStdHandle(STD_ERROR_HANDLE, old_file->filehand))
  +                return GetLastError();
  +        }
  +        else if (hFile == GetStdHandle(STD_OUTPUT_HANDLE)) {
  +            if (!SetStdHandle(STD_OUTPUT_HANDLE, old_file->filehand))
  +                return GetLastError();
  +        }
  +        else if (hFile == GetStdHandle(STD_INPUT_HANDLE)) {
  +            if (!SetStdHandle(STD_INPUT_HANDLE, old_file->filehand))
  +                return GetLastError();
  +        }
  +        else
  +            return APR_ENOTIMPL;
       }
   
  +    (*new_file)->cntxt = old_file->cntxt;
       (*new_file)->fname = ap_pstrdup(old_file->cntxt, old_file->fname);
       (*new_file)->demonfname = ap_pstrdup(old_file->cntxt, 
old_file->demonfname);
       (*new_file)->lowerdemonfname = ap_pstrdup(old_file->cntxt, 
old_file->lowerdemonfname);
  @@ -102,6 +111,7 @@
       (*new_file)->ctime = old_file->ctime;
       ap_register_cleanup((*new_file)->cntxt, (void *)(*new_file), 
file_cleanup,
                           ap_null_cleanup);
  +
       return APR_SUCCESS;
   }
   
  
  
  

Reply via email to