apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/threadproc/win32 proc.c
Date Mon, 01 Jul 2002 17:14:21 GMT
wrowe       2002/07/01 10:14:21

  Modified:    threadproc/win32 proc.c
  Log:
    Unix, NW and OS2 folks, please look at this change and consider similar
    patches.  It seems like extreme overkill to create a pipe when we are
    only setting up a log fd for output, and similar cases.  We waste an
    entire pipe resource just to attach (pipe) to a logfile?  That seems goofy.
  
    We now have both _dup and _dup2, so we should take advantage of them.
  
  Revision  Changes    Path
  1.76      +56 -81    apr/threadproc/win32/proc.c
  
  Index: proc.c
  ===================================================================
  RCS file: /home/cvs/apr/threadproc/win32/proc.c,v
  retrieving revision 1.75
  retrieving revision 1.76
  diff -u -r1.75 -r1.76
  --- proc.c	23 Jun 2002 06:19:34 -0000	1.75
  +++ proc.c	1 Jul 2002 17:14:21 -0000	1.76
  @@ -154,135 +154,110 @@
   #endif
   }
   
  -static apr_status_t make_inheritable_duplicate(apr_file_t *original,
  -                                               apr_file_t *duplicate)
  -{
  -#ifdef _WIN32_WCE
  -    return APR_ENOTIMPL;
  -#else
  -    if (original == NULL)
  -        return APR_SUCCESS;
  -
  -    /* XXX: Can't use apr_file_dup here because it creates a non-inhertible 
  -     * handle, and apr_open_file'd apr_file_t's are non-inheritable,
  -     * so we must assume we need to make an inheritable handle.
  -     */
  -    if (!CloseHandle(duplicate->filehand))
  -        return apr_get_os_error();
  -    else
  -    {
  -        HANDLE hproc = GetCurrentProcess();
  -        if (!DuplicateHandle(hproc, original->filehand, 
  -                             hproc, &duplicate->filehand, 0,
  -                             TRUE, DUPLICATE_SAME_ACCESS))
  -            return apr_get_os_error();
  -    }
  -
  -    return APR_SUCCESS;
  -#endif
  -}
  -
   APR_DECLARE(apr_status_t) apr_procattr_io_set(apr_procattr_t *attr,
                                                apr_int32_t in, 
                                                apr_int32_t out,
                                                apr_int32_t err)
   {
  -    apr_status_t stat;
  +    apr_status_t stat = APR_SUCCESS;
   
       if (in) {
           stat = open_nt_process_pipe(&attr->child_in, &attr->parent_in, in,
                                       attr->pool);
           if (stat == APR_SUCCESS)
               stat = make_handle_private(attr->parent_in);
  -        if (stat != APR_SUCCESS)
  -            return stat;
       }
  -    if (out) {
  +    if (out && stat == APR_SUCCESS) {
           stat = open_nt_process_pipe(&attr->parent_out, &attr->child_out,
out,
                                       attr->pool);
           if (stat == APR_SUCCESS)
               stat = make_handle_private(attr->parent_out);
  -        if (stat != APR_SUCCESS)
  -            return stat;
       }
  -    if (err) {
  +    if (err && stat == APR_SUCCESS) {
           stat = open_nt_process_pipe(&attr->parent_err, &attr->child_err,
err,
                                       attr->pool);
           if (stat == APR_SUCCESS)
               stat = make_handle_private(attr->parent_err);
  -        if (stat != APR_SUCCESS)
  -            return stat;
       }
  -    return APR_SUCCESS;
  +    return stat;
   }
   
   APR_DECLARE(apr_status_t) apr_procattr_child_in_set(apr_procattr_t *attr, 
                                                     apr_file_t *child_in, 
                                                     apr_file_t *parent_in)
   {
  -    apr_status_t stat;
  +    apr_status_t rv = APR_SUCCESS;
   
  -    if (attr->child_in == NULL && attr->parent_in == NULL) {
  -        stat = open_nt_process_pipe(&attr->child_in, &attr->parent_in,
  -                                    APR_FULL_BLOCK,
  -                                    attr->pool);
  -        if (stat == APR_SUCCESS)
  -            stat = make_handle_private(attr->parent_in);
  -        if (stat != APR_SUCCESS)
  -            return stat;
  +    if (child_in) {
  +        if (attr->child_in == NULL)
  +            rv = apr_file_dup(&attr->child_in, child_in, attr_pool);
  +        else
  +            rv = apr_file_dup2(attr->child_in, child_in, attr_pool);
  +
  +        if (rv == APR_SUCCESS)
  +            rv = apr_file_inherit_set(attr->child_in);
       }
   
  -    stat = make_inheritable_duplicate (child_in, attr->child_in);
  -    if (stat == APR_SUCCESS)
  -        stat = make_inheritable_duplicate (parent_in, attr->parent_in);
  +    if (parent_in && rv == APR_SUCCESS) {
  +        if (attr->parent_in == NULL)
  +            rv = apr_file_dup(&attr->parent_in, parent_in, attr_pool);
  +        else
  +            rv = apr_file_dup2(attr->parent_in, parent_in, attr_pool);
  +    }
   
  -    return stat;
  +    return rv;
   }
   
   APR_DECLARE(apr_status_t) apr_procattr_child_out_set(apr_procattr_t *attr,
                                                      apr_file_t *child_out,
                                                      apr_file_t *parent_out)
   {
  -    apr_status_t stat;
  +    apr_status_t rv = APR_SUCCESS;
   
  -    if (attr->child_out == NULL && attr->parent_out == NULL) {
  -        stat = open_nt_process_pipe(&attr->child_out, &attr->parent_out,
  -                                    APR_FULL_BLOCK,
  -                                    attr->pool);
  -        if (stat == APR_SUCCESS)
  -            stat = make_handle_private(attr->parent_out);
  -        if (stat != APR_SUCCESS)
  -            return stat;
  -    }        
  -        
  -    stat = make_inheritable_duplicate (child_out, attr->child_out);
  -    if (stat == APR_SUCCESS)
  -        stat = make_inheritable_duplicate (parent_out, attr->parent_out);
  +    if (child_out) {
  +        if (attr->child_out == NULL)
  +            rv = apr_file_dup(&attr->child_out, child_out, attr_pool);
  +        else
  +            rv = apr_file_dup2(attr->child_out, child_out, attr_pool);
   
  -    return stat;
  +        if (rv == APR_SUCCESS)
  +            rv = apr_file_inherit_set(attr->child_out);
  +    }
  +
  +    if (parent_out && rv == APR_SUCCESS) {
  +        if (attr->parent_out == NULL)
  +            rv = apr_file_dup(&attr->parent_out, parent_out, attr_pool);
  +        else
  +            rv = apr_file_dup2(attr->parent_out, parent_out, attr_pool);
  +    }
  +
  +    return rv;
   }
   
   APR_DECLARE(apr_status_t) apr_procattr_child_err_set(apr_procattr_t *attr,
                                                      apr_file_t *child_err,
                                                      apr_file_t *parent_err)
   {
  -    apr_status_t stat;
  +    apr_status_t rv = APR_SUCCESS;
   
  -    if (attr->child_err == NULL && attr->parent_err == NULL) {
  -        stat = open_nt_process_pipe(&attr->child_err, &attr->parent_err,
  -                                    APR_FULL_BLOCK,
  -                                    attr->pool);
  -        if (stat == APR_SUCCESS)
  -            stat = make_handle_private(attr->parent_err);
  -        if (stat != APR_SUCCESS)
  -            return stat;
  -    }        
  -        
  -    stat = make_inheritable_duplicate (child_err, attr->child_err);
  -    if (stat == APR_SUCCESS)
  -        stat = make_inheritable_duplicate (parent_err, attr->parent_err);
  +    if (child_err) {
  +        if (attr->child_err == NULL)
  +            rv = apr_file_dup(&attr->child_err, child_err, attr_pool);
  +        else
  +            rv = apr_file_dup2(attr->child_err, child_err, attr_pool);
   
  -    return stat;
  +        if (rv == APR_SUCCESS)
  +            rv = apr_file_inherit_set(attr->child_err);
  +    }
  +
  +    if (parent_err && rv == APR_SUCCESS) {
  +        if (attr->parent_err == NULL)
  +            rv = apr_file_dup(&attr->parent_err, parent_err, attr_pool);
  +        else
  +            rv = apr_file_dup2(attr->parent_err, parent_err, attr_pool);
  +    }
  +
  +    return rv;
   }
   
   APR_DECLARE(apr_status_t) apr_procattr_dir_set(apr_procattr_t *attr,
  
  
  

Mime
View raw message