[hackers] [ubase] Some more stylistic changes to switch_root || sin

From: <git_AT_suckless.org>
Date: Mon, 14 Apr 2014 12:21:46 +0200

commit fc4dc81535007e4854b97b3f681b8c80ce041fa4
Author: sin <sin_AT_2f30.org>
Date: Mon Apr 14 11:20:09 2014 +0100

    Some more stylistic changes to switch_root

diff --git a/switch_root.c b/switch_root.c
index 318d08c..afbe328 100644
--- a/switch_root.c
+++ b/switch_root.c
_AT_@ -20,9 +20,8 @@ delete_content(const char *dir, dev_t curdevice)
         struct dirent *dent;
 
         /* don't dive into other filesystems */
- if (lstat(dir, &st) || st.st_dev != curdevice){
+ if (lstat(dir, &st) || st.st_dev != curdevice)
                 return;
- }
         /* delete contents recursively */
         if (S_ISDIR(st.st_mode)) {
                 d = opendir(dir);
_AT_@ -32,9 +31,7 @@ delete_content(const char *dir, dev_t curdevice)
                                 if (dent->d_name[0] == '.'
                                  && ((dent->d_name[1] == '.' && dent->d_name[2] == 0)
                                      || (dent->d_name[1] == 0)))
- {
                                         continue;
- }
 
                                 /* build path and dive deeper */
                                 strlcat(path, dir, sizeof(path));
_AT_@ -77,45 +74,39 @@ main(int argc, char **argv)
         } ARGEND;
 
         /* check number of args and if we are PID 1 */
- if (argc != 2 || getpid() != 1){
+ if (argc != 2 || getpid() != 1)
                 usage();
- }
 
         /* chdir to newroot and make sure it's a different fs */
- if (chdir(argv[0])) {
+ if (chdir(argv[0]))
                 eprintf("chdir %s:", argv[0]);
- }
- if (stat("/", &st)) {
+
+ if (stat("/", &st))
                 eprintf("stat %s:", "/");
- }
+
         curdev = st.st_dev;
- if (stat(".", &st)) {
+ if (stat(".", &st))
                 eprintf("stat %s:", ".");
- }
- if (st.st_dev == curdev) {
+ if (st.st_dev == curdev)
                 usage();
- }
 
- /* further checks */
- if (stat("/init", &st) || !S_ISREG(st.st_mode)) {
- /* avoids trouble with real filesystems */
+ /* avoids trouble with real filesystems */
+ if (stat("/init", &st) || !S_ISREG(st.st_mode))
                 eprintf("/init is not a regular file
");
- }
+
         statfs("/", &stfs);
- if ((unsigned)stfs.f_type != RAMFS_MAGIC && (unsigned)stfs.f_type != TMPFS_MAGIC){
+ if ((unsigned)stfs.f_type != RAMFS_MAGIC && (unsigned)stfs.f_type != TMPFS_MAGIC)
                 eprintf("current filesystem is not a RAMFS or TMPFS
");
- }
 
         /* wipe / */
         delete_content("/", curdev);
 
         /* overmount / with newroot and chroot into it */
- if (mount(".", "/", NULL, MS_MOVE, NULL)) {
+ if (mount(".", "/", NULL, MS_MOVE, NULL))
                 eprintf("mount %s:", ".");
- }
- if (chroot(".")) {
+
+ if (chroot("."))
                 eprintf("chroot failed
");
- }
 
         /* if -c is set, redirect stdin/stdout/stderr to console */
         if (console) {
Received on Mon Apr 14 2014 - 12:21:46 CEST

This archive was generated by hypermail 2.3.0 : Mon Apr 14 2014 - 12:24:13 CEST