From: Dwight Engen Date: Mon, 15 Apr 2013 17:43:14 +0000 (-0400) Subject: fix checking hook script exit code X-Git-Tag: lxc-1.0.0.alpha1~1^2~294 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e7da691af29fe1d8b93d2e4acc98eb188ae74cc;p=thirdparty%2Flxc.git fix checking hook script exit code pclose returns the exit status from wait, we need to check that to see if the script itself failed or not. Tested a script that returned 0, 1, and also one that did a sleep and then was killed by a signal. Signed-off-by: Dwight Engen Acked-by: Serge E. Hallyn --- diff --git a/src/lxc/conf.c b/src/lxc/conf.c index 917c0526b..cf97eeffd 100644 --- a/src/lxc/conf.c +++ b/src/lxc/conf.c @@ -299,6 +299,7 @@ static int run_buffer(char *buffer) { FILE *f; char *output; + int ret; f = popen(buffer, "r"); if (!f) { @@ -318,9 +319,17 @@ static int run_buffer(char *buffer) free(output); - if (pclose(f) == -1) { + ret = pclose(f); + if (ret == -1) { SYSERROR("Script exited on error"); return -1; + } else if (WIFEXITED(ret) && WEXITSTATUS(ret) != 0) { + ERROR("Script exited with status %d", WEXITSTATUS(ret)); + return -1; + } else if (WIFSIGNALED(ret)) { + ERROR("Script terminated by signal %d (%s)", WTERMSIG(ret), + strsignal(WTERMSIG(ret))); + return -1; } return 0;