mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
vbox: use user cache dir when screenshotting.
For VBOX it's most likely that the connection is vbox:///session and it runs with local non-root account. This caused permission denied when LOCALSTATEDIR was used to create temp file. This patch makes use of the virGetUserCacheDirectory to address this problem for non-root users. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
48461b169e
commit
36a8eb8001
@ -7254,8 +7254,10 @@ vboxDomainScreenshot(virDomainPtr dom,
|
|||||||
IMachine *machine = NULL;
|
IMachine *machine = NULL;
|
||||||
nsresult rc;
|
nsresult rc;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
char *cacheDir;
|
||||||
int tmp_fd = -1;
|
int tmp_fd = -1;
|
||||||
unsigned int max_screen;
|
unsigned int max_screen;
|
||||||
|
bool privileged = geteuid() == 0;
|
||||||
char *ret = NULL;
|
char *ret = NULL;
|
||||||
|
|
||||||
if (!data->vboxObj)
|
if (!data->vboxObj)
|
||||||
@ -7288,11 +7290,18 @@ vboxDomainScreenshot(virDomainPtr dom,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (virAsprintf(&tmp, "%s/cache/libvirt/vbox.screendump.XXXXXX", LOCALSTATEDIR) < 0) {
|
if ((privileged && virAsprintf(&cacheDir, "%s/cache/libvirt", LOCALSTATEDIR) < 0) ||
|
||||||
|
(!privileged && !(cacheDir = virGetUserCacheDirectory()))) {
|
||||||
VBOX_RELEASE(machine);
|
VBOX_RELEASE(machine);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (virAsprintf(&tmp, "%s/vbox.screendump.XXXXXX", cacheDir) < 0) {
|
||||||
|
VBOX_RELEASE(machine);
|
||||||
|
VIR_FREE(cacheDir);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
|
if ((tmp_fd = mkostemp(tmp, O_CLOEXEC)) == -1) {
|
||||||
virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp);
|
virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp);
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
@ -7368,6 +7377,7 @@ vboxDomainScreenshot(virDomainPtr dom,
|
|||||||
VIR_FORCE_CLOSE(tmp_fd);
|
VIR_FORCE_CLOSE(tmp_fd);
|
||||||
unlink(tmp);
|
unlink(tmp);
|
||||||
VIR_FREE(tmp);
|
VIR_FREE(tmp);
|
||||||
|
VIR_FREE(cacheDir);
|
||||||
VBOX_RELEASE(machine);
|
VBOX_RELEASE(machine);
|
||||||
vboxIIDUnalloc(&iid);
|
vboxIIDUnalloc(&iid);
|
||||||
return ret;
|
return ret;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user