From 36a8eb8001e9f32c46d56e3ca3d6e87ac16ec87d Mon Sep 17 00:00:00 2001 From: Dawid Zamirski Date: Mon, 9 Mar 2015 11:07:46 -0400 Subject: [PATCH] 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 --- src/vbox/vbox_common.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c index 55d362455d..7ecefd6c8b 100644 --- a/src/vbox/vbox_common.c +++ b/src/vbox/vbox_common.c @@ -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;