]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
remove redundant pidfile path constructions
authorMartin Kletzander <mkletzan@redhat.com>
Sun, 7 Sep 2014 17:52:34 +0000 (19:52 +0200)
committerMartin Kletzander <mkletzan@redhat.com>
Mon, 15 Sep 2014 07:49:34 +0000 (09:49 +0200)
Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
daemon/libvirtd.c
src/libvirt_private.syms
src/locking/lock_daemon.c
src/util/virpidfile.c
src/util/virpidfile.h

index 05ee50e08cc22cf4db7ad1bc3cd06a78f53cf93e..9ad8ff5471447285a779e7635ce3842333b3fb8e 100644 (file)
@@ -250,41 +250,6 @@ static int daemonForkIntoBackground(const char *argv0)
 }
 
 
-static int
-daemonPidFilePath(bool privileged,
-                  char **pidfile)
-{
-    if (privileged) {
-        if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/libvirtd.pid") < 0)
-            goto error;
-    } else {
-        char *rundir = NULL;
-        mode_t old_umask;
-
-        if (!(rundir = virGetUserRuntimeDirectory()))
-            goto error;
-
-        old_umask = umask(077);
-        if (virFileMakePath(rundir) < 0) {
-            umask(old_umask);
-            goto error;
-        }
-        umask(old_umask);
-
-        if (virAsprintf(pidfile, "%s/libvirtd.pid", rundir) < 0) {
-            VIR_FREE(rundir);
-            goto error;
-        }
-
-        VIR_FREE(rundir);
-    }
-
-    return 0;
-
- error:
-    return -1;
-}
-
 static int
 daemonUnixSocketPaths(struct daemonConfig *config,
                       bool privileged,
@@ -1313,8 +1278,10 @@ int main(int argc, char **argv) {
     }
 
     if (!pid_file &&
-        daemonPidFilePath(privileged,
-                          &pid_file) < 0) {
+        virPidFileConstructPath(privileged,
+                                LOCALSTATEDIR,
+                                "libvirtd",
+                                &pid_file) < 0) {
         VIR_ERROR(_("Can't determine pid file path."));
         exit(EXIT_FAILURE);
     }
index e819049496c8f4cfabd486797af83ae94fcbbf48..f128b0ccfc282258ebb2ca66b38ba46b1320d87a 100644 (file)
@@ -1778,6 +1778,7 @@ virPCIIsVirtualFunction;
 virPidFileAcquire;
 virPidFileAcquirePath;
 virPidFileBuildPath;
+virPidFileConstructPath;
 virPidFileDelete;
 virPidFileDeletePath;
 virPidFileRead;
index 02d77e39a8d73c45a387923d8c6d2e7e3466d2a1..fe7cfb87a36f2cd8c19b2f61584d9aee9d126b49 100644 (file)
@@ -365,42 +365,6 @@ virLockDaemonForkIntoBackground(const char *argv0)
 }
 
 
-static int
-virLockDaemonPidFilePath(bool privileged,
-                         char **pidfile)
-{
-    if (privileged) {
-        if (VIR_STRDUP(*pidfile, LOCALSTATEDIR "/run/virtlockd.pid") < 0)
-            goto error;
-    } else {
-        char *rundir = NULL;
-        mode_t old_umask;
-
-        if (!(rundir = virGetUserRuntimeDirectory()))
-            goto error;
-
-        old_umask = umask(077);
-        if (virFileMakePath(rundir) < 0) {
-            umask(old_umask);
-            goto error;
-        }
-        umask(old_umask);
-
-        if (virAsprintf(pidfile, "%s/virtlockd.pid", rundir) < 0) {
-            VIR_FREE(rundir);
-            goto error;
-        }
-
-        VIR_FREE(rundir);
-    }
-
-    return 0;
-
- error:
-    return -1;
-}
-
-
 static int
 virLockDaemonUnixSocketPaths(bool privileged,
                              char **sockfile)
@@ -1283,8 +1247,10 @@ int main(int argc, char **argv) {
     }
 
     if (!pid_file &&
-        virLockDaemonPidFilePath(privileged,
-                                 &pid_file) < 0) {
+        virPidFileConstructPath(privileged,
+                                LOCALSTATEDIR,
+                                "virtlockd",
+                                &pid_file) < 0) {
         VIR_ERROR(_("Can't determine pid file path."));
         exit(EXIT_FAILURE);
     }
index 1d9a1c52ab1d67513392c1955870ff1848008050..19ec103ce85750cffe8f9c59eae6d9792434f3ff 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virpidfile.c: manipulation of pidfiles
  *
- * Copyright (C) 2010-2012 Red Hat, Inc.
+ * Copyright (C) 2010-2012, 2014 Red Hat, Inc.
  * Copyright (C) 2006, 2007 Binary Karma
  * Copyright (C) 2006 Shuveb Hussain
  *
@@ -521,3 +521,50 @@ int virPidFileRelease(const char *dir,
     VIR_FREE(pidfile);
     return rc;
 }
+
+
+int
+virPidFileConstructPath(bool privileged,
+                        const char *statedir,
+                        const char *progname,
+                        char **pidfile)
+{
+    if (privileged) {
+        /*
+         * This is here just to allow calling this function with
+         * statedir == NULL; of course only when !privileged.
+         */
+        if (!statedir) {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           "%s", _("No statedir specified"));
+            goto cleanup;
+        }
+        if (virAsprintf(pidfile, "%s/run/%s.pid", statedir, progname) < 0)
+            goto cleanup;
+    } else {
+        char *rundir = NULL;
+        mode_t old_umask;
+
+        if (!(rundir = virGetUserRuntimeDirectory()))
+            goto error;
+
+        old_umask = umask(077);
+        if (virFileMakePath(rundir) < 0) {
+            umask(old_umask);
+            goto error;
+        }
+        umask(old_umask);
+
+        if (virAsprintf(pidfile, "%s/%s.pid", rundir, progname) < 0) {
+            VIR_FREE(rundir);
+            goto error;
+        }
+
+        VIR_FREE(rundir);
+    }
+
+    return 0;
+
+ error:
+    return -1;
+}
index 2720206cccb0d8dc4df2f9e1d9e2d4dc7c110b61..ca1dbff2e38099aceb43729bd210a789a4e85484 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * virpidfile.h: manipulation of pidfiles
  *
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2011, 2014 Red Hat, Inc.
  * Copyright (C) 2006, 2007 Binary Karma
  * Copyright (C) 2006 Shuveb Hussain
  *
@@ -69,4 +69,9 @@ int virPidFileRelease(const char *dir,
                       const char *name,
                       int fd);
 
+int virPidFileConstructPath(bool privileged,
+                            const char *statedir,
+                            const char *progname,
+                            char **pidfile);
+
 #endif /* __VIR_PIDFILE_H__ */