Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Mar 2013 20:22:52 +0000 (UTC)
From:      Pawel Jakub Dawidek <pjd@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r248281 - head/lib/libutil
Message-ID:  <201303142022.r2EKMqMh006617@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: pjd
Date: Thu Mar 14 20:22:52 2013
New Revision: 248281
URL: http://svnweb.freebsd.org/changeset/base/248281

Log:
  When pidptr was passed as NULL to pidfile_open(3), we were returning
  EAGAIN/EWOULDBLOCK when another daemon was running and had the pidfile open.
  We should return EEXIST in that case, fix it.
  
  Reported by:	Dirk Engling <erdgeist@erdgeist.org>
  Reviewed by:	jhb, Dirk Engling <erdgeist@erdgeist.org>
  MFC after:	1 week

Modified:
  head/lib/libutil/pidfile.c

Modified: head/lib/libutil/pidfile.c
==============================================================================
--- head/lib/libutil/pidfile.c	Thu Mar 14 20:18:12 2013	(r248280)
+++ head/lib/libutil/pidfile.c	Thu Mar 14 20:22:52 2013	(r248281)
@@ -126,20 +126,25 @@ pidfile_open(const char *path, mode_t mo
 	fd = flopen(pfh->pf_path,
 	    O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode);
 	if (fd == -1) {
-		if (errno == EWOULDBLOCK && pidptr != NULL) {
-			count = 20;
-			rqtp.tv_sec = 0;
-			rqtp.tv_nsec = 5000000;
-			for (;;) {
-				errno = pidfile_read(pfh->pf_path, pidptr);
-				if (errno != EAGAIN || --count == 0)
-					break;
-				nanosleep(&rqtp, 0);
-			}
-			if (errno == EAGAIN)
-				*pidptr = -1;
-			if (errno == 0 || errno == EAGAIN)
+		if (errno == EWOULDBLOCK) {
+			if (pidptr == NULL) {
 				errno = EEXIST;
+			} else {
+				count = 20;
+				rqtp.tv_sec = 0;
+				rqtp.tv_nsec = 5000000;
+				for (;;) {
+					errno = pidfile_read(pfh->pf_path,
+					    pidptr);
+					if (errno != EAGAIN || --count == 0)
+						break;
+					nanosleep(&rqtp, 0);
+				}
+				if (errno == EAGAIN)
+					*pidptr = -1;
+				if (errno == 0 || errno == EAGAIN)
+					errno = EEXIST;
+			}
 		}
 		free(pfh);
 		return (NULL);



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