summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorghelmer <ghelmer@FreeBSD.org>2012-01-10 18:43:27 +0000
committerghelmer <ghelmer@FreeBSD.org>2012-01-10 18:43:27 +0000
commitf6e21fcb264de7e7e3df9d592037f2dd84bb4008 (patch)
treeea55e76101d5ad51f74c363951121b3f9bdffbdd /lib/libutil
parent247e21eaf0336e81aa10ad6731f793e8deaabc69 (diff)
downloadFreeBSD-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.c14
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.
OpenPOWER on IntegriCloud