[lxc-devel] [PATCH] fix checking hook script exit code
Dwight Engen
dwight.engen at oracle.com
Fri Apr 12 19:05:40 UTC 2013
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 (abnormal
termination).
Signed-off-by: Dwight Engen <dwight.engen at oracle.com>
---
src/lxc/conf.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/src/lxc/conf.c b/src/lxc/conf.c
index 6b3f318..07529da 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) {
@@ -317,8 +318,10 @@ static int run_buffer(char *buffer)
free(output);
- if (pclose(f) == -1) {
- SYSERROR("Script exited on error");
+ ret = pclose(f);
+ if (ret < 0 || !WIFEXITED(ret) || WEXITSTATUS(ret) != 0) {
+ SYSERROR("Script exited:%snormally with:%d",
+ WIFEXITED(ret) ? "" : "ab", WEXITSTATUS(ret));
return -1;
}
--
1.7.12.3
More information about the lxc-devel
mailing list