+- add patches.suse/early_userspace-instead-of-linuxrc
authorOlaf Hering <olh@suse.de>
Sun, 23 Nov 2003 21:03:16 +0000 (21:03 +0000)
committerOlaf Hering <olh@suse.de>
Sun, 23 Nov 2003 21:03:16 +0000 (21:03 +0000)
+  run /sbin/kinit if available, instead of linuxrc

suse-commit: 2d9a97e07460e78516e8985a7bc22ac857e51ff0

fs/binfmt_elf.c
init/do_mounts.c
init/initramfs.c
init/main.c
kernel/kmod.c
usr/gen_init_cpio.c
usr/sbin/hotplug.c [new file with mode: 0644]

index 969fdbb..1d414dd 100644 (file)
@@ -1449,7 +1449,7 @@ cleanup:
 
 #endif         /* USE_ELF_CORE_DUMP */
 
-static int __init init_elf_binfmt(void)
+int init_elf_binfmt(void)
 {
        return register_binfmt(&elf_format);
 }
@@ -1460,6 +1460,6 @@ static void __exit exit_elf_binfmt(void)
        unregister_binfmt(&elf_format);
 }
 
-module_init(init_elf_binfmt)
+EXPORT_SYMBOL(init_elf_binfmt);
 module_exit(exit_elf_binfmt)
 MODULE_LICENSE("GPL");
index ad8c88a..771a14e 100644 (file)
@@ -370,12 +370,38 @@ void __init mount_root(void)
        mount_block_root("/dev/root", root_mountflags);
 }
 
+extern int sysfs_mounted;
+extern asmlinkage long sys_access(const char * filename, int mode);
+extern asmlinkage long sys_umount(char __user * name, int flags);
+static char *kinit_command = "/sbin/kinit";
+
+static int __init kinit_setup(char *str)
+{
+       kinit_command = str;
+       return 1;
+}
+
+__setup("kinit=", kinit_setup);
+
+static int __init kinit_exec(void * shell)
+{
+       static char *argv[] = { "kinit", NULL, };
+       extern char * envp_init[];
+
+       close(0);close(1);close(2);
+       setsid();
+       (void) open("/dev/console",O_RDWR,0);
+       (void) dup(0);
+       (void) dup(0);
+       return execve(shell, argv, envp_init);
+}
 /*
  * Prepare the namespace - decide what/where to mount, load ramdisks, etc.
  */
 void __init prepare_namespace(void)
 {
        int is_floppy;
+       int pid, i;
 
        mount_devfs();
 
@@ -390,9 +416,26 @@ void __init prepare_namespace(void)
 
        is_floppy = MAJOR(ROOT_DEV) == FLOPPY_MAJOR;
 
+       if (sysfs_mounted)
+               sys_umount("/sys",0);
+
        if (initrd_load())
                goto out;
 
+       /*
+        * check if there is an early userspace init, if yes
+        * let it do all the work of mounting the root fs and return
+        */
+       if (kinit_command && sys_access(kinit_command,0) == 0) {
+               pid = kernel_thread(kinit_exec, kinit_command, SIGCHLD);
+               if (pid > 0) {
+                       while (pid != waitpid(-1, &i, 0))
+                               yield();
+               }
+               sys_chdir("/root");
+               goto out;
+       }
+
        if (is_floppy && rd_doload && rd_load_disk(0))
                ROOT_DEV = Root_RAM0;
 
index 38d00d0..6150eb7 100644 (file)
@@ -477,12 +477,17 @@ extern char __initramfs_start, __initramfs_end;
 #include <linux/initrd.h>
 #endif
 
+extern int sysfs_mounted;
+
 void __init populate_rootfs(void)
 {
        char *err = unpack_to_rootfs(&__initramfs_start,
                         &__initramfs_end - &__initramfs_start, 0);
        if (err)
                panic(err);
+       sysfs_mounted = sys_mount("sys", "/sys","sysfs",NULL,NULL);
+       printk(" mount sysfs returned %ld\n", sysfs_mounted);
+       sysfs_mounted = !sysfs_mounted;
 #ifdef CONFIG_BLK_DEV_INITRD
        if (initrd_start) {
                int fd;
index b969f8f..efaa537 100644 (file)
@@ -491,6 +491,7 @@ asmlinkage void __init start_kernel(void)
 }
 
 int __initdata initcall_debug;
+int __initdata sysfs_mounted;
 
 static int __init initcall_debug_setup(char *str)
 {
@@ -535,6 +536,8 @@ static void __init do_initcalls(void)
        flush_scheduled_work();
 }
 
+int init_elf_binfmt(void);
+
 /*
  * Ok, the machine is now initialized. None of the devices
  * have been touched yet, but the CPU subsystem is up and
@@ -554,6 +557,7 @@ static void __init do_basic_setup(void)
        sock_init();
 
        init_workqueues();
+       init_elf_binfmt();
        do_initcalls();
 }
 
index 2c74533..07096c1 100644 (file)
@@ -249,7 +249,7 @@ int call_usermodehelper(char *path, char **argv, char **envp, int wait)
        };
        DECLARE_WORK(work, __call_usermodehelper, &sub_info);
 
-       if (!system_running)
+       if (0 && !system_running)
                return -EBUSY;
 
        if (path[0] == '\0')
index e1ccfaa..fd89afd 100644 (file)
@@ -215,7 +215,10 @@ int main (int argc, char *argv[])
 {
        cpio_mkdir("/dev", 0755, 0, 0);
        cpio_mknod("/dev/console", 0600, 0, 0, 'c', 5, 1);
+       cpio_mknod("/dev/ram0", 0600, 0, 0, 'b', 5, 1);
        cpio_mkdir("/root", 0700, 0, 0);
+       cpio_mkdir("/sys", 0755, 0, 0);
+       cpio_mkdir("/events", 0755, 0, 0);
        cpio_trailer();
 
        exit(0);
diff --git a/usr/sbin/hotplug.c b/usr/sbin/hotplug.c
new file mode 100644 (file)
index 0000000..e55c870
--- /dev/null
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+#define BUFSIZE 12345
+int
+main(int argc, char **argv, char **envp)
+{
+       int fd, i;
+       char **ep = envp;
+       char *buf, *p;
+       buf = malloc(42);
+       if (!buf)
+               exit(1);
+       p = getenv("SEQNUM");
+       snprintf(buf, 42, "/events/dbg.%08u.%s", getpid(), p ? p : "");
+       if ((fd = open(buf, O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) {
+               //perror(buf);
+               exit(1);
+       }
+       free(buf);
+       p = malloc(BUFSIZE);
+       buf = p;
+       for (i = 0; i < argc; ++i) {
+               buf += snprintf(buf, p + BUFSIZE - buf, " %s", argv[i]);
+               if (buf > p + BUFSIZE)
+                       goto full;
+       }
+       buf += snprintf(buf, p + BUFSIZE - buf, "\n");
+       if (buf > p + BUFSIZE)
+               goto full;
+       while (*ep) {
+               buf += snprintf(buf, p + BUFSIZE - buf, "%s\n", *ep++);
+               if (buf > p + BUFSIZE)
+                       break;
+       }
+      full:
+       buf = p;
+       write(fd, buf, strlen(buf));
+       close(fd);
+       free(buf);
+       return 0;
+}