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)
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);
VIR_FORCE_CLOSE(tmp_fd);
unlink(tmp);
VIR_FREE(tmp);
+ VIR_FREE(cacheDir);
VBOX_RELEASE(machine);
vboxIIDUnalloc(&iid);
return ret;