]> xenbits.xensource.com Git - libvirt.git/commitdiff
utils: More useful error message for hook script failure
authorOsier Yang <jyang@redhat.com>
Fri, 29 Jul 2011 14:40:47 +0000 (22:40 +0800)
committerOsier Yang <jyang@redhat.com>
Fri, 29 Jul 2011 14:40:47 +0000 (22:40 +0800)
Commit 3709a386 ported hooks codes to new command execution API,
together with the useful error message removed. Though we can't
get "errbuf" from the new command execution API anymore, still
we can give a more useful error.

https://bugzilla.redhat.com/show_bug.cgi?id=726398

src/util/hooks.c

index 64adfcbda39a45cf10b195fff24580bb37fd01fa..110a94b52f9c491120add7481071bca45399e54b 100644 (file)
@@ -193,6 +193,7 @@ int
 virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
             const char *input) {
     int ret;
+    int exitstatus;
     char *path;
     virCommandPtr cmd;
     const char *drvstr;
@@ -257,7 +258,13 @@ virHookCall(int driver, const char *id, int op, int sub_op, const char *extra,
     if (input)
         virCommandSetInputBuffer(cmd, input);
 
-    ret = virCommandRun(cmd, NULL);
+    ret = virCommandRun(cmd, &exitstatus);
+    if (ret == 0 && exitstatus != 0) {
+        virHookReportError(VIR_ERR_HOOK_SCRIPT_FAILED,
+                           _("Hook script %s %s failed with error code %d"),
+                           path, drvstr, exitstatus);
+        ret = -1;
+    }
 
     virCommandFree(cmd);