[PATCH 2/3] Move daemonPidFilePath into virutil.c

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Change daemonPidFilePath to virDaemonPidFilePath so it is accessible
in other parts of the code.

Signed-off-by: Martin Kletzander <mkletzan@xxxxxxxxxx>
---
 daemon/libvirtd.c        | 43 +++----------------------------------------
 src/libvirt_private.syms |  1 +
 src/util/virutil.c       | 39 +++++++++++++++++++++++++++++++++++++++
 src/util/virutil.h       |  4 ++++
 4 files changed, 47 insertions(+), 40 deletions(-)

diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index 38b7346..0dbe6d4 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1,7 +1,7 @@
 /*
  * libvirtd.c: daemon start of day, guest process & i/o management
  *
- * Copyright (C) 2006-2012 Red Hat, Inc.
+ * Copyright (C) 2006-2013 Red Hat, Inc.
  * Copyright (C) 2006 Daniel P. Berrange
  *
  * This library is free software; you can redistribute it and/or
@@ -237,43 +237,6 @@ error:


 static int
-daemonPidFilePath(bool privileged,
-                  char **pidfile)
-{
-    if (privileged) {
-        if (!(*pidfile = strdup(LOCALSTATEDIR "/run/libvirtd.pid")))
-            goto no_memory;
-    } 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 no_memory;
-        }
-
-        VIR_FREE(rundir);
-    }
-
-    return 0;
-
-no_memory:
-    virReportOOMError();
-error:
-    return -1;
-}
-
-static int
 daemonUnixSocketPaths(struct daemonConfig *config,
                       bool privileged,
                       char **sockfile,
@@ -1252,8 +1215,8 @@ int main(int argc, char **argv) {
     }

     if (!pid_file &&
-        daemonPidFilePath(privileged,
-                          &pid_file) < 0) {
+        virGetDaemonPidFilePath(privileged,
+                                &pid_file) < 0) {
         VIR_ERROR(_("Can't determine pid file path."));
         exit(EXIT_FAILURE);
     }
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 30fdcd7..d1989fd 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -1869,6 +1869,7 @@ virFileWriteStr;
 virFindFCHostCapableVport;
 virFindFileInPath;
 virFormatIntDecimal;
+virGetDaemonPidFilePath;
 virGetDeviceID;
 virGetDeviceUnprivSGIO;
 virGetFCHostNameByWWN;
diff --git a/src/util/virutil.c b/src/util/virutil.c
index 5fd0ce0..8b15894 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -90,6 +90,7 @@
 #include "nonblocking.h"
 #include "passfd.h"
 #include "virprocess.h"
+#include "configmake.h"

 #ifndef NSIG
 # define NSIG 32
@@ -2339,6 +2340,44 @@ check_and_return:
     return result;
 }

+
+int
+virGetDaemonPidFilePath(bool privileged,
+                        char **pidfile)
+{
+    if (privileged) {
+        if (!(*pidfile = strdup(LOCALSTATEDIR "/run/libvirtd.pid")))
+            goto no_memory;
+    } 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 no_memory;
+        }
+
+        VIR_FREE(rundir);
+    }
+
+    return 0;
+
+no_memory:
+    virReportOOMError();
+error:
+    return -1;
+}
+
 #ifdef HAVE_GETPWUID_R
 enum {
     VIR_USER_ENT_DIRECTORY,
diff --git a/src/util/virutil.h b/src/util/virutil.h
index 7b37d65..aa90c32 100644
--- a/src/util/virutil.h
+++ b/src/util/virutil.h
@@ -262,6 +262,10 @@ static inline int getgid (void) { return 0; }

 char *virGetHostname(virConnectPtr conn);

+int virGetDaemonPidFilePath(bool privileged,
+                            char **pidfile)
+    ATTRIBUTE_NONNULL(2);
+
 char *virGetUserDirectory(void);
 char *virGetUserConfigDirectory(void);
 char *virGetUserCacheDirectory(void);
-- 
1.8.1.5

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]