]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Fix pidfile_lock compat on Linux.
authorRoy Marples <roy@marples.name>
Fri, 1 Apr 2016 21:27:22 +0000 (21:27 +0000)
committerRoy Marples <roy@marples.name>
Fri, 1 Apr 2016 21:27:22 +0000 (21:27 +0000)
compat/pidfile.c
dhcpcd.c

index 74367020eba6ea50fbf371a77d53941e4d1d9af7..8adc1a0fb43a2a5e6b6ecd8f64b0656e1e330c66 100644 (file)
@@ -25,6 +25,8 @@
  * SUCH DAMAGE.
  */
 
+#include <sys/file.h>
+
 #include <errno.h>
 #include <fcntl.h>
 #include <inttypes.h>
@@ -37,7 +39,7 @@
 #include <unistd.h>
 
 #include "pidfile.h"
-#include "../defs.h"
+#include "../config.h"
 
 static pid_t pidfile_pid;
 static char *pidfile_path;
@@ -146,7 +148,7 @@ pidfile_lock(const char *path)
                        pidfile_fd = -1;
                        /* Don't unlink, other process has lock. */
                        errno = error;
-                       return -1;
+                       return errno == EAGAIN ? pidfile_read(path) : -1;
                }
 #endif
 #ifndef O_CLOEXEC
index a6863a80da20d4ec7fc2bda7003861056c1fcaf8..ac5720a44fd3bf59368a84d0321e185bd74f05c8 100644 (file)
--- a/dhcpcd.c
+++ b/dhcpcd.c
@@ -1800,9 +1800,13 @@ printpidfile:
 
        if (!(ctx.options & DHCPCD_TEST)) {
                if ((pid = pidfile_lock(ctx.pidfile)) != 0) {
-                       logger(&ctx, LOG_ERR, ""PACKAGE
-                           " already running on pid %d (%s)",
-                           pid, ctx.pidfile);
+                       if (pid == -1)
+                               logger(&ctx, LOG_ERR, "%s: pidfile_lock: %m",
+                                   __func__);
+                       else    
+                               logger(&ctx, LOG_ERR, ""PACKAGE
+                                   " already running on pid %d (%s)",
+                                   pid, ctx.pidfile);
                        goto exit_failure;
                }