pidfile_open incorrectly returns EAGAIN when pidfile is locked

From: Dirk Engling <erdgeist_at_erdgeist.org>
Date: Tue, 12 Mar 2013 21:16:32 +0100
While debugging my own daemon I noticed that pidfile_open does not
perform the appropriate checks for a running daemon if the caller does
not provide a pidptr to pidfile_open

fd = flopen(pfh->pf_path,
	    O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode);

fails when another daemon holds the lock and flopen sets errno to
EAGAIN, the check 4 lines below in

		if (errno == EWOULDBLOCK && pidptr != NULL) {

means that the pidfile_read is never executed.

This results in my second daemon receiving an EAGAIN which clearly was
meant to report a race condition between two daemons starting at the
same time and the first one not yet finishing pidfile_write.

The expected behavior would be to set errno to EEXIST, even if no pidptr
was passed.

Regards,

  erdgeist
Received on Tue Mar 12 2013 - 19:16:35 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:35 UTC