diff options
author | Derek Foreman <derekf@osg.samsung.com> | 2015-06-08 11:37:31 -0500 |
---|---|---|
committer | Bryce Harrington <bryce@osg.samsung.com> | 2015-07-16 19:28:36 -0700 |
commit | 6bc33d63cfc0799b85a8e62c3657b5a13de5a78a (patch) | |
tree | e78a6c2806bb3b3df82f20c4d77275296149a7b8 /shared | |
parent | 4a8a3a1c710b3d2cb795c96bd811c0484c2b497f (diff) |
log: Open log file CLOEXEC so child processes don't get the fd
Reviewed-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk>
Reviewed-by: Bryce Harrington <bryce@osg.samsung.com>
Signed-off-by: Derek Foreman <derekf@osg.samsung.com>
Diffstat (limited to 'shared')
-rw-r--r-- | shared/os-compatibility.c | 22 | ||||
-rw-r--r-- | shared/os-compatibility.h | 3 |
2 files changed, 17 insertions, 8 deletions
diff --git a/shared/os-compatibility.c b/shared/os-compatibility.c index b903347f..05999745 100644 --- a/shared/os-compatibility.c +++ b/shared/os-compatibility.c @@ -36,8 +36,8 @@ #include "os-compatibility.h" -static int -set_cloexec_or_close(int fd) +int +os_fd_set_cloexec(int fd) { long flags; @@ -46,16 +46,22 @@ set_cloexec_or_close(int fd) flags = fcntl(fd, F_GETFD); if (flags == -1) - goto err; + return -1; if (fcntl(fd, F_SETFD, flags | FD_CLOEXEC) == -1) - goto err; + return -1; - return fd; + return 0; +} -err: - close(fd); - return -1; +static int +set_cloexec_or_close(int fd) +{ + if (os_fd_set_cloexec(fd) != 0) { + close(fd); + return -1; + } + return fd; } int diff --git a/shared/os-compatibility.h b/shared/os-compatibility.h index a12ac0bd..06d25748 100644 --- a/shared/os-compatibility.h +++ b/shared/os-compatibility.h @@ -41,6 +41,9 @@ backtrace(void **buffer, int size) #endif int +os_fd_set_cloexec(int fd); + +int os_socketpair_cloexec(int domain, int type, int protocol, int *sv); int |