On Thu, Apr 18, 2013 at 12:30:55PM +0200, Martin Kletzander wrote:
Change daemonPidFilePath to virDaemonPidFilePath so it is accessible
in other parts of the code.
Signed-off-by: Martin Kletzander <mkletzan(a)redhat.com>
---
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;
+}
This method is pretending to be generic, but in fact the path is
completely specific to libvirtd, so won't work with virtlockd
for example.
Daniel
--
|:
http://berrange.com -o-
http://www.flickr.com/photos/dberrange/ :|
|:
http://libvirt.org -o-
http://virt-manager.org :|
|:
http://autobuild.org -o-
http://search.cpan.org/~danberr/ :|
|:
http://entangle-photo.org -o-
http://live.gnome.org/gtk-vnc :|