提交 98352a10 编写于 作者: J Jim Meyering

libvirtd: new config-file option: unix_sock_dir

Before this change, the unix socket directory was hard-coded
to be e.g., /var/run/libvirt for euid==0 and ~/.libvirt otherwise.
With this change, you may now specify that directory in libvirtd's
config file via a line like this: unix_sock_dir = "/var/run/libvirt".
This is essential for running tests that do not impinge on any
existing libvirtd process, and in running tests in parallel.
* qemud/libvirtd.conf (unix_sock_dir): Add comment and example.
* qemud/qemud.h (struct qemud_server) [logDir]: Change type
from char[PATH_MAX] to char*.
* qemud/qemud.c (unix_sock_dir): New global
(remoteReadConfigFile): Set the global.
(qemudInitPaths): Use the global, unix_sock_dir, if non-NULL.
One minor improvement: unlink both sockets or none, never
just one of them.
(qemudCleanup): Free logDir.
(main): Use the new global rather than hard-coding "/run/libvirt".
* qemud/libvirtd.aug (sock_acl_entry): Add "unix_sock_dir".
上级 3557096d
Mon Feb 9 17:26:07 +0100 2009 Jim Meyering <meyering@redhat.com>
libvirtd: new config-file option: unix_sock_dir
Before this change, the unix socket directory was hard-coded
to be e.g., /var/run/libvirt for euid==0 and ~/.libvirt otherwise.
With this change, you may now specify that directory in libvirtd's
config file via a line like this: unix_sock_dir = "/var/run/libvirt".
This is essential for running tests that do not impinge on any
existing libvirtd process, and in running tests in parallel.
* qemud/libvirtd.conf (unix_sock_dir): Add comment and example.
* qemud/qemud.h (struct qemud_server) [logDir]: Change type
from char[PATH_MAX] to char*.
* qemud/qemud.c (unix_sock_dir): New global
(remoteReadConfigFile): Set the global.
(qemudInitPaths): Use the global, unix_sock_dir, if non-NULL.
One minor improvement: unlink both sockets or none, never
just one of them.
(qemudCleanup): Free logDir.
(main): Use the new global rather than hard-coding "/run/libvirt".
* qemud/libvirtd.aug (sock_acl_entry): Add "unix_sock_dir".
Mon Feb 9 10:13:28 +0100 2009 Jim Meyering <meyering@redhat.com> Mon Feb 9 10:13:28 +0100 2009 Jim Meyering <meyering@redhat.com>
don't print uninitialized in debug diagnostic don't print uninitialized in debug diagnostic
......
...@@ -35,6 +35,7 @@ module Libvirtd = ...@@ -35,6 +35,7 @@ module Libvirtd =
let sock_acl_entry = str_entry "unix_sock_group" let sock_acl_entry = str_entry "unix_sock_group"
| str_entry "unix_sock_ro_perms" | str_entry "unix_sock_ro_perms"
| str_entry "unix_sock_rw_perms" | str_entry "unix_sock_rw_perms"
| str_entry "unix_sock_dir"
let authentication_entry = str_entry "auth_unix_ro" let authentication_entry = str_entry "auth_unix_ro"
| str_entry "auth_unix_rw" | str_entry "auth_unix_rw"
...@@ -79,4 +80,3 @@ module Libvirtd = ...@@ -79,4 +80,3 @@ module Libvirtd =
. Util.stdexcl . Util.stdexcl
let xfm = transform lns filter let xfm = transform lns filter
...@@ -97,7 +97,8 @@ ...@@ -97,7 +97,8 @@
# control then you may want to relax this to: # control then you may want to relax this to:
#unix_sock_rw_perms = "0770" #unix_sock_rw_perms = "0770"
# Set the name of the directory in which sockets will be found/created.
#unix_sock_dir = "/var/run/libvirt"
################################################################# #################################################################
# #
......
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
#include "libvirt_internal.h" #include "libvirt_internal.h"
#include "virterror_internal.h" #include "virterror_internal.h"
#define VIR_FROM_THIS VIR_FROM_QEMU
#include "qemud.h" #include "qemud.h"
#include "util.h" #include "util.h"
#include "remote_internal.h" #include "remote_internal.h"
...@@ -136,6 +138,8 @@ static char *listen_addr = (char *) LIBVIRTD_LISTEN_ADDR; ...@@ -136,6 +138,8 @@ static char *listen_addr = (char *) LIBVIRTD_LISTEN_ADDR;
static char *tls_port = (char *) LIBVIRTD_TLS_PORT; static char *tls_port = (char *) LIBVIRTD_TLS_PORT;
static char *tcp_port = (char *) LIBVIRTD_TCP_PORT; static char *tcp_port = (char *) LIBVIRTD_TCP_PORT;
static char *unix_sock_dir = NULL;
#if HAVE_POLKIT #if HAVE_POLKIT
static int auth_unix_rw = REMOTE_AUTH_POLKIT; static int auth_unix_rw = REMOTE_AUTH_POLKIT;
static int auth_unix_ro = REMOTE_AUTH_POLKIT; static int auth_unix_ro = REMOTE_AUTH_POLKIT;
...@@ -712,46 +716,75 @@ static int qemudInitPaths(struct qemud_server *server, ...@@ -712,46 +716,75 @@ static int qemudInitPaths(struct qemud_server *server,
int maxlen) int maxlen)
{ {
uid_t uid = geteuid(); uid_t uid = geteuid();
char *sock_dir;
char *dir_prefix = NULL;
int ret = -1;
char *sock_dir_prefix = NULL;
if (unix_sock_dir)
sock_dir = unix_sock_dir;
else {
sock_dir = sockname;
if (uid == SYSTEM_UID) { if (uid == SYSTEM_UID) {
if (snprintf (sockname, maxlen, "%s/run/libvirt/libvirt-sock", dir_prefix = strdup (LOCAL_STATE_DIR);
LOCAL_STATE_DIR) >= maxlen) if (dir_prefix == NULL) {
goto snprintf_error; virReportOOMError(NULL);
goto cleanup;
unlink(sockname); }
if (snprintf (sock_dir, maxlen, "%s/run/libvirt",
if (snprintf (roSockname, maxlen, "%s/run/libvirt/libvirt-sock-ro", dir_prefix) >= maxlen)
LOCAL_STATE_DIR) >= maxlen)
goto snprintf_error;
unlink(roSockname);
if (snprintf(server->logDir, PATH_MAX, "%s/log/libvirt/", LOCAL_STATE_DIR) >= PATH_MAX)
goto snprintf_error; goto snprintf_error;
} else { } else {
char *userdir = virGetUserDirectory(NULL, uid); dir_prefix = virGetUserDirectory(NULL, uid);
if (userdir == NULL) { if (dir_prefix == NULL) {
/* Do not diagnose here; virGetUserDirectory does that. */ /* Do not diagnose here; virGetUserDirectory does that. */
return -1; goto snprintf_error;
} }
if (snprintf(sockname, maxlen, "@%s/.libvirt/libvirt-sock", userdir) >= maxlen) { if (snprintf(sock_dir, maxlen, "%s/.libvirt", dir_prefix) >= maxlen)
VIR_FREE(userdir);
goto snprintf_error; goto snprintf_error;
} }
}
sock_dir_prefix = strdup (sock_dir);
if (!sock_dir_prefix) {
virReportOOMError(NULL);
goto cleanup;
}
if (snprintf(server->logDir, PATH_MAX, "%s/.libvirt/log", userdir) >= PATH_MAX) { if (uid == SYSTEM_UID) {
VIR_FREE(userdir); if (snprintf (sockname, maxlen, "%s/libvirt-sock",
sock_dir_prefix) >= maxlen
|| (snprintf (roSockname, maxlen, "%s/libvirt-sock-ro",
sock_dir_prefix) >= maxlen))
goto snprintf_error;
unlink(sockname);
unlink(roSockname);
} else {
if (snprintf(sockname, maxlen, "@%s/libvirt-sock",
sock_dir_prefix) >= maxlen)
goto snprintf_error; goto snprintf_error;
} }
VIR_FREE(userdir);
} /* !remote */
return 0; if (uid == SYSTEM_UID)
server->logDir = strdup (LOCAL_STATE_DIR "/log/libvirt");
else
virAsprintf(&server->logDir, "%s/.libvirt/log", dir_prefix);
if (server->logDir == NULL)
virReportOOMError(NULL);
ret = 0;
snprintf_error: snprintf_error:
VIR_ERROR("%s", _("Resulting path too long for buffer in qemudInitPaths()")); if (ret)
return -1; VIR_ERROR("%s",
_("Resulting path too long for buffer in qemudInitPaths()"));
cleanup:
free (dir_prefix);
free (sock_dir_prefix);
return ret;
} }
static struct qemud_server *qemudInitialize(int sigread) { static struct qemud_server *qemudInitialize(int sigread) {
...@@ -2208,6 +2241,7 @@ static void qemudCleanup(struct qemud_server *server) { ...@@ -2208,6 +2241,7 @@ static void qemudCleanup(struct qemud_server *server) {
free(sock); free(sock);
sock = next; sock = next;
} }
free(server->logDir);
#ifdef HAVE_SASL #ifdef HAVE_SASL
if (server->saslUsernameWhitelist) { if (server->saslUsernameWhitelist) {
...@@ -2556,6 +2590,8 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename) ...@@ -2556,6 +2590,8 @@ remoteReadConfigFile (struct qemud_server *server, const char *filename)
unix_sock_rw_perms = NULL; unix_sock_rw_perms = NULL;
} }
GET_CONF_STR (conf, filename, unix_sock_dir);
GET_CONF_INT (conf, filename, mdns_adv); GET_CONF_INT (conf, filename, mdns_adv);
GET_CONF_STR (conf, filename, mdns_name); GET_CONF_STR (conf, filename, mdns_name);
...@@ -2846,11 +2882,10 @@ int main(int argc, char **argv) { ...@@ -2846,11 +2882,10 @@ int main(int argc, char **argv) {
goto error2; goto error2;
/* Change the group ownership of /var/run/libvirt to unix_sock_gid */ /* Change the group ownership of /var/run/libvirt to unix_sock_gid */
if (getuid() == 0) { if (unix_sock_dir && geteuid() == 0) {
const char *sockdirname = LOCAL_STATE_DIR "/run/libvirt"; if (chown(unix_sock_dir, -1, unix_sock_gid) < 0)
VIR_ERROR(_("Failed to change group ownership of %s"),
if (chown(sockdirname, -1, unix_sock_gid) < 0) unix_sock_dir);
VIR_ERROR(_("Failed to change group ownership of %s"), sockdirname);
} }
if (virEventAddHandleImpl(sigpipe[0], if (virEventAddHandleImpl(sigpipe[0],
......
/* /*
* qemud.h: daemon data structure definitions * qemud.h: daemon data structure definitions
* *
* Copyright (C) 2006-2008 Red Hat, Inc. * Copyright (C) 2006-2009 Red Hat, Inc.
* Copyright (C) 2006 Daniel P. Berrange * Copyright (C) 2006 Daniel P. Berrange
* *
* This library is free software; you can redistribute it and/or * This library is free software; you can redistribute it and/or
...@@ -181,7 +181,7 @@ struct qemud_server { ...@@ -181,7 +181,7 @@ struct qemud_server {
struct qemud_client **clients; struct qemud_client **clients;
int sigread; int sigread;
char logDir[PATH_MAX]; char *logDir;
unsigned int shutdown : 1; unsigned int shutdown : 1;
#ifdef HAVE_AVAHI #ifdef HAVE_AVAHI
struct libvirtd_mdns *mdns; struct libvirtd_mdns *mdns;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册