diff options
author | ghelmer <ghelmer@FreeBSD.org> | 2012-01-10 18:43:27 +0000 |
---|---|---|
committer | ghelmer <ghelmer@FreeBSD.org> | 2012-01-10 18:43:27 +0000 |
commit | f6e21fcb264de7e7e3df9d592037f2dd84bb4008 (patch) | |
tree | ea55e76101d5ad51f74c363951121b3f9bdffbdd /lib/libutil | |
parent | 247e21eaf0336e81aa10ad6731f793e8deaabc69 (diff) | |
download | FreeBSD-src-f6e21fcb264de7e7e3df9d592037f2dd84bb4008.zip FreeBSD-src-f6e21fcb264de7e7e3df9d592037f2dd84bb4008.tar.gz |
Set the FD_CLOEXEC flag on the open pidfile file descriptor.
Discussed with: pjd, des
Diffstat (limited to 'lib/libutil')
-rw-r--r-- | lib/libutil/pidfile.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c index 953d1e0..fcd504c 100644 --- a/lib/libutil/pidfile.c +++ b/lib/libutil/pidfile.c @@ -137,6 +137,20 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr) free(pfh); return (NULL); } + + /* + * 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. |