simple-init

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

commit 7f99c5d6b89b4edf6f3025b50dbb5b4cc52ae094
parent 9e0c3f9375d3a32b42eec9bf627ce9feeb3a6b52
Author: depsterr <depsterr@protonmail.com>
Date:   Sun, 31 May 2020 02:35:29 +0200

started work on initscripts

Diffstat:
Ainitscripts/Makefile | 11+++++++++++
Ainitscripts/config.h | 5+++++
Ainitscripts/util.c | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ainitscripts/util.h | 1+
Minstall.sh | 2++
5 files changed, 79 insertions(+), 0 deletions(-)

diff --git a/initscripts/Makefile b/initscripts/Makefile @@ -0,0 +1,11 @@ +CC=c99 + +default: rc.init rc.shutdown + +install: default + +rc.init: init.c util.c + $(CC) $^ -o $@ + +rc.shutdown: shutdown.c util.c + $(CC) $^ -o $@ diff --git a/initscripts/config.h b/initscripts/config.h @@ -0,0 +1,5 @@ +/* Services to run post boot */ +static char *const post_boot_services[] = { + { "/bin/getty/", "38400", "tty1", 0 } + { "/bin/getty/", "38400", "tty2", 0 } +}; diff --git a/initscripts/util.c b/initscripts/util.c @@ -0,0 +1,60 @@ +#include <sys/types.h> +#include <unistd.h> + +#include <stdlib.h> +#include <string.h> +#include <stdio.h> + +void spawn_process(char* argv[]) { + if (fork() == 0) { + setsid(); + execvp(argv[0], argv); + perror("execvp"); + exit(1); + } +} + +void log(char* msg) { + printf("\033[31;1m=>\033[m %s\n", msg); + printk("init: %s\n", msg); +} + +unsigned char is_mounted(char* path) { + if (access(path, F_OK) == -1) + return 0; + + if (access("/proc/mounts", F_OK) == -1) + return 0; + + struct mntent *ent; + FILE *aFile; + + aFile = setmntent("/proc/mounts", "r"); + + if (aFile == NULL) + return 0; + + while (NULL != (ent = getmntent(aFile))) { + if(!strcmp(path, ent->mnt_dir) + return 1; + } + endmntent(aFile); + return 0; +} + +void mount(char* options, char* type, char* device, char* mountpoint) { + if (is_mounted(mountpoint)) { + char newopts[256] = "remount," + strcat(newopts,options); + options = newopts; + } + + char *const mountcmd[] = { "/bin/mount", "-o", options, "-t", type, device, mountpoint, 0 }; + spawn(mountcmd); +} + +void save_random_seed() { +} + +void load_random_seed() { +} diff --git a/initscripts/util.h b/initscripts/util.h @@ -0,0 +1 @@ +void spawn_process(char *const argv[]); diff --git a/install.sh b/install.sh @@ -14,6 +14,8 @@ case $response in ;; esac +git submodule update --init --recursive + for dir in $MAKE_DIRECTORIES; do cd $dir make install