提交 36a8eb80 编写于 作者: D Dawid Zamirski 提交者: Michal Privoznik

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: NMichal Privoznik <mprivozn@redhat.com>
上级 48461b16
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册