Skip to content

Commit

Permalink
Given two solutions to the current mpm inheritence bugs,
Browse files Browse the repository at this point in the history
    1) track the target file's existing flags and register the proper
       sort of cleanup (a bug in the new design) or
    2) revert to the previous behavior and retain the existing cleanup

  I've gone with option 2, since Joe Orton has expressed concern with
  introducing too many changes in the coming release.  However, this
  implies that;
    apr_file_close(fd1);
    apr_file_dup2(fd1, fd2);
  is absolutely unsupported.  Since it wouldn't work on Win32 in the
  first place, I'm not terribly concerned about this limitation.


git-svn-id: https://svn.apache.org/repos/asf/apr/apr/trunk@64441 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
wrowe committed Mar 22, 2003
1 parent 2f1416b commit d3b0a6e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions file_io/unix/filedup.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,16 @@ 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_dup2() retains the original cleanup, reflecting
* the existing inherit and nocleanup flags. This means,
* that apr_file_dup2() cannot be called against an apr_file_t
* already closed with apr_file_close, because the expected
* cleanup was already killed.
*/
if (which_dup == 2) {
return APR_SUCCESS;
}

/* 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
Expand Down Expand Up @@ -139,14 +149,6 @@ APR_DECLARE(apr_status_t) apr_file_dup(apr_file_t **new_file,
APR_DECLARE(apr_status_t) apr_file_dup2(apr_file_t *new_file,
apr_file_t *old_file, apr_pool_t *p)
{
/* an existing apr_file_t may already be closed, and therefore
* have no cleanup remaining; but we don't want to double-register
* the same cleanup in _file_dup. Kill the existing cleanup before
* invoking _file_dup to the existing new_file.
*/
apr_pool_cleanup_kill(new_file->pool, (void *)(new_file),
apr_unix_file_cleanup);

return _file_dup(&new_file, old_file, p, 2);
}

Expand Down

0 comments on commit d3b0a6e

Please sign in to comment.