mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
libvirtd: create run dir when running at non-root user
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
Signed-off-by: Xu He Jie <xuhj@linux.vnet.ibm.com>
Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
1
AUTHORS
1
AUTHORS
@@ -192,6 +192,7 @@ Patches have also been contributed by:
|
|||||||
Tom Vijlbrief <tom.vijlbrief@xs4all.nl>
|
Tom Vijlbrief <tom.vijlbrief@xs4all.nl>
|
||||||
Shradha Shah <sshah@solarflare.com>
|
Shradha Shah <sshah@solarflare.com>
|
||||||
Steve Hodgson <shodgson@solarflare.com>
|
Steve Hodgson <shodgson@solarflare.com>
|
||||||
|
Xu He Jie <xuhj@linux.vnet.ibm.com>
|
||||||
|
|
||||||
[....send patches to get your name here....]
|
[....send patches to get your name here....]
|
||||||
|
|
||||||
|
|||||||
@@ -1249,6 +1249,8 @@ int main(int argc, char **argv) {
|
|||||||
bool privileged = geteuid() == 0 ? true : false;
|
bool privileged = geteuid() == 0 ? true : false;
|
||||||
bool implicit_conf = false;
|
bool implicit_conf = false;
|
||||||
bool use_polkit_dbus;
|
bool use_polkit_dbus;
|
||||||
|
char *run_dir = NULL;
|
||||||
|
mode_t old_umask;
|
||||||
|
|
||||||
struct option opts[] = {
|
struct option opts[] = {
|
||||||
{ "verbose", no_argument, &verbose, 1},
|
{ "verbose", no_argument, &verbose, 1},
|
||||||
@@ -1403,22 +1405,31 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
/* Ensure the rundir exists (on tmpfs on some systems) */
|
/* Ensure the rundir exists (on tmpfs on some systems) */
|
||||||
if (privileged) {
|
if (privileged) {
|
||||||
const char *rundir = LOCALSTATEDIR "/run/libvirt";
|
run_dir = strdup(LOCALSTATEDIR "/run/libvirt");
|
||||||
mode_t old_umask;
|
} else {
|
||||||
|
char *user_dir = virGetUserDirectory(geteuid());
|
||||||
|
|
||||||
old_umask = umask(022);
|
if (!user_dir) {
|
||||||
if (mkdir (rundir, 0755)) {
|
VIR_ERROR(_("Can't determine user directory"));
|
||||||
if (errno != EEXIST) {
|
goto cleanup;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
umask(old_umask);
|
ignore_value(virAsprintf(&run_dir, "%s/.libvirt/", user_dir));
|
||||||
|
VIR_FREE(user_dir);
|
||||||
}
|
}
|
||||||
|
if (!run_dir) {
|
||||||
|
virReportOOMError();
|
||||||
|
goto cleanup;
|
||||||
|
}
|
||||||
|
|
||||||
|
old_umask = umask(022);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
umask(old_umask);
|
||||||
|
|
||||||
/* Try to claim the pidfile, exiting if we can't */
|
/* Try to claim the pidfile, exiting if we can't */
|
||||||
if ((pid_file_fd = virPidFileAcquirePath(pid_file, getpid())) < 0) {
|
if ((pid_file_fd = virPidFileAcquirePath(pid_file, getpid())) < 0) {
|
||||||
@@ -1571,6 +1582,8 @@ cleanup:
|
|||||||
VIR_FREE(sock_file_ro);
|
VIR_FREE(sock_file_ro);
|
||||||
VIR_FREE(pid_file);
|
VIR_FREE(pid_file);
|
||||||
VIR_FREE(remote_config_file);
|
VIR_FREE(remote_config_file);
|
||||||
|
VIR_FREE(run_dir);
|
||||||
|
|
||||||
daemonConfigFree(config);
|
daemonConfigFree(config);
|
||||||
virLogShutdown();
|
virLogShutdown();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user