Skip to content

Commit ba4df28

Browse files
author
Al Viro
committed
don't bother with kernel_thread/kernel_execve for launching linuxrc
exec_usermodehelper_fns() will do just fine... Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
1 parent cb45076 commit ba4df28

1 file changed

Lines changed: 16 additions & 25 deletions

File tree

‎init/do_mounts_initrd.c‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
#include <linux/initrd.h>
1717
#include <linux/sched.h>
1818
#include <linux/freezer.h>
19+
#include <linux/kmod.h>
1920

2021
#include "do_mounts.h"
2122

2223
unsigned long initrd_start, initrd_end;
2324
int initrd_below_start_ok;
2425
unsigned int real_root_dev; /* do_proc_dointvec cannot handle kdev_t */
25-
static int __initdata old_fd, root_fd;
2626
static int __initdata mount_initrd = 1;
2727

2828
static int __init no_initrd(char *str)
@@ -33,61 +33,52 @@ static int __init no_initrd(char *str)
3333

3434
__setup("noinitrd", no_initrd);
3535

36-
static int __init do_linuxrc(void *_shell)
36+
static int init_linuxrc(struct subprocess_info *info, struct cred *new)
3737
{
38-
static const char *argv[] = { "linuxrc", NULL, };
39-
extern const char *envp_init[];
40-
const char *shell = _shell;
41-
42-
sys_close(old_fd);sys_close(root_fd);
38+
sys_unshare(CLONE_FS | CLONE_FILES);
39+
/* move initrd over / and chdir/chroot in initrd root */
40+
sys_chdir("/root");
41+
sys_mount(".", "/", NULL, MS_MOVE, NULL);
42+
sys_chroot(".");
4343
sys_setsid();
44-
return kernel_execve(shell, argv, envp_init);
44+
return 0;
4545
}
4646

4747
static void __init handle_initrd(void)
4848
{
49+
static char *argv[] = { "linuxrc", NULL, };
50+
extern char *envp_init[];
4951
int error;
50-
int pid;
5152

5253
real_root_dev = new_encode_dev(ROOT_DEV);
5354
create_dev("/dev/root.old", Root_RAM0);
5455
/* mount initrd on rootfs' /root */
5556
mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
5657
sys_mkdir("/old", 0700);
57-
root_fd = sys_open("/", 0, 0);
58-
old_fd = sys_open("/old", 0, 0);
59-
/* move initrd over / and chdir/chroot in initrd root */
60-
sys_chdir("/root");
61-
sys_mount(".", "/", NULL, MS_MOVE, NULL);
62-
sys_chroot(".");
58+
sys_chdir("/old");
6359

6460
/*
6561
* In case that a resume from disk is carried out by linuxrc or one of
6662
* its children, we need to tell the freezer not to wait for us.
6763
*/
6864
current->flags |= PF_FREEZER_SKIP;
6965

70-
pid = kernel_thread(do_linuxrc, "/linuxrc", SIGCHLD);
71-
if (pid > 0)
72-
while (pid != sys_wait4(-1, NULL, 0, NULL))
73-
yield();
66+
call_usermodehelper_fns("/linuxrc", argv, envp_init, UMH_WAIT_PROC,
67+
init_linuxrc, NULL, NULL);
7468

7569
current->flags &= ~PF_FREEZER_SKIP;
7670

7771
/* move initrd to rootfs' /old */
78-
sys_fchdir(old_fd);
79-
sys_mount("/", ".", NULL, MS_MOVE, NULL);
72+
sys_mount("..", ".", NULL, MS_MOVE, NULL);
8073
/* switch root and cwd back to / of rootfs */
81-
sys_fchdir(root_fd);
82-
sys_chroot(".");
83-
sys_close(old_fd);
84-
sys_close(root_fd);
74+
sys_chroot("..");
8575

8676
if (new_decode_dev(real_root_dev) == Root_RAM0) {
8777
sys_chdir("/old");
8878
return;
8979
}
9080

81+
sys_chdir("/");
9182
ROOT_DEV = new_decode_dev(real_root_dev);
9283
mount_root();
9384

0 commit comments

Comments
 (0)