]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
vbox: use user cache dir when screenshotting.
authorDawid Zamirski <dzamirski@datto.com>
Mon, 9 Mar 2015 15:07:46 +0000 (11:07 -0400)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 12 Mar 2015 16:53:12 +0000 (17:53 +0100)
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>
src/vbox/vbox_common.c

index 55d362455d57a7bc98dbfd6df9996a1f7da364b2..7ecefd6c8b6f61e6b77a427e35e0c50ba930e7ef 100644 (file)
@@ -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;