simple-init

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

commit 4afc24fd19c1e7160bf8a41e40386f98d85e72ca
parent 0551e88bdf8f269d09217de57b594a3c35e002e6
Author: depsterr <depsterr@protonmail.com>
Date:   Sun, 31 May 2020 18:39:42 +0200

created simple shutdown

Diffstat:
MREADME.md | 14+++-----------
Minitscripts/init.c | 1+
Minitscripts/shutdown.c | 12+++++++++++-
3 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/README.md b/README.md @@ -2,19 +2,11 @@ These are some linux init "scripts" written in C. The scripts are heavily inspired by [the kisslinux init scripts](https://github.com/kisslinux/init). However, unlike the kiss init scripts, my init script doesn't: -* support mdev (though you could easily change this yourself) +* support mdev, if you want/need this, then edit the source. -* read options from rc.conf +* use any hooks, config files etc, if you want/need this, then edit the source. -* apply sysctl conf files (if you need this, then you could write a script and then look at 'Services and custom startup programs') - -## Progress - -The boot init script currently works. - -The shutdown script is not yet implemented. - -## Services and custom startup programs +## Adding services or hooks Just add them in `init.c` with a call to `spawn_process`, though beware of the following: diff --git a/initscripts/init.c b/initscripts/init.c @@ -39,6 +39,7 @@ int main() { 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); diff --git a/initscripts/shutdown.c b/initscripts/shutdown.c @@ -1,4 +1,5 @@ #include <sys/reboot.h> +#include <signal.h> #include <unistd.h> #include "util.h" @@ -7,15 +8,24 @@ int main(int argc, char* argv[]) { if (argc < 2) exit(1); + log("Saving random seed"); save_random_seed(); + log("Sending TERM signal to all processes"); + kill(-1, SIGTERM); sleep(2); + log("Sending KILL signal to all processes"); + kill(-1, SIGKILL); + + log("Unmounting all filesystems"); char* swapcmd[] = { "swapoff", "-a", 0}; - char* umountcmd[] = { "mount", "-rat", "nosysfs,noproc,nodevtmpfs,notmpfs", 0}; + char* umountcmd[] = { "umount", "-ra", 0}; spawn_process(swapcmd); spawn_process(umountcmd); + wait_for_children(); + log("Requesting shutdown from kernel"); if(argv[1][0] == 'p') { reboot(RB_POWER_OFF); } else {