]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
switch_root: simplify code and reduce indentation [oclint]
authorSami Kerola <kerolasa@iki.fi>
Sun, 3 Jul 2016 11:30:46 +0000 (12:30 +0100)
committerSami Kerola <kerolasa@iki.fi>
Thu, 21 Jul 2016 20:14:33 +0000 (21:14 +0100)
The if statement in line 162 already ensures value of cfd to be 0 or
greater, so the later if is not needed.

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
sys-utils/switch_root.c

index dc55a6d080188958a2db5696fe0002614e8c3625..6f5468fca3ec11f341af69f2ae63dce37f19a2bc 100644 (file)
@@ -176,22 +176,21 @@ static int switchroot(const char *newroot)
                return -1;
        }
 
-       if (cfd >= 0) {
-               pid = fork();
-               if (pid <= 0) {
-                       struct statfs stfs;
-                       if (fstatfs(cfd, &stfs) == 0 &&
-                           (F_TYPE_EQUAL(stfs.f_type, STATFS_RAMFS_MAGIC) ||
-                            F_TYPE_EQUAL(stfs.f_type, STATFS_TMPFS_MAGIC)))
-                               recursiveRemove(cfd);
-                       else
-                               warn(_("old root filesystem is not an initramfs"));
-
-                       if (pid == 0)
-                               exit(EXIT_SUCCESS);
-               }
-               close(cfd);
+       pid = fork();
+       if (pid <= 0) {
+               struct statfs stfs;
+
+               if (fstatfs(cfd, &stfs) == 0 &&
+                   (F_TYPE_EQUAL(stfs.f_type, STATFS_RAMFS_MAGIC) ||
+                    F_TYPE_EQUAL(stfs.f_type, STATFS_TMPFS_MAGIC)))
+                       recursiveRemove(cfd);
+               else
+                       warn(_("old root filesystem is not an initramfs"));
+               if (pid == 0)
+                       exit(EXIT_SUCCESS);
        }
+
+       close(cfd);
        return 0;
 }