[libvirt] [PATCH] utils: More useful error message for hook script failure

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 | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/util/hooks.c b/src/util/hooks.c index 64adfcb..00f3a01 100644 --- a/src/util/hooks.c +++ b/src/util/hooks.c @@ -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 (exitstatus != 0) { + virHookReportError(VIR_ERR_HOOK_SCRIPT_FAILED, + _("Hook script %s %s failed with error code %d"), + path, drvstr, exitstatus); + ret = -1; + } virCommandFree(cmd); -- 1.7.6

On Fri, Jul 29, 2011 at 06:23:41PM +0800, Osier Yang wrote:
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 | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/src/util/hooks.c b/src/util/hooks.c index 64adfcb..00f3a01 100644 --- a/src/util/hooks.c +++ b/src/util/hooks.c @@ -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 (exitstatus != 0) { + virHookReportError(VIR_ERR_HOOK_SCRIPT_FAILED, + _("Hook script %s %s failed with error code %d"), + path, drvstr, exitstatus); + ret = -1; + }
virCommandFree(cmd);
ACK, Daniel -- Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/ daniel@veillard.com | Rpmfind RPM search engine http://rpmfind.net/ http://veillard.com/ | virtualization library http://libvirt.org/

On 07/29/2011 04:23 AM, Osier Yang wrote:
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 | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/src/util/hooks.c b/src/util/hooks.c index 64adfcb..00f3a01 100644 --- a/src/util/hooks.c +++ b/src/util/hooks.c @@ -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 (exitstatus != 0) {
Needs to be: if (ret == 0 && exitstatus != 0). If ret is -1 (possible if the command completely failed, such as if you are OOM or the child died due to a signal rather than a normal exit), then exitstatus might be undefined. -- Eric Blake eblake@redhat.com +1-801-349-2682 Libvirt virtualization library http://libvirt.org

于 2011年07月29日 19:48, Eric Blake 写道:
On 07/29/2011 04:23 AM, Osier Yang wrote:
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 | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/src/util/hooks.c b/src/util/hooks.c index 64adfcb..00f3a01 100644 --- a/src/util/hooks.c +++ b/src/util/hooks.c @@ -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 (exitstatus != 0) {
Needs to be: if (ret == 0 && exitstatus != 0).
If ret is -1 (possible if the command completely failed, such as if you are OOM or the child died due to a signal rather than a normal exit), then exitstatus might be undefined.
Make sense, and I pushed with the addition, Thanks Osier
participants (3)
-
Daniel Veillard
-
Eric Blake
-
Osier Yang