View | Details | Raw Unified | Return to bug 46425
Collapse All | Expand All

(-)file_io/unix/filedup.c (-2 / +21 lines)
Lines 24-44 Link Here
24
                             apr_file_t *old_file, apr_pool_t *p,
24
                             apr_file_t *old_file, apr_pool_t *p,
25
                             int which_dup)
25
                             int which_dup)
26
{
26
{
27
    int rv;
27
    int rv, flags = 0;
28
    
28
    
29
    if (which_dup == 2) {
29
    if (which_dup == 2) {
30
        if ((*new_file) == NULL) {
30
        if ((*new_file) == NULL) {
31
            /* We can't dup2 unless we have a valid new_file */
31
            /* We can't dup2 unless we have a valid new_file */
32
            return APR_EINVAL;
32
            return APR_EINVAL;
33
        }
33
        }
34
#ifdef HAVE_DUP3
35
        if (!(old_file->flags & APR_INHERIT))
36
            flags |= O_CLOEXEC;
37
        rv = dup3(old_file->filedes, (*new_file)->filedes, flags);
38
#else
34
        rv = dup2(old_file->filedes, (*new_file)->filedes);
39
        rv = dup2(old_file->filedes, (*new_file)->filedes);
40
#endif
35
    } else {
41
    } else {
36
        rv = dup(old_file->filedes);
42
        rv = dup(old_file->filedes);
37
    }
43
    }
38
44
39
    if (rv == -1)
45
    if (rv == -1)
40
        return errno;
46
        return errno;
41
    
47
48
    if (
49
#ifdef HAVE_DUP3
50
        (which_dup != 2) &&
51
#endif 
52
        !(old_file->flags & APR_INHERIT)) {
53
        flags = fcntl(old_file->filedes, F_GETFD);
54
        if (flags == -1)
55
            return errno;
56
        flags |= FD_CLOEXEC;
57
        if (fcntl(old_file->filedes, F_SETFD, flags) == -1)
58
            return errno;
59
    }
60
   
42
    if (which_dup == 1) {
61
    if (which_dup == 1) {
43
        (*new_file) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
62
        (*new_file) = (apr_file_t *)apr_pcalloc(p, sizeof(apr_file_t));
44
        (*new_file)->pool = p;
63
        (*new_file)->pool = p;

Return to bug 46425