dualinit

A meta-init system for linux
Log | Files | Refs | LICENSE

commit 067eb5082f7fa26e9ddfd0f05cdbc43c06113402
parent 725c264213c80ab465910e41818fe7b56b60e2aa
Author: Friedel Schoen <[email protected]>
Date:   Thu, 29 Dec 2022 00:22:08 +0100

removing default mounts

Diffstat:
Mincl/config.h | 2--
Mincl/default.h | 12++----------
Msrc/config.c | 43+++++++++++++++----------------------------
Dsrc/default.c | 24------------------------
Msrc/exec/dualinit.c | 27+++++----------------------
5 files changed, 22 insertions(+), 86 deletions(-)

diff --git a/incl/config.h b/incl/config.h @@ -43,8 +43,6 @@ extern bool color; extern bool verbose; extern mount_t mounts[]; extern int mount_size; -extern bool mount_default; -extern bool mount_master; extern int timeout; parse_error_t config_parsef(FILE* file, const char* filename); diff --git a/incl/default.h b/incl/default.h @@ -10,14 +10,6 @@ # define DEFAULT_INIT "/sbin/init" #endif -#ifndef REBOOT_INSTR -# define REBOOT_INSTR "/etc/dualinit-reboot.txt" -#endif - #ifndef DEFAULT_EXEC_PATH # define DEFAULT_EXEC_PATH "/usr/share/dualinit/bin/init" -#endif - -extern const mount_t DEFAULT_MOUNTS[]; - -extern const char* DEFAULT_MASTER_MOUNTS[]; -\ No newline at end of file +#endif +\ No newline at end of file diff --git a/src/config.c b/src/config.c @@ -8,6 +8,7 @@ #include <stdlib.h> #include <string.h> #include <sys/fcntl.h> +#include <sys/mount.h> #include <unistd.h> #define CHECK_SECTION \ @@ -53,15 +54,13 @@ section_t sections[SECTION_MAX]; mount_t mounts[SECTION_MOUNT_MAX]; -int section_size = 0; -int mount_size = 0; -section_t* master = NULL; -section_t* default_s = NULL; -bool color = false; -bool verbose = true; -bool mount_default = true; -bool mount_master = true; -int timeout = 10; +int section_size = 0; +int mount_size = 0; +section_t* master = NULL; +section_t* default_s = NULL; +bool color = false; +bool verbose = true; +int timeout = 10; parse_error_t config_parse(int fd, const char* filename) { @@ -199,16 +198,6 @@ parse_error_t config_parsef(FILE* file, const char* filename) { CHECK_PARAMS_EQUALS(2); PARSE_BOOL(verbose); - } else if (streq(columns[0], "mount-default")) { - CHECK_ROOT; - CHECK_PARAMS_EQUALS(2); - - PARSE_BOOL(mount_default); - } else if (streq(columns[0], "mount-master")) { - CHECK_ROOT; - CHECK_PARAMS_EQUALS(2); - - PARSE_BOOL(mount_master); } else if (streq(columns[0], "master")) { CHECK_SECTION; CHECK_PARAMS_EQUALS(1); @@ -329,15 +318,13 @@ void config_cleanup() { void config_reset() { config_cleanup(); - section_size = 0; - mount_size = 0; - master = NULL; - default_s = NULL; - color = false; - verbose = true; - mount_default = true; - mount_master = true; - timeout = 10; + section_size = 0; + mount_size = 0; + master = NULL; + default_s = NULL; + color = false; + verbose = true; + timeout = 10; } diff --git a/src/default.c b/src/default.c @@ -1,23 +0,0 @@ -#include "default.h" - -#include <sys/mount.h> - -const mount_t DEFAULT_MOUNTS[] = { - { NULL, "/dev", "/dev", NULL, MS_BIND | MS_REC, false }, - // - /dev /dev rbind - { NULL, "/", "/dualinit", NULL, MS_BIND, false }, - // - / /dualinit bind - { "proc", "proc", "/proc", NULL, MS_RELATIME, false }, - // proc proc /proc relatime - { "tmpfs", "run", "/run", "mode=0755", 0, false }, - // tmpfs run /run mode=0755 - { NULL, "/sys", "/sys", NULL, MS_BIND | MS_REC, false }, - // - /sys /sys rbind - { "tmpfs", "tmp", "/tmp", "mode=1777", MS_STRICTATIME, false }, - // tmpfs tmp /tmp mode=1777,strictatime - { 0 }, -}; - -const char* DEFAULT_MASTER_MOUNTS[] = { - "/boot", "/lost+found", NULL -}; -\ No newline at end of file diff --git a/src/exec/dualinit.c b/src/exec/dualinit.c @@ -47,7 +47,7 @@ int main() { PANIC("cannot open %s: %s\n", DEFAULT_CONFIG, strerror(errno)); } - parse_error_t parse_code = parse_config(choice_file, DEFAULT_CONFIG); + parse_error_t parse_code = config_parse(choice_file, DEFAULT_CONFIG); if (parse_code != 0) { PANIC("invalid config"); } @@ -87,27 +87,11 @@ int main() { for (int i = 0; i < mount_size; i++) { mount_chroot(section->root, &mounts[i]); - free_mount(&mounts[i]); - } - - if (mount_default) { - for (const mount_t* mnt = DEFAULT_MOUNTS; mnt->target != NULL; mnt++) { - mount_chroot(section->root, mnt); - } - } - - if (mount_master) { - for (const char** mnt = DEFAULT_MASTER_MOUNTS; *mnt; mnt++) { - self_mount.source = *mnt; - self_mount.target = *mnt; - mount_chroot(section->root, &self_mount); - } } } for (int i = 0; i < section->mount_size; i++) { mount_chroot(section->root, &section->mounts[i]); - free_mount(&mounts[i]); } if (!is_root) { @@ -126,12 +110,11 @@ int main() { if (section->init != NULL) strcpy(init, section->init); - for (int i = 0; i < section_index; i++) - free_section(&section[i]); + config_cleanup(); INFO("entering %s\n\n", init); - if (execlp(section->init, section->init, NULL) == -1) { - PANIC("error: cannot execute %s: %s\n", section->init, strerror(errno)); - } + execlp(section->init, section->init, NULL); + + PANIC("error: cannot execute %s: %s\n", section->init, strerror(errno)); }