prepare: Create global var for tmp_sysroot_etc
authorLuke Yang <luke.jia.yang@gmail.com>
Thu, 13 Jun 2024 18:41:27 +0000 (14:41 -0400)
committerLuke Yang <luke.jia.yang@gmail.com>
Thu, 20 Jun 2024 19:09:11 +0000 (15:09 -0400)
Coverity points out that ""/sysroot.tmp/etc"" could be a copy-paste
error. This is mistake from coverity, but to supress the warning,
we create a global var, tmp_sysroot_etc, which replaces all
instances of TMP_SYSROOT "/etc".

src/switchroot/ostree-prepare-root.c

index 4ac442027298e4337a467df021b1fac542db580d..2cb9f67ca9836e62b1b7f3208e41dc02d6a8fc95 100644 (file)
@@ -537,6 +537,7 @@ main (int argc, char *argv[])
                                                 &etc_transient, &error))
         errx (EXIT_FAILURE, "Failed to parse etc.transient value: %s", error->message);
 
+      static const char *tmp_sysroot_etc = TMP_SYSROOT "/etc";
       if (etc_transient)
         {
           char *ovldir = "/run/ostree/transient-etc";
@@ -564,15 +565,15 @@ main (int argc, char *argv[])
 
           g_autofree char *ovl_options
               = g_strdup_printf ("lowerdir=%s,upperdir=%s,workdir=%s", lowerdir, upperdir, workdir);
-          if (mount ("overlay", TMP_SYSROOT "/etc", "overlay", MS_SILENT, ovl_options) < 0)
+          if (mount ("overlay", tmp_sysroot_etc, "overlay", MS_SILENT, ovl_options) < 0)
             err (EXIT_FAILURE, "failed to mount transient etc overlayfs");
         }
       else
         {
           /* Bind-mount /etc (at deploy path), and remount as writable. */
-          if (mount ("etc", TMP_SYSROOT "/etc", NULL, MS_BIND | MS_SILENT, NULL) < 0)
+          if (mount ("etc", tmp_sysroot_etc, NULL, MS_BIND | MS_SILENT, NULL) < 0)
             err (EXIT_FAILURE, "failed to prepare /etc bind-mount at /sysroot.tmp/etc");
-          if (mount (TMP_SYSROOT "/etc", TMP_SYSROOT "/etc", NULL, MS_BIND | MS_REMOUNT | MS_SILENT,
+          if (mount (tmp_sysroot_etc, tmp_sysroot_etc, NULL, MS_BIND | MS_REMOUNT | MS_SILENT,
                      NULL)
               < 0)
             err (EXIT_FAILURE, "failed to make writable /etc bind-mount at /sysroot.tmp/etc");