diff options
Diffstat (limited to 'lib/libc/gen/posix_spawn.c')
-rw-r--r-- | lib/libc/gen/posix_spawn.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/lib/libc/gen/posix_spawn.c b/lib/libc/gen/posix_spawn.c index acfe68c63c5..c45080b1a11 100644 --- a/lib/libc/gen/posix_spawn.c +++ b/lib/libc/gen/posix_spawn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: posix_spawn.c,v 1.3 2012/12/05 23:20:00 deraadt Exp $ */ +/* $OpenBSD: posix_spawn.c,v 1.4 2014/08/31 02:21:18 guenther Exp $ */ /*- * Copyright (c) 2008 Ed Schouten <ed@FreeBSD.org> * All rights reserved. @@ -155,8 +155,17 @@ process_file_actions_entry(posix_spawn_file_actions_entry_t *fae) } break; case FAE_DUP2: - /* Perform a dup2() */ - if (dup2(fae->fae_fildes, fae->fae_newfildes) == -1) + /* + * Perform a dup2(), making sure the FD_CLOEXEC flag is clear + */ + if (fae->fae_fildes == fae->fae_newfildes) { + int flags = fcntl(fd, F_GETFD); + + if (flags == -1 || + ((flags & FD_CLOEXEC) && + fcntl(fd, F_SETFD, flags & ~FD_CLOEXEC) == -1)) + return (errno); + } else if (dup2(fae->fae_fildes, fae->fae_newfildes) == -1) return (errno); break; case FAE_CLOSE: |