mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-11 09:17:52 +03: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;
|
||||
nsresult rc;
|
||||
char *tmp;
|
||||
char *cacheDir;
|
||||
int tmp_fd = -1;
|
||||
unsigned int max_screen;
|
||||
bool privileged = geteuid() == 0;
|
||||
char *ret = NULL;
|
||||
|
||||
if (!data->vboxObj)
|
||||
@ -7288,11 +7290,18 @@ vboxDomainScreenshot(virDomainPtr dom,
|
||||
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);
|
||||
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) {
|
||||
virReportSystemError(errno, _("mkostemp(\"%s\") failed"), tmp);
|
||||
VIR_FREE(tmp);
|
||||
@ -7368,6 +7377,7 @@ vboxDomainScreenshot(virDomainPtr dom,
|
||||
VIR_FORCE_CLOSE(tmp_fd);
|
||||
unlink(tmp);
|
||||
VIR_FREE(tmp);
|
||||
VIR_FREE(cacheDir);
|
||||
VBOX_RELEASE(machine);
|
||||
vboxIIDUnalloc(&iid);
|
||||
return ret;
|
||||
|
Loading…
Reference in New Issue
Block a user