[LEDE-DEV] [PATCH procd v2 1/2] init: Check chroot return value in sysupgrade_exec_upgraded()

Matthias Schiffer mschiffer at universe-factory.net
Wed Jul 19 05:57:46 PDT 2017


On 07/18/2017 03:33 AM, Florian Fainelli wrote:
> chroot() can fail and its return value should be checked against, in that case
> do an exit() since this is a fatal condition that we cannot recover from.
> 
> Fixes: 63789e51ed91 ("init: add support for sysupgrades triggered from preinit")
> Signed-off-by: Florian Fainelli <f.fainelli at gmail.com>
> ---
>  sysupgrade.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/sysupgrade.c b/sysupgrade.c
> index 30f1836135c9..bd909ad33a77 100644
> --- a/sysupgrade.c
> +++ b/sysupgrade.c
> @@ -26,8 +26,10 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
>  {
>  	char *wdt_fd = watchdog_fd();
>  	char *argv[] = { "/sbin/upgraded", NULL, NULL, NULL};
> +	int ret;
>  
> -	if (chroot(prefix)) {
> +	ret = chroot(prefix);
> +	if (ret < 0) {
>  		fprintf(stderr, "Failed to chroot for upgraded exec.\n");
>  		return;
>  	}
> @@ -45,5 +47,9 @@ void sysupgrade_exec_upgraded(const char *prefix, char *path, char *command)
>  	fprintf(stderr, "Failed to exec upgraded.\n");
>  	unsetenv("WDTFD");
>  	watchdog_set_cloexec(true);
> -	chroot(".");
> +	ret = chroot(".");
> +	if (ret < 0) {
> +		fprintf(stderr, "Failed to chroot upon exit.\n");

This error message doesn't sound quite right. "Unable to reset chroot,
exiting."?

> +		exit(EXIT_FAILURE);
> +	}
>  }
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/lede-dev/attachments/20170719/668e3a4d/attachment.sig>


More information about the Lede-dev mailing list