]> xenbits.xensource.com Git - libvirt.git/commitdiff
hooks: let virCommand do the error reporting
authorEric Blake <eblake@redhat.com>
Tue, 9 Oct 2012 03:44:36 +0000 (21:44 -0600)
committerEric Blake <eblake@redhat.com>
Tue, 9 Oct 2012 14:41:53 +0000 (08:41 -0600)
The code was reporting raw exit status without decoding it into
normal vs. signal exit.  virCommandRun already does this, but
with a different error type, so all we have to do is recast
the error to the correct type.
Reported by li guang.

* src/util/hooks.c (virHookCall): Simplify.

src/util/hooks.c

index f5890d2fc3f737c261523a7e97831a0e3ffe7def..8817a4e0f822273de24c630aa7795c568555e929 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * hooks.c: implementation of the synchronous hooks support
  *
- * Copyright (C) 2010-2011 Red Hat, Inc.
+ * Copyright (C) 2010-2012 Red Hat, Inc.
  * Copyright (C) 2010 Daniel Veillard
  *
  * This library is free software; you can redistribute it and/or
@@ -206,7 +206,6 @@ virHookCall(int driver,
             char **output)
 {
     int ret;
-    int exitstatus;
     char *path;
     virCommandPtr cmd;
     const char *drvstr;
@@ -279,12 +278,11 @@ virHookCall(int driver,
     if (output)
         virCommandSetOutputBuffer(cmd, output);
 
-    ret = virCommandRun(cmd, &exitstatus);
-    if (ret == 0 && exitstatus != 0) {
-        virReportError(VIR_ERR_HOOK_SCRIPT_FAILED,
-                       _("Hook script %s %s failed with error code %d"),
-                       path, drvstr, exitstatus);
-        ret = -1;
+    ret = virCommandRun(cmd, NULL);
+    if (ret < 0) {
+        /* Convert INTERNAL_ERROR into known error.  */
+        virErrorPtr err = virGetLastError();
+        virReportError(VIR_ERR_HOOK_SCRIPT_FAILED, "%s", err->message);
     }
 
     virCommandFree(cmd);