[LEDE-DEV,procd,2/2] upgraded: Check chroot() return value

Message ID 20170715194424.6494-2-f.fainelli@gmail.com
State Superseded, archived
Delegated to: Florian Fainelli
Headers show

Commit Message

Florian Fainelli July 15, 2017, 7:44 p.m.
Check the chroot() return value, fixes unused return value warnings/errors:

procd-2017-06-22-e5e99c46/upgraded/upgraded.c:78:8: error: ignoring return
value of 'chroot', declared with attribute warn_unused_result
[-Werror=unused-result] chroot(".");

Fixes: 056d8ddda8d5 ("upgraded: link dynamically, chroot during exec")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 upgraded/upgraded.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Comments

Matthias Schiffer July 16, 2017, 5:40 p.m. | #1
On 07/15/2017 09:44 PM, Florian Fainelli wrote:
> Check the chroot() return value, fixes unused return value warnings/errors:
> 
> procd-2017-06-22-e5e99c46/upgraded/upgraded.c:78:8: error: ignoring return
> value of 'chroot', declared with attribute warn_unused_result
> [-Werror=unused-result] chroot(".");
> 
> Fixes: 056d8ddda8d5 ("upgraded: link dynamically, chroot during exec")
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---

LGTM.

Reviewed-by: Matthias Schiffer <mschiffer@universe-factory.net>

>  upgraded/upgraded.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/upgraded/upgraded.c b/upgraded/upgraded.c
> index 09c623cf804b..220da7903f92 100644
> --- a/upgraded/upgraded.c
> +++ b/upgraded/upgraded.c
> @@ -78,7 +78,10 @@ int main(int argc, char **argv)
>  		return 1;
>  	}
>  
> -	chroot(".");
> +	if (chroot(".") < 0) {
> +		fprintf(stderr, "failed to chroot: %s\n", strerror(errno));
> +		return 1;
> +	}
>  
>  	if (fchdir(fd) == -1) {
>  		fprintf(stderr, "failed to chdir to prefix directory: %s\n", strerror(errno));
>

Patch

diff --git a/upgraded/upgraded.c b/upgraded/upgraded.c
index 09c623cf804b..220da7903f92 100644
--- a/upgraded/upgraded.c
+++ b/upgraded/upgraded.c
@@ -78,7 +78,10 @@  int main(int argc, char **argv)
 		return 1;
 	}
 
-	chroot(".");
+	if (chroot(".") < 0) {
+		fprintf(stderr, "failed to chroot: %s\n", strerror(errno));
+		return 1;
+	}
 
 	if (fchdir(fd) == -1) {
 		fprintf(stderr, "failed to chdir to prefix directory: %s\n", strerror(errno));