simple-init

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

commit ff2ce9aaadadf1e64ab95113ea44417d39f35a6c
parent 549fbee214a4cd22df5e1cc9256d449a1c440f99
Author: depsterr <depsterr@protonmail.com>
Date:   Thu,  2 Jul 2020 04:08:12 +0200

fixed various bugs

Diffstat:
Minitscripts/Makefile | 2+-
Minitscripts/config.mk | 3+--
Ainitscripts/init.c | 78++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Minitscripts/util.c | 4++--
4 files changed, 82 insertions(+), 5 deletions(-)

diff --git a/initscripts/Makefile b/initscripts/Makefile @@ -11,7 +11,7 @@ install: default clean: rm rc.* -$(INIT): boot.c util.c +$(INIT): init.c util.c $(CC) $^ -o $@ $(SHUTDOWN): shutdown.c util.c diff --git a/initscripts/config.mk b/initscripts/config.mk @@ -1,7 +1,6 @@ # Change this if you want to install to a custom path. -DESTDIR=/usr/lib/init +DESTDIR?=/usr/lib/init CC=cc INIT=rc.boot SHUTDOWN=rc.shutdown - diff --git a/initscripts/init.c b/initscripts/init.c @@ -0,0 +1,78 @@ +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> + +#include "util.h" + +int main() { + + 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(); + spawn_process(udevcmd5); + + log_message("Boot completed, starting ttys"); + char* tty1[] = { "/usr/bin/getty", "38400", "tty1", 0 }; + char* tty2[] = { "/usr/bin/getty", "38400", "tty2", 0 }; + respawn_process(tty1); + respawn_process(tty2); +} diff --git a/initscripts/util.c b/initscripts/util.c @@ -58,8 +58,8 @@ void make_path(char* path) { for (int n = 1; path[n] != '\0' && ret == 0; n++) { if (path[n] == '/') { dirpath = realloc(dirpath, n + 1); - strncpy(dirpath, path, n); - dirpath[n + 1] = '\0'; + strncpy(dirpath, path, n + 1); + dirpath[n] = '\0'; mkdir(dirpath, 0755); } }