style fixes. No code changes
This commit is contained in:
parent
50f7f446ec
commit
51742f4bb0
30 changed files with 84 additions and 82 deletions
|
@ -24,7 +24,7 @@
|
|||
#define MS_MOVE 8192
|
||||
#endif
|
||||
|
||||
dev_t rootdev;
|
||||
static dev_t rootdev;
|
||||
|
||||
// Recursively delete contents of rootfs.
|
||||
|
||||
|
@ -39,12 +39,13 @@ static void delete_contents(const char *directory)
|
|||
|
||||
// Recursively delete the contents of directories.
|
||||
if (S_ISDIR(st.st_mode)) {
|
||||
if((dir = opendir(directory))) {
|
||||
dir = opendir(directory);
|
||||
if (dir) {
|
||||
while ((d = readdir(dir))) {
|
||||
char *newdir=d->d_name;
|
||||
char *newdir = d->d_name;
|
||||
|
||||
// Skip . and ..
|
||||
if(*newdir=='.' && (!newdir[1] || (newdir[1]=='.' && !newdir[2])))
|
||||
if (*newdir=='.' && (!newdir[1] || (newdir[1]=='.' && !newdir[2])))
|
||||
continue;
|
||||
|
||||
// Recurse to delete contents
|
||||
|
@ -66,7 +67,7 @@ static void delete_contents(const char *directory)
|
|||
int switch_root_main(int argc, char **argv);
|
||||
int switch_root_main(int argc, char **argv)
|
||||
{
|
||||
char *newroot, *console=NULL;
|
||||
char *newroot, *console = NULL;
|
||||
struct stat st1, st2;
|
||||
struct statfs stfs;
|
||||
|
||||
|
@ -77,18 +78,18 @@ int switch_root_main(int argc, char **argv)
|
|||
|
||||
// Change to new root directory and verify it's a different fs.
|
||||
|
||||
newroot=argv[optind++];
|
||||
newroot = argv[optind++];
|
||||
|
||||
if (chdir(newroot) || lstat(".", &st1) || lstat("/", &st2) ||
|
||||
st1.st_dev == st2.st_dev)
|
||||
{
|
||||
bb_error_msg_and_die("bad newroot %s", newroot);
|
||||
}
|
||||
rootdev=st2.st_dev;
|
||||
rootdev = st2.st_dev;
|
||||
|
||||
// Additional sanity checks: we're about to rm -rf /, so be REALLY SURE
|
||||
// we mean it. (I could make this a CONFIG option, but I would get email
|
||||
// from all the people who WILL eat their filesystemss.)
|
||||
// from all the people who WILL eat their filesystems.)
|
||||
|
||||
if (lstat("/init", &st1) || !S_ISREG(st1.st_mode) || statfs("/", &stfs) ||
|
||||
(stfs.f_type != RAMFS_MAGIC && stfs.f_type != TMPFS_MAGIC) ||
|
||||
|
@ -105,14 +106,13 @@ int switch_root_main(int argc, char **argv)
|
|||
// recalculate "." and ".." links.
|
||||
|
||||
if (mount(".", "/", NULL, MS_MOVE, NULL) || chroot(".") || chdir("/"))
|
||||
bb_error_msg_and_die("moving root");
|
||||
bb_error_msg_and_die("error moving root");
|
||||
|
||||
// If a new console specified, redirect stdin/stdout/stderr to that.
|
||||
|
||||
if (console) {
|
||||
close(0);
|
||||
if (open(console, O_RDWR) < 0)
|
||||
bb_error_msg_and_die("bad console '%s'", console);
|
||||
xopen(console, O_RDWR);
|
||||
dup2(0, 1);
|
||||
dup2(0, 2);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue