diff options
author | ghelmer <ghelmer@FreeBSD.org> | 2012-01-11 16:35:26 +0000 |
---|---|---|
committer | ghelmer <ghelmer@FreeBSD.org> | 2012-01-11 16:35:26 +0000 |
commit | 5f5cbaa5f6d44d5f62a291801325f3d3e6896b06 (patch) | |
tree | 94e62c2d6a53bd454f708567e70912052b5a7774 /lib/libutil | |
parent | a2848bd240339bb07b647bb82bc7a4043e977d3f (diff) | |
download | FreeBSD-src-5f5cbaa5f6d44d5f62a291801325f3d3e6896b06.zip FreeBSD-src-5f5cbaa5f6d44d5f62a291801325f3d3e6896b06.tar.gz |
jilles pointed out that O_CLOEXEC could be used in the open(2) flags
rather than using fcntl(2) later, and in addition to saving a system
call, removes a possible race with fork/exec from threads or signal
handlers.
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/pidfile.c | 15 |
1 files changed, 1 insertions, 14 deletions
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index ba95756..60f81fd 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -117,7 +117,7 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) * pidfile_write() can be called multiple times. */ fd = flopen(pfh->pf_path, - O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); + O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode); if (fd == -1) { if (errno == EWOULDBLOCK && pidptr != NULL) { count = 20; @@ -139,19 +139,6 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) } /* - * Prevent the file descriptor from escaping to other - * programs via exec(3). - */ - if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1) { - error = errno; - unlink(pfh->pf_path); - close(fd); - free(pfh); - errno = error; - return (NULL); - } - - /* * Remember file information, so in pidfile_write() we are sure we write * to the proper descriptor. */ |