Index: file_io/unix/filedup.c =================================================================== --- file_io/unix/filedup.c (wersja 746595) +++ file_io/unix/filedup.c (kopia robocza) @@ -24,21 +24,40 @@ apr_file_t *old_file, apr_pool_t *p, int which_dup) { - int rv; + int rv, flags = 0; if (which_dup == 2) { if ((*new_file) == NULL) { /* We can't dup2 unless we have a valid new_file */ return APR_EINVAL; } +#ifdef HAVE_DUP3 + if (!(old_file->flags & APR_INHERIT)) + flags |= O_CLOEXEC; + rv = dup3(old_file->filedes, (*new_file)->filedes, flags); +#else rv = dup2(old_file->filedes, (*new_file)->filedes); +#endif } else { rv = dup(old_file->filedes); } if (rv == -1) return errno; - + + if ( +#ifdef HAVE_DUP3 + (which_dup != 2) && +#endif + !(old_file->flags & APR_INHERIT)) { + flags = fcntl(old_file->filedes, F_GETFD); + if (flags == -1) + return errno; + flags |= FD_CLOEXEC; + if (fcntl(old_file->filedes, F_SETFD, flags) == -1) + return errno; + } + if (which_dup == 1) { (*new_file) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t)); (*new_file)->pool = p;