diff options
author | 2014-08-31 02:21:18 +0000 | |
---|---|---|
committer | 2014-08-31 02:21:18 +0000 | |
commit | ed42a740c17f7bea88482a716bacbc46a06b7249 (patch) | |
tree | 41266fb76fcd0cc0229b872cae91df94a24ad430 /lib/libc/gen/posix_spawn.c | |
parent | regen (diff) | |
download | wireguard-openbsd-ed42a740c17f7bea88482a716bacbc46a06b7249.tar.xz wireguard-openbsd-ed42a740c17f7bea88482a716bacbc46a06b7249.zip |
Add additional userland interfaces for setting close-on-exec on fds
when creating them: mkostemp(), mkostemps(), the 'e' mode letter for
fopen(), freopen(), fdopen(), and popen(). The close-on-exec flag will
be cleared by the action created by posix_spawn_file_actions_adddup2().
Also, add support for the C11 'x' mode letter for fopen() and freopen(),
setting O_EXCL when possibly creating files.
Note: this requires kernel support for pipe2() and dup3()!
ok millert@
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: |