mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-08 12:41:29 +00:00
Create hostdevmgr in UserRuntimeDirectory for session libvirt
Without this, session libvirt won't start if it fails to create the directory.
This commit is contained in:
parent
1fc4846b09
commit
63f22dc80f
@ -89,6 +89,7 @@ static virHostdevManagerPtr
|
|||||||
virHostdevManagerNew(void)
|
virHostdevManagerNew(void)
|
||||||
{
|
{
|
||||||
virHostdevManagerPtr hostdevMgr;
|
virHostdevManagerPtr hostdevMgr;
|
||||||
|
bool privileged = geteuid() == 0;
|
||||||
|
|
||||||
if (!(hostdevMgr = virObjectNew(virHostdevManagerClass)))
|
if (!(hostdevMgr = virObjectNew(virHostdevManagerClass)))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -105,14 +106,39 @@ virHostdevManagerNew(void)
|
|||||||
if ((hostdevMgr->activeSCSIHostdevs = virSCSIDeviceListNew()) == NULL)
|
if ((hostdevMgr->activeSCSIHostdevs = virSCSIDeviceListNew()) == NULL)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0)
|
if (privileged) {
|
||||||
goto error;
|
if (VIR_STRDUP(hostdevMgr->stateDir, HOSTDEV_STATE_DIR) < 0)
|
||||||
|
goto error;
|
||||||
|
|
||||||
if (virFileMakePath(hostdevMgr->stateDir) < 0) {
|
if (virFileMakePath(hostdevMgr->stateDir) < 0) {
|
||||||
virReportError(VIR_ERR_OPERATION_FAILED,
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
_("Failed to create state dir '%s'"),
|
_("Failed to create state dir '%s'"),
|
||||||
hostdevMgr->stateDir);
|
hostdevMgr->stateDir);
|
||||||
goto error;
|
goto error;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
char *rundir = NULL;
|
||||||
|
mode_t old_umask;
|
||||||
|
|
||||||
|
if (!(rundir = virGetUserRuntimeDirectory()))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < 0) {
|
||||||
|
VIR_FREE(rundir);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
VIR_FREE(rundir);
|
||||||
|
|
||||||
|
old_umask = umask(077);
|
||||||
|
|
||||||
|
if (virFileMakePath(hostdevMgr->stateDir) < 0) {
|
||||||
|
umask(old_umask);
|
||||||
|
virReportError(VIR_ERR_OPERATION_FAILED,
|
||||||
|
_("Failed to create state dir '%s'"),
|
||||||
|
hostdevMgr->stateDir);
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
umask(old_umask);
|
||||||
}
|
}
|
||||||
|
|
||||||
return hostdevMgr;
|
return hostdevMgr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user