[lxc-devel] [PATCH] lxc_init.c: error handing for sigaction and sigprocmask

Stéphane Graber stgraber at ubuntu.com
Thu Jan 16 16:03:08 UTC 2014


On Thu, Jan 16, 2014 at 03:30:01PM +0800, Qiang Huang wrote:
> Look through all LXC code and seems like only here are missed.
> 
> Signed-off-by: Qiang Huang <h.huangqiang at huawei.com>

Acked-by: Stéphane Graber <stgraber at ubuntu.com>

> ---
> Maybe this bug can be marked resolved:
> https://github.com/lxc/lxc/issues/83
> ---
>  src/lxc/lxc_init.c | 46 +++++++++++++++++++++++++++++++---------------
>  1 file changed, 31 insertions(+), 15 deletions(-)
> 
> diff --git a/src/lxc/lxc_init.c b/src/lxc/lxc_init.c
> index d88a935..a59dd9c 100644
> --- a/src/lxc/lxc_init.c
> +++ b/src/lxc/lxc_init.c
> @@ -123,11 +123,14 @@ int main(int argc, char *argv[])
>  	 * mask all the signals so we are safe to install a
>  	 * signal handler and to fork
>  	 */
> -	sigfillset(&mask);
> -	sigdelset(&mask, SIGILL);
> -	sigdelset(&mask, SIGSEGV);
> -	sigdelset(&mask, SIGBUS);
> -	sigprocmask(SIG_SETMASK, &mask, &omask);
> +	if (sigfillset(&mask) ||
> +	    sigdelset(&mask, SIGILL) ||
> +	    sigdelset(&mask, SIGSEGV) ||
> +	    sigdelset(&mask, SIGBUS) ||
> +	    sigprocmask(SIG_SETMASK, &mask, &omask)) {
> +		SYSERROR("failed to set signal mask");
> +		exit(EXIT_FAILURE);
> +	}
> 
>  	for (i = 1; i < NSIG; i++) {
>  		struct sigaction act;
> @@ -143,15 +146,22 @@ int main(int argc, char *argv[])
>  		    i == SIGKILL)
>  			continue;
> 
> -		sigfillset(&act.sa_mask);
> -		sigdelset(&act.sa_mask, SIGILL);
> -		sigdelset(&act.sa_mask, SIGSEGV);
> -		sigdelset(&act.sa_mask, SIGBUS);
> -		sigdelset(&act.sa_mask, SIGSTOP);
> -		sigdelset(&act.sa_mask, SIGKILL);
> +		if (sigfillset(&act.sa_mask) ||
> +		    sigdelset(&act.sa_mask, SIGILL) ||
> +		    sigdelset(&act.sa_mask, SIGSEGV) ||
> +		    sigdelset(&act.sa_mask, SIGBUS) ||
> +		    sigdelset(&act.sa_mask, SIGSTOP) ||
> +		    sigdelset(&act.sa_mask, SIGKILL)) {
> +			ERROR("failed to set signal");
> +			exit(EXIT_FAILURE);
> +		}
> +
>  		act.sa_flags = 0;
>  		act.sa_handler = interrupt_handler;
> -		sigaction(i, &act, NULL);
> +		if (sigaction(i, &act, NULL)) {
> +			SYSERROR("failed to sigaction");
> +			exit(EXIT_FAILURE);
> +		}
>  	}
> 
>  	lxc_setup_fs();
> @@ -170,7 +180,10 @@ int main(int argc, char *argv[])
>  		for (i = 1; i < NSIG; i++)
>  			signal(i, SIG_DFL);
> 
> -		sigprocmask(SIG_SETMASK, &omask, NULL);
> +		if (sigprocmask(SIG_SETMASK, &omask, NULL)) {
> +			SYSERROR("failed to set signal mask");
> +			exit(EXIT_FAILURE);
> +		}
> 
>  		NOTICE("about to exec '%s'", aargv[0]);
> 
> @@ -180,8 +193,11 @@ int main(int argc, char *argv[])
>  	}
> 
>  	/* let's process the signals now */
> -	sigdelset(&omask, SIGALRM);
> -	sigprocmask(SIG_SETMASK, &omask, NULL);
> +	if (sigdelset(&omask, SIGALRM) ||
> +	    sigprocmask(SIG_SETMASK, &omask, NULL)) {
> +		SYSERROR("failed to set signal mask");
> +		exit(EXIT_FAILURE);
> +	}
> 
>  	/* no need of other inherited fds but stderr */
>  	close(fileno(stdin));
> -- 
> 1.8.3
> 

-- 
Stéphane Graber
Ubuntu developer
http://www.ubuntu.com
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20140116/84701a2e/attachment.pgp>


More information about the lxc-devel mailing list