jail: fix various ignoring return value compilation warning
authorChristian Marangi <ansuelsmth@gmail.com>
Sun, 17 Jul 2022 11:11:36 +0000 (13:11 +0200)
committerChristian Marangi <ansuelsmth@gmail.com>
Sun, 17 Jul 2022 11:14:00 +0000 (13:14 +0200)
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 <ansuelsmth@gmail.com>
jail/jail.c

index bfa2587b30550e7f79ddcaa733466b1d1488bed2..ce6b268ea28e1f2aa6768eed0cd24e70be5229f8 100644 (file)
@@ -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);