svn commit: r231938 - head/lib/libutil

Guy Helmer ghelmer at FreeBSD.org
Mon Feb 20 13:59:25 UTC 2012


Author: ghelmer
Date: Mon Feb 20 13:59:24 2012
New Revision: 231938
URL: http://svn.freebsd.org/changeset/base/231938

Log:
  Set the O_CLOEXEC flag when opening the pidfile to avoid leaking the
  file descriptor via exec(3).
  
  Now that daemon(8) has been fixed to resolve the issue noted by trociny,
  the consensus is that this change should be OK.

Modified:
  head/lib/libutil/pidfile.c

Modified: head/lib/libutil/pidfile.c
==============================================================================
--- head/lib/libutil/pidfile.c	Mon Feb 20 13:22:00 2012	(r231937)
+++ head/lib/libutil/pidfile.c	Mon Feb 20 13:59:24 2012	(r231938)
@@ -124,7 +124,7 @@ pidfile_open(const char *path, mode_t mo
 	 * 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;


More information about the svn-src-all mailing list