apr-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apr/file_io/unix filedup.c
Date Wed, 19 Mar 2003 03:34:47 GMT
wrowe       2003/03/18 19:34:47

  Modified:    file_io/unix filedup.c
  Log:
    A common sense logic change.  If we are dup()ing or dup2()ing
 into one
    of the std[in|out|err] fd's - we should automatically toggle the inherit
    bit.  If the user calls apr_file_inherit_set() again it will be a noop.
  
    This brings Unix into line with Win32's implementation of dup.  If folks
    feel we should *only* apply this code to which_dup==2 cases, that's fine
    with me; although close(1); dup(n) would generally create a new fd 1 on
    unix, that code isn't portable to Win32 and should be strongly discouraged.
  
  Revision  Changes    Path
  1.59      +14 -4     apr/file_io/unix/filedup.c
  
  Index: filedup.c
  ===================================================================
  RCS file: /home/cvs/apr/file_io/unix/filedup.c,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- filedup.c	19 Mar 2003 02:31:15 -0000	1.58
  +++ filedup.c	19 Mar 2003 03:34:47 -0000	1.59
  @@ -117,13 +117,23 @@
       /* make sure unget behavior is consistent */
       (*new_file)->ungetchar = old_file->ungetchar;
   
  -    /* apr_file_dup() clears the inherit attribute, user must call 
  -     * apr_file_inherit_set() again on the dupped handle, as necessary.
  +    /* apr_file_dup() clears the inherit attribute for normal files,
  +     * but sets the inherit attribute for std[out,in,err] fd's. 
  +     * The user must call apr_file_inherit_[un]set() on the dupped 
  +     * apr_file_t when desired.
        */
  -    (*new_file)->flags = old_file->flags & ~APR_INHERIT;
  +    if ((*new_file)->filedes <= 2) {
  +        (*new_file)->flags = old_file->flags | APR_INHERIT;
  +    }
  +    else {
  +        (*new_file)->flags = old_file->flags & ~APR_INHERIT;
  +    }
   
       apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),
  -                              apr_unix_file_cleanup, apr_unix_file_cleanup);
  +                              apr_unix_file_cleanup, 
  +                              ((*new_file)->flags & APR_INHERIT)
  +                                 ? apr_pool_cleanup_null
  +                                 : apr_unix_file_cleanup);
   
       return APR_SUCCESS;
   }
  
  
  

Mime
View raw message