diff options
author | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2003-03-19 03:34:47 +0000 |
---|---|---|
committer | wrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68> | 2003-03-19 03:34:47 +0000 |
commit | 0b510b8d5af69b99b6fe2b9408473f1aa544ef1a (patch) | |
tree | 42cead4a783a646bf3287dceba33aec711e0cc3c | |
parent | 3f455edbe2e9907f9380525a2d7cf0eb0010c5a9 (diff) | |
download | libapr-0b510b8d5af69b99b6fe2b9408473f1aa544ef1a.tar.gz |
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.
git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@64428 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r-- | file_io/unix/filedup.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/file_io/unix/filedup.c b/file_io/unix/filedup.c index a2ad2cc94..cb7edde82 100644 --- a/file_io/unix/filedup.c +++ b/file_io/unix/filedup.c @@ -117,13 +117,23 @@ static apr_status_t _file_dup(apr_file_t **new_file, /* 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; } |