[lxc-devel] [PATCH v2] fix checking hook script exit code

Serge Hallyn serge.hallyn at ubuntu.com
Tue Apr 16 02:20:29 UTC 2013


Quoting Dwight Engen (dwight.engen at oracle.com):
> 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 <dwight.engen at oracle.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

Thanks, Dwight!

> ---
>  src/lxc/conf.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
> 
> diff --git a/src/lxc/conf.c b/src/lxc/conf.c
> index c416da5..43cbbd8 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;
> -- 
> 1.7.12.3
> 
> 




More information about the lxc-devel mailing list