[PATCH 3/7] screenshot: Implementing the public API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 src/libvirt.c |   77 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 77 insertions(+), 0 deletions(-)

diff --git a/src/libvirt.c b/src/libvirt.c
index 8be18d4..9f8f2e6 100644
--- a/src/libvirt.c
+++ b/src/libvirt.c
@@ -2445,6 +2445,83 @@ error:
 }
 
 /**
+ * virDomainScreenshot:
+ * @domain: a domain object
+ * @to: path for the image
+ * @flags: extra flags, currently unused
+ *
+ * Take a screenshot of current domain console and store it
+ * as image under given path. The image format is hypervisor
+ * specific.
+ *
+ * Returns 0 in case of success and -1 in case of failure.
+ */
+int
+virDomainScreenshot(virDomainPtr domain, const char *to, int flags)
+{
+    char filepath[4096];
+    virConnectPtr conn;
+
+    VIR_DOMAIN_DEBUG(domain, "to=%s, flags=%d", to, flags);
+
+    virResetLastError();
+
+    if (!VIR_IS_CONNECTED_DOMAIN(domain)) {
+        virLibDomainError(VIR_ERR_INVALID_DOMAIN, __FUNCTION__);
+        virDispatchError(NULL);
+        return -1;
+    }
+    if (domain->conn->flags & VIR_CONNECT_RO) {
+        virLibDomainError(VIR_ERR_OPERATION_DENIED, __FUNCTION__);
+        goto error;
+    }
+    conn = domain->conn;
+    if (to == NULL) {
+        virLibDomainError(VIR_ERR_INVALID_ARG, __FUNCTION__);
+        goto error;
+    }
+
+    /*
+     * We must absolutize the file path as the save is done out of process
+     * TODO: check for URI when libxml2 is linked in.
+     */
+    if(to[0] != '/') {
+        unsigned int len, t;
+
+        t = strlen(to);
+        if (getcwd(filepath, sizeof(filepath) - (t + 3)) == NULL) {
+            virLibDomainError(VIR_ERR_SYSTEM_ERROR,
+                              _("cannot get current directory"));
+            goto error;
+        }
+        len = strlen(filepath);
+        /* that should be covered by getcwd() semantic, but be 100% sure */
+        if (len > sizeof(filepath) - (t + 3)) {
+            virLibDomainError(VIR_ERR_INTERNAL_ERROR,
+                              _("path too long"));
+            goto error;
+        }
+        filepath[len] = '/';
+        strcpy(&filepath[len + 1], to);
+        to = &filepath[0];
+    }
+
+    if (conn->driver->domainScreenshot) {
+        int ret;
+        ret = conn->driver->domainScreenshot (domain, to, flags);
+        if (ret < 0)
+            goto error;
+        return ret;
+    }
+
+    virLibConnError(VIR_ERR_NO_SUPPORT, __FUNCTION__);
+
+error:
+    virDispatchError(domain->conn);
+    return -1;
+}
+
+/**
  * virDomainShutdown:
  * @domain: a domain object
  *
-- 
1.7.4

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]