From: Christian Marangi Date: Sun, 17 Jul 2022 11:11:36 +0000 (+0200) Subject: jail: fix various ignoring return value compilation warning X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=ef5d3e36e8b23ee2e1989c22717b21649dc9a388;p=project%2Fprocd.git jail: fix various ignoring return value compilation warning This fix the following compilation error: jail/jail.c: In function 'main': jail/jail.c:2733:33: error: ignoring return value of 'asprintf' declared with attribute 'warn_unused_result' [-Werror=unused-result] 2733 | asprintf(&opts.envp[envc++], "%s=%s", enve->envarg, tmp); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c: In function 'build_jail_fs': jail/jail.c:740:24: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 740 | (void) symlink("../dev/resolv.conf.d/resolv.conf.auto", jaillink); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c: In function 'create_devices': jail/jail.c:643:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 643 | (void) symlink("/dev/pts/ptmx", "/dev/ptmx"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:644:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 644 | (void) symlink("/proc/self/fd", "/dev/fd"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:645:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 645 | (void) symlink("/proc/self/fd/0", "/dev/stdin"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:646:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 646 | (void) symlink("/proc/self/fd/1", "/dev/stdout"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ jail/jail.c:647:16: error: ignoring return value of 'symlink' declared with attribute 'warn_unused_result' [-Werror=unused-result] 647 | (void) symlink("/proc/self/fd/2", "/dev/stderr"); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Christian Marangi --- diff --git a/jail/jail.c b/jail/jail.c index bfa2587..ce6b268 100644 --- a/jail/jail.c +++ b/jail/jail.c @@ -585,6 +585,7 @@ static int create_devices(void) { struct mknod_args **cur, *curdef; char *path, *tmp; + int ret; if (!opts.devices) goto only_default_devices; @@ -640,11 +641,25 @@ only_default_devices: } /* Dev symbolic links as defined in OCI spec */ - (void) symlink("/dev/pts/ptmx", "/dev/ptmx"); - (void) symlink("/proc/self/fd", "/dev/fd"); - (void) symlink("/proc/self/fd/0", "/dev/stdin"); - (void) symlink("/proc/self/fd/1", "/dev/stdout"); - (void) symlink("/proc/self/fd/2", "/dev/stderr"); + ret = symlink("/dev/pts/ptmx", "/dev/ptmx"); + if (ret < 0) + WARNING("symlink() failed to create link to /dev/pts/ptmx"); + + ret = symlink("/proc/self/fd", "/dev/fd"); + if (ret < 0) + WARNING("symlink() failed to create link to /proc/self/fd"); + + ret = symlink("/proc/self/fd/0", "/dev/stdin"); + if (ret < 0) + WARNING("symlink() failed to create link to /proc/self/fd/0"); + + ret = symlink("/proc/self/fd/1", "/dev/stdout"); + if (ret < 0) + WARNING("symlink() failed to create link to /proc/self/fd/1"); + + ret = symlink("/proc/self/fd/2", "/dev/stderr"); + if (ret < 0) + WARNING("symlink() failed to create link to /proc/self/fd/2"); return 0; } @@ -737,7 +752,9 @@ static int build_jail_fs(void) if (overlaydir) unlink(jaillink); - (void) symlink("../dev/resolv.conf.d/resolv.conf.auto", jaillink); + ret = symlink("../dev/resolv.conf.d/resolv.conf.auto", jaillink); + if (ret < 0) + WARNING("symlink() failed to create link to ../dev/resolv.conf.d/resolv.conf.auto"); } run_hooks(opts.hooks.createContainer, enter_jail_fs); @@ -2729,8 +2746,14 @@ int main(int argc, char **argv) opts.envp = calloc(1 + envn, sizeof(char*)); list_for_each_entry_safe(enve, tmpenve, &envl, list) { tmp = getenv(enve->envarg); - if (tmp) - asprintf(&opts.envp[envc++], "%s=%s", enve->envarg, tmp); + if (tmp) { + ret = asprintf(&opts.envp[envc++], "%s=%s", enve->envarg, tmp); + if (ret < 0) { + ERROR("filed to handle envargs %s\n", tmp); + free(enve); + goto errout; + } + } list_del(&enve->list); free(enve);