Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Feb 2012 14:11:24 +0000 (UTC)
From:      Guy Helmer <ghelmer@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r231087 - head/lib/libutil
Message-ID:  <201202061411.q16EBOwt039268@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ghelmer
Date: Mon Feb  6 14:11:24 2012
New Revision: 231087
URL: http://svn.freebsd.org/changeset/base/231087

Log:
  Using the O_CLOEXEC flag on open(2) caused the pidfile lock to be lost
  when the child process execs daemon's target program thanks to flock(2)
  semantics. So, we apparently have to leak the open pidfile's file
  descriptor to keep the lock for the pidfile(3) functions to work properly.
  
  Test case demonstrated by trociny:
  
  ref8-amd64:/home/trociny% uname -r
  8.2-STABLE
  ref8-amd64:/home/trociny% daemon -p /tmp/sleep.pid sleep 10
  ref8-amd64:/home/trociny% daemon -p /tmp/sleep.pid sleep 10
  daemon: process already running, pid: 19799
  
  kopusha:~% uname -r
  10.0-CURRENT
  kopusha:~% daemon -p /tmp/sleep.pid sleep 10
  kopusha:~% daemon -p /tmp/sleep.pid sleep 10
  kopusha:~%

Modified:
  head/lib/libutil/pidfile.c

Modified: head/lib/libutil/pidfile.c
==============================================================================
--- head/lib/libutil/pidfile.c	Mon Feb  6 13:36:49 2012	(r231086)
+++ head/lib/libutil/pidfile.c	Mon Feb  6 14:11:24 2012	(r231087)
@@ -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_CLOEXEC | O_NONBLOCK, mode);
+	    O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode);
 	if (fd == -1) {
 		if (errno == EWOULDBLOCK && pidptr != NULL) {
 			count = 20;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201202061411.q16EBOwt039268>