summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorpjd <pjd@FreeBSD.org>2013-03-14 20:22:52 +0000
committerpjd <pjd@FreeBSD.org>2013-03-14 20:22:52 +0000
commit1b62958b4e3fc6e1ea024e0c6d27308be8a97a46 (patch)
tree38ea865b333d6b945882197ba73331589eabd9ae /lib/libutil
parent63efc821c3e4785928997ea88e1de93e62ce3acb (diff)
downloadFreeBSD-src-1b62958b4e3fc6e1ea024e0c6d27308be8a97a46.zip
FreeBSD-src-1b62958b4e3fc6e1ea024e0c6d27308be8a97a46.tar.gz
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
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/pidfile.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/libutil/pidfile.c b/lib/libutil/pidfile.c
index bca0315..7949e9e 100644
--- a/lib/libutil/pidfile.c
+++ b/lib/libutil/pidfile.c
@@ -126,20 +126,25 @@ pidfile_open(const char *path, mode_t mode, pid_t *pidptr)
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);
OpenPOWER on IntegriCloud