OK how about this one ...

Rich.

-- 
Richard Jones, Emerging Technologies, Red Hat  http://et.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top
? scripts/Makefile
? scripts/Makefile.in
Index: src/xend_internal.c
===================================================================
RCS file: /data/cvs/libvirt/src/xend_internal.c,v
retrieving revision 1.197
diff -u -p -r1.197 xend_internal.c
--- src/xend_internal.c 6 Jun 2008 11:09:57 -0000       1.197
+++ src/xend_internal.c 9 Jun 2008 11:58:10 -0000
@@ -160,25 +160,37 @@ struct xend {
 };
 
 
+static void virXendError(virConnectPtr conn, virErrorNumber error,
+                         const char *fmt, ...)
+    ATTRIBUTE_FORMAT(printf,3,4);
+
+#define MAX_ERROR_MESSAGE_LEN 1024
+
 /**
  * virXendError:
  * @conn: the connection if available
  * @error: the error number
- * @info: extra information string
+ * @fmt: format string followed by variable args
  *
  * Handle an error at the xend daemon interface
  */
 static void
-virXendError(virConnectPtr conn, virErrorNumber error, const char *info)
+virXendError(virConnectPtr conn, virErrorNumber error,
+             const char *fmt, ...)
 {
-    const char *errmsg;
+    va_list args;
+    char msg[MAX_ERROR_MESSAGE_LEN];
+    const char *msg2;
 
-    if (error == VIR_ERR_OK)
-        return;
+    if (fmt) {
+        va_start (args, fmt);
+        vsnprintf (msg, sizeof (msg), fmt, args);
+        va_end (args);
+    }
 
-    errmsg = __virErrorMsg(error, info);
+    msg2 = __virErrorMsg (error, fmt ? msg : NULL);
     __virRaiseError(conn, NULL, NULL, VIR_FROM_XEND, error, VIR_ERR_ERROR,
-                    errmsg, info, NULL, 0, 0, errmsg, info);
+                    msg2, msg, NULL, 0, 0, msg2, msg);
 }
 
 /**
@@ -490,7 +502,8 @@ xend_get(virConnectPtr xend, const char 
 
     if (((ret < 0) || (ret >= 300)) &&
         ((ret != 404) || (!STRPREFIX(path, "/xend/domain/")))) {
-        virXendError(xend, VIR_ERR_GET_FAILED, content);
+        virXendError(xend, VIR_ERR_GET_FAILED,
+                     _("xend_get: error from xen daemon: %s"), content);
     }
 
     return ret;
@@ -539,16 +552,19 @@ xend_post(virConnectPtr xend, const char
     close(s);
 
     if ((ret < 0) || (ret >= 300)) {
-        virXendError(xend, VIR_ERR_POST_FAILED, content);
+        virXendError(xend, VIR_ERR_POST_FAILED,
+                     _("xend_post: error from xen daemon: %s"), content);
     } else if ((ret == 202) && (strstr(content, "failed") != NULL)) {
-        virXendError(xend, VIR_ERR_POST_FAILED, content);
+        virXendError(xend, VIR_ERR_POST_FAILED,
+                     _("xend_post: error from xen daemon: %s"), content);
         ret = -1;
     } else if (((ret >= 200) && (ret <= 202)) && (strstr(content, "xend.err") 
!= NULL)) {
         /* This is to catch case of things like 'virsh dump Domain-0 foo'
          * which returns a success code, but the word 'xend.err'
          * in body to indicate error :-(
          */
-        virXendError(xend, VIR_ERR_POST_FAILED, content);
+        virXendError(xend, VIR_ERR_POST_FAILED,
+                     _("xend_post: error from xen daemon: %s"), content);
         ret = -1;
     }
 
@@ -1026,7 +1042,8 @@ xenDaemonOpen_tcp(virConnectPtr conn, co
     pent = gethostbyname(host);
     if (pent == NULL) {
         if (inet_aton(host, &ip) == 0) {
-            virXendError(NULL, VIR_ERR_UNKNOWN_HOST, host);
+            virXendError(NULL, VIR_ERR_UNKNOWN_HOST,
+                         _("gethostbyname failed: %s"), host);
             errno = ESRCH;
             return (-1);
         }
@@ -3925,12 +3942,14 @@ xenDaemonDomainMigratePrepare (virConnec
     if (uri_in == NULL) {
         r = gethostname (hostname, HOST_NAME_MAX+1);
         if (r == -1) {
-            virXendError (dconn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+            virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
+                          _("gethostname failed: %s"), strerror (errno));
             return -1;
         }
         *uri_out = strdup (hostname);
         if (*uri_out == NULL) {
-            virXendError (dconn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+            virXendError (dconn, VIR_ERR_SYSTEM_ERROR,
+                          _("failed to strdup hostname: %s"), strerror 
(errno));
             return -1;
         }
     }
@@ -4575,14 +4594,16 @@ xenDaemonDomainBlockPeek (virDomainPtr d
 
     if (!data.ok) {
         virXendError (domain->conn, VIR_ERR_INVALID_ARG,
-                      _("invalid path"));
+                      _("%s: invalid path"), path);
         return -1;
     }
 
     /* The path is correct, now try to open it and get its size. */
     fd = open (path, O_RDONLY);
     if (fd == -1) {
-        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
+                      _("failed to open for reading: %s: %s"),
+                      path, strerror (errno));
         goto done;
     }
 
@@ -4592,7 +4613,9 @@ xenDaemonDomainBlockPeek (virDomainPtr d
      */
     if (lseek (fd, offset, SEEK_SET) == (off_t) -1 ||
         saferead (fd, buffer, size) == (ssize_t) -1) {
-        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR, strerror (errno));
+        virXendError (domain->conn, VIR_ERR_SYSTEM_ERROR,
+                      _("failed to lseek or read from file: %s: %s"),
+                      path, strerror (errno));
         goto done;
     }
 
--
Libvir-list mailing list
Libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to