]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Sync latest from NetBSD.
authorRoy Marples <roy@marples.name>
Mon, 18 Apr 2016 08:34:56 +0000 (08:34 +0000)
committerRoy Marples <roy@marples.name>
Mon, 18 Apr 2016 08:34:56 +0000 (08:34 +0000)
compat/pidfile.c

index b301a574268c3a620401c30d34c5228558d9edfd..129c8d1d6b0fd70ae874a9eba2bb2286e18ad791 100644 (file)
@@ -1,4 +1,4 @@
-/*     $NetBSD: pidfile.c,v 1.12 2016/04/10 19:05:50 roy Exp $ */
+/*     $NetBSD: pidfile.c,v 1.14 2016/04/12 20:40:43 roy Exp $ */
 
 /*-
  * Copyright (c) 1999, 2016 The NetBSD Foundation, Inc.
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: pidfile.c,v 1.11 2015/01/22 19:04:28 christos Exp $");
+__RCSID("$NetBSD: pidfile.c,v 1.14 2016/04/12 20:40:43 roy Exp $");
 #endif
 
-#include <sys/file.h>
 #include <sys/param.h>
 
 #include <errno.h>
@@ -142,13 +141,12 @@ pidfile_read(const char *path)
        ssize_t n;
        pid_t pid;
 
-       if (path == NULL) {
-               if (pidfile_path[0] != '\0')
-                       path = pidfile_path;
-               else if (pidfile_varrun_path(dpath, sizeof(dpath), NULL) == -1)
+       if (path == NULL && pidfile_path[0] != '\0')
+               path = pidfile_path;
+       if (path == NULL || strchr(path, '/') == NULL) {
+               if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1)
                        return -1;
-               else
-                       path = dpath;
+               path = dpath;
        }
 
        if ((fd = open(path, O_RDONLY | O_NONBLOCK)) == -1)
@@ -190,14 +188,14 @@ pidfile_lock(const char *path)
        }
 
        if (path == NULL || strchr(path, '/') == NULL) {
-               if (pidfile_varrun_path(dpath, sizeof(dpath), NULL) == -1)
+               if (pidfile_varrun_path(dpath, sizeof(dpath), path) == -1)
                        return -1;
                path = dpath;
        }
 
        /* If path has changed (no good reason), clean up the old pidfile. */
-       if (strcmp(pidfile_path, path) != 0)
-               pidfile_cleanup();
+       if (pidfile_fd != -1 && strcmp(pidfile_path, path) != 0)
+               pidfile_clean();
 
        if (pidfile_fd == -1) {
                int fd, opts;