}
-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,
}
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);
}
virPidFileAcquire;
virPidFileAcquirePath;
virPidFileBuildPath;
+virPidFileConstructPath;
virPidFileDelete;
virPidFileDeletePath;
virPidFileRead;
}
-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)
}
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);
}
/*
* 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
*
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;
+}
/*
* 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
*
const char *name,
int fd);
+int virPidFileConstructPath(bool privileged,
+ const char *statedir,
+ const char *progname,
+ char **pidfile);
+
#endif /* __VIR_PIDFILE_H__ */