
Hi, Eric This patch is second version, but I forgot adding patch version at mail's title. Should I send this patch with correct title again? :) And thanks for your patch review and reply. 于 2011年08月29日 10:52, xuhj@linux.vnet.ibm.com 写道:
From: Xu He Jie <xuhj@linux.vnet.ibm.com>
Signed-off-by: Xu He Jie <xuhj@linux.vnet.ibm.com>
When libvirtd is running at non-root user, it won't create ${HOME}/.libvirt.
It will show error message: 17:44:16.838: 7035: error : virPidFileAcquirePath:322 : Failed to open pid file
--- daemon/libvirtd.c | 46 ++++++++++++++++++++++++++++++++-------------- 1 files changed, 32 insertions(+), 14 deletions(-)
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c index 423c3d7..e0004c7 100644 --- a/daemon/libvirtd.c +++ b/daemon/libvirtd.c @@ -1249,6 +1249,7 @@ int main(int argc, char **argv) { bool privileged = geteuid() == 0 ? true : false; bool implicit_conf = false; bool use_polkit_dbus; + char *run_dir = NULL;
struct option opts[] = { { "verbose", no_argument, &verbose, 1}, @@ -1403,21 +1404,35 @@ int main(int argc, char **argv) {
/* Ensure the rundir exists (on tmpfs on some systems) */ if (privileged) { - const char *rundir = LOCALSTATEDIR "/run/libvirt"; - mode_t old_umask; - - old_umask = umask(022); - if (mkdir (rundir, 0755)) { - if (errno != EEXIST) { - char ebuf[1024]; - VIR_ERROR(_("unable to create rundir %s: %s"), rundir, - virStrerror(errno, ebuf, sizeof(ebuf))); - ret = VIR_DAEMON_ERR_RUNDIR; - umask(old_umask); - goto cleanup; - } + run_dir = strdup(LOCALSTATEDIR "/run/libvirt"); + if (!run_dir) { + VIR_ERROR(_("Can't allocate memory")); + goto cleanup; + } + } + else { + char *user_dir = NULL; + + if (!(user_dir = virGetUserDirectory(geteuid()))) { + VIR_ERROR(_("Can't determine user directory")); + goto cleanup; + } + + if (virAsprintf(&run_dir, "%s/.libvirt/", user_dir) < 0) { + VIR_ERROR(_("Can't allocate memory")); + VIR_FREE(user_dir); + goto cleanup; } - umask(old_umask); + + VIR_FREE(user_dir); + } + + if (virFileMakePath(run_dir) < 0) { + char ebuf[1024]; + VIR_ERROR(_("unable to create rundir %s: %s"), run_dir, + virStrerror(errno, ebuf, sizeof(ebuf))); + ret = VIR_DAEMON_ERR_RUNDIR; + goto cleanup; }
/* Try to claim the pidfile, exiting if we can't */ @@ -1571,6 +1586,9 @@ cleanup: VIR_FREE(sock_file_ro); VIR_FREE(pid_file); VIR_FREE(remote_config_file); + if (run_dir) + VIR_FREE(run_dir); + daemonConfigFree(config); virLogShutdown();