At 01:09 PM 3/21/2003, Jeff Trawick wrote: >I'm a bit nervous about the existing/new special handling for descriptors 0-2.
Ok, here is a patch that uses the target file's inherit and noclose flag bits for apr_file_dup2(), and leaves apr_file_dup() results as never inherited and always registering a cleanup. Would this patch satisfy your concerns? Does this patch resolve the new misbehavior? Bill
Index: file_io/unix/filedup.c =================================================================== RCS file: /home/cvs/apr/file_io/unix/filedup.c,v retrieving revision 1.60 diff -u -r1.60 filedup.c --- file_io/unix/filedup.c 19 Mar 2003 10:17:26 -0000 1.60 +++ file_io/unix/filedup.c 21 Mar 2003 17:31:58 -0000 @@ -117,16 +117,25 @@ /* make sure unget behavior is consistent */ (*new_file)->ungetchar = old_file->ungetchar; - /* 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. - */ - if ((*new_file)->filedes <= 2) { - (*new_file)->flags = old_file->flags | APR_INHERIT; + if (which_dup == 1) { + /* apr_file_dup() retains all old_file flags with the exceptions + * of APR_INHERIT and APR_FILE_NOCLEANUP. + * The user must call apr_file_inherit_set() on the dupped + * apr_file_t when desired. + */ + (*new_file)->flags = old_file->flags + & ~(APR_INHERIT | APR_FILE_NOCLEANUP); + } } - else { - (*new_file)->flags = old_file->flags & ~APR_INHERIT; + else /* which_dup == 2 */ { + /* apr_file_dup2() must respect the original settings for the + * new_file->flags inheritence. If there is no cleanup, we + * should be finished already, otherwise fall through to the + * apr_pool_cleanup_register + */ + if ((*new_file)->flags & APR_FILE_NOCLEANUP) { + return APR_SUCCESS; + } } apr_pool_cleanup_register((*new_file)->pool, (void *)(*new_file),