diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-12 00:32:05 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-04-12 00:32:05 +0000 |
commit | 51742f4bb0c57a4d5063ece9437a2f34a42e52c8 (patch) | |
tree | 7a912fc65ff43bdb09078d75bfc02ad8f5380b47 /util-linux/switch_root.c | |
parent | 50f7f446ecaadef6895a4ee601567e0b68330637 (diff) | |
download | busybox-w32-51742f4bb0c57a4d5063ece9437a2f34a42e52c8.tar.gz busybox-w32-51742f4bb0c57a4d5063ece9437a2f34a42e52c8.tar.bz2 busybox-w32-51742f4bb0c57a4d5063ece9437a2f34a42e52c8.zip |
style fixes. No code changes
Diffstat (limited to 'util-linux/switch_root.c')
-rw-r--r-- | util-linux/switch_root.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/util-linux/switch_root.c b/util-linux/switch_root.c index 43377e16e..6dba9f05f 100644 --- a/util-linux/switch_root.c +++ b/util-linux/switch_root.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #define MS_MOVE 8192 | 24 | #define MS_MOVE 8192 |
25 | #endif | 25 | #endif |
26 | 26 | ||
27 | dev_t rootdev; | 27 | static dev_t rootdev; |
28 | 28 | ||
29 | // Recursively delete contents of rootfs. | 29 | // Recursively delete contents of rootfs. |
30 | 30 | ||
@@ -39,12 +39,13 @@ static void delete_contents(const char *directory) | |||
39 | 39 | ||
40 | // Recursively delete the contents of directories. | 40 | // Recursively delete the contents of directories. |
41 | if (S_ISDIR(st.st_mode)) { | 41 | if (S_ISDIR(st.st_mode)) { |
42 | if((dir = opendir(directory))) { | 42 | dir = opendir(directory); |
43 | if (dir) { | ||
43 | while ((d = readdir(dir))) { | 44 | while ((d = readdir(dir))) { |
44 | char *newdir=d->d_name; | 45 | char *newdir = d->d_name; |
45 | 46 | ||
46 | // Skip . and .. | 47 | // Skip . and .. |
47 | if(*newdir=='.' && (!newdir[1] || (newdir[1]=='.' && !newdir[2]))) | 48 | if (*newdir=='.' && (!newdir[1] || (newdir[1]=='.' && !newdir[2]))) |
48 | continue; | 49 | continue; |
49 | 50 | ||
50 | // Recurse to delete contents | 51 | // Recurse to delete contents |
@@ -66,7 +67,7 @@ static void delete_contents(const char *directory) | |||
66 | int switch_root_main(int argc, char **argv); | 67 | int switch_root_main(int argc, char **argv); |
67 | int switch_root_main(int argc, char **argv) | 68 | int switch_root_main(int argc, char **argv) |
68 | { | 69 | { |
69 | char *newroot, *console=NULL; | 70 | char *newroot, *console = NULL; |
70 | struct stat st1, st2; | 71 | struct stat st1, st2; |
71 | struct statfs stfs; | 72 | struct statfs stfs; |
72 | 73 | ||
@@ -77,18 +78,18 @@ int switch_root_main(int argc, char **argv) | |||
77 | 78 | ||
78 | // Change to new root directory and verify it's a different fs. | 79 | // Change to new root directory and verify it's a different fs. |
79 | 80 | ||
80 | newroot=argv[optind++]; | 81 | newroot = argv[optind++]; |
81 | 82 | ||
82 | if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) || | 83 | if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) || |
83 | st1.st_dev == st2.st_dev) | 84 | st1.st_dev == st2.st_dev) |
84 | { | 85 | { |
85 | bb_error_msg_and_die("bad newroot %s", newroot); | 86 | bb_error_msg_and_die("bad newroot %s", newroot); |
86 | } | 87 | } |
87 | rootdev=st2.st_dev; | 88 | rootdev = st2.st_dev; |
88 | 89 | ||
89 | // Additional sanity checks: we're about to rm -rf /, so be REALLY SURE | 90 | // Additional sanity checks: we're about to rm -rf /, so be REALLY SURE |
90 | // we mean it. (I could make this a CONFIG option, but I would get email | 91 | // we mean it. (I could make this a CONFIG option, but I would get email |
91 | // from all the people who WILL eat their filesystemss.) | 92 | // from all the people who WILL eat their filesystems.) |
92 | 93 | ||
93 | if (lstat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/", &stfs) || | 94 | if (lstat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/", &stfs) || |
94 | (stfs.f_type != RAMFS_MAGIC && stfs.f_type != TMPFS_MAGIC) || | 95 | (stfs.f_type != RAMFS_MAGIC && stfs.f_type != TMPFS_MAGIC) || |
@@ -105,14 +106,13 @@ int switch_root_main(int argc, char **argv) | |||
105 | // recalculate "." and ".." links. | 106 | // recalculate "." and ".." links. |
106 | 107 | ||
107 | if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot(".") || chdir("/")) | 108 | if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot(".") || chdir("/")) |
108 | bb_error_msg_and_die("moving root"); | 109 | bb_error_msg_and_die("error moving root"); |
109 | 110 | ||
110 | // If a new console specified, redirect stdin/stdout/stderr to that. | 111 | // If a new console specified, redirect stdin/stdout/stderr to that. |
111 | 112 | ||
112 | if (console) { | 113 | if (console) { |
113 | close(0); | 114 | close(0); |
114 | if (open(console, O_RDWR) < 0) | 115 | xopen(console, O_RDWR); |
115 | bb_error_msg_and_die("bad console '%s'", console); | ||
116 | dup2(0, 1); | 116 | dup2(0, 1); |
117 | dup2(0, 2); | 117 | dup2(0, 2); |
118 | } | 118 | } |