simple-init

A set of init binaries for linux
git clone git://depsterr.com/git/simple-init
Log | Files | Refs | README | LICENSE

commit 549fbee214a4cd22df5e1cc9256d449a1c440f99
parent b224bcce2e8727991dd2d65d998b5fc57744cbbd
Author: depsterr <depsterr@protonmail.com>
Date:   Mon, 22 Jun 2020 18:40:49 +0200

fixed various issues

Diffstat:
Minitscripts/Makefile | 2+-
Ainitscripts/boot.c | 83+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Minitscripts/config.mk | 2+-
Dinitscripts/init.c | 77-----------------------------------------------------------------------------
Minitscripts/util.h | 2--
5 files changed, 85 insertions(+), 81 deletions(-)

diff --git a/initscripts/Makefile b/initscripts/Makefile @@ -11,7 +11,7 @@ install: default clean: rm rc.* -$(INIT): init.c util.c +$(INIT): boot.c util.c $(CC) $^ -o $@ $(SHUTDOWN): shutdown.c util.c diff --git a/initscripts/boot.c b/initscripts/boot.c @@ -0,0 +1,83 @@ +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +#include "util.h" + +int main() { + + log_message("Welcome to linux"); + + log_message("Mounting pseudo filesystems"); + + mount("nosuid,noexec,nodev", "proc", "proc", "/proc" ); + mount("nosuid,noexec,nodev", "sysfs", "sys", "/sys" ); + mount("mode=0755,nosuid,nodev", "tmpfs", "run", "/run" ); + wait_for_children(); + mount("mode=0755,nosuid", "devtmpfs", "dev", "/dev" ); + + mkdir("/run/user" , 0755); + mkdir("/run/lock" , 0755); + mkdir("/run/log" , 0755); + mkdir("/dev/pts" , 0755); + mkdir("/dev/shm" , 0755); + + wait_for_children(); + mount("mode=0620,gid=5,nosuid,noexec", "devpts", "devpts", "/dev/pts" ); + mount("mode=1777,nosuid,nodev", "tmpfs", "shm", "/dev/shm" ); + + + /* dest, link */ + symlink("/proc/self/fd", "/dev/fd" ); + symlink("fd/0", "/dev/stdin" ); + symlink("fd/1", "/dev/stdout" ); + symlink("fd/2", "/dev/stderr" ); + + /* Call modprobe stuff here */ + + log_message("Starting device manager"); + + log_message("Starting udev"); + char* udevcmd1[] = { "udevd", "-d", 0}; + char* udevcmd2[] = { "udevadm", "trigger", "-c", "add", "-t", "subsystems", 0}; + /* avoid storing duplicate strings twice. */ + char* udevcmd3[] = { udevcmd2[0], udevcmd2[1], udevcmd2[2], udevcmd2[3], udevcmd2[4], "devices", 0}; + char* udevcmd4[] = { udevcmd2[0], "settle", 0}; + spawn_process(udevcmd1); + wait_for_children(); + spawn_process(udevcmd2); + spawn_process(udevcmd3); + wait_for_children(); + spawn_process(udevcmd4); + + log_message("Mounting filesystems"); + char* mountcmd1[] = { "mount", "-o", "remount,rw", "/", 0}; + char* mountcmd2[] = { mountcmd1[0], "-a", 0}; + spawn_process(mountcmd1); + spawn_process(mountcmd2); + + log_message("Enabling swap"); + char* swapcmd[] = { "swapon", mountcmd2[1], 0}; + spawn_process(swapcmd); + + log_message("Seeding random"); + load_random_seed(); + + log_message("Setting up loopback"); + char* netloopcmd[] = { "ip", "link", "set", "up", "dev", "lo", 0}; + spawn_process(netloopcmd); + + log_message("Killing device managers"); + char* udevcmd5[] = { udevcmd2[0], "control", "--exit", 0}; + wait_for_children(); + spawn_process(udevcmd5); + + /* Startup services here */ + + wait_for_children(); + log_message("Boot completed, starting ttys"); + char* tty1[] = { "/bin/getty", "38400", "tty1", 0 }; + char* tty2[] = { "/bin/getty", "38400", "tty2", 0 }; + respawn_process(tty1); + respawn_process(tty2); +} diff --git a/initscripts/config.mk b/initscripts/config.mk @@ -2,6 +2,6 @@ DESTDIR=/usr/lib/init CC=cc -INIT=rc.init +INIT=rc.boot SHUTDOWN=rc.shutdown diff --git a/initscripts/init.c b/initscripts/init.c @@ -1,77 +0,0 @@ -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> - -#include "util.h" - -int main() { - - log_message("Welcome to linux"); - - log_message("Mounting pseudo filesystems"); - - mount("nosuid,noexec,nodev", "proc", "proc", "/proc" ); - mount("nosuid,noexec,nodev", "sysfs", "sys", "/sys" ); - mount("mode=0755,nosuid,nodev", "tmpfs", "run", "/run" ); - wait_for_children(); - mount("mode=0755,nosuid", "devtmpfs", "dev", "/dev" ); - - mkdir("/run/user" , 0755); - mkdir("/run/lock" , 0755); - mkdir("/run/log" , 0755); - mkdir("/dev/pts" , 0755); - mkdir("/dev/shm" , 0755); - - wait_for_children(); - mount("mode=0620,gid=5,nosuid,noexec", "devpts", "devpts", "/dev/pts" ); - mount("mode=1777,nosuid,nodev", "tmpfs", "shm", "/dev/shm" ); - - - /* dest, link */ - symlink("/proc/self/fd", "/dev/fd" ); - symlink("fd/0", "/dev/stdin" ); - symlink("fd/1", "/dev/stdout" ); - symlink("fd/2", "/dev/stderr" ); - - log_message("Starting device manager"); - - log_message("Starting udev"); - char* udevcmd1[] = { "udevd", "-d", 0}; - char* udevcmd2[] = { "udevadm", "trigger", "-c", "add", "-t", "subsystems", 0}; - /* avoid storing duplicate strings twice. */ - char* udevcmd3[] = { udevcmd2[0], udevcmd2[1], udevcmd2[2], udevcmd2[3], udevcmd2[4], "devices", 0}; - char* udevcmd4[] = { udevcmd2[0], "settle", 0}; - spawn_process(udevcmd1); - wait_for_children(); - spawn_process(udevcmd2); - spawn_process(udevcmd3); - wait_for_children(); - spawn_process(udevcmd4); - - log_message("Mounting filesystems"); - char* mountcmd1[] = { "mount", "-o", "remount,rw", "/", 0}; - char* mountcmd2[] = { mountcmd1[0], "-a", 0}; - spawn_process(mountcmd1); - spawn_process(mountcmd2); - - log_message("Enabling swap"); - char* swapcmd[] = { "swapon", mountcmd2[1], 0}; - spawn_process(swapcmd); - - log_message("Seeding random"); - load_random_seed(); - - log_message("Setting up loopback"); - char* netloopcmd[] = { "ip", "link", "set", "up", "dev", "lo", 0}; - spawn_process(netloopcmd); - - log_message("Killing device managers"); - char* udevcmd5[] = { udevcmd2[0], "control", "--exit", 0}; - - wait_for_children(); - log_message("Boot completed, starting ttys"); - char* tty1[] = { "/bin/getty", "38400", "tty1", 0 }; - char* tty2[] = { "/bin/getty", "38400", "tty2", 0 }; - respawn_process(tty1); - respawn_process(tty2); -} diff --git a/initscripts/util.h b/initscripts/util.h @@ -1,5 +1,3 @@ -#include "config.h" - /* Waits for children to exit. If children exit unsuccessfully it drops the user into an emergency shell */ void wait_for_children();