diff options
author | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-08-11 20:20:47 +0300 |
---|---|---|
committer | Yaroslav de la Peña Smirnov <yps@yaroslavps.com> | 2025-08-11 20:20:47 +0300 |
commit | f6a1cdd50b3ab0116be6d853a0577e22b2e69f8c (patch) | |
tree | 1dddecc4db0bba47f51111adbf4cab3192b2823b /minit.c | |
download | minit-f6a1cdd50b3ab0116be6d853a0577e22b2e69f8c.tar.gz minit-f6a1cdd50b3ab0116be6d853a0577e22b2e69f8c.zip |
init minit commit, innit
Diffstat (limited to 'minit.c')
-rw-r--r-- | minit.c | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -0,0 +1,40 @@ +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> + +#include <linux/reboot.h> +#include <sys/mount.h> +#include <sys/reboot.h> +#include <sys/syscall.h> + +[[noreturn]] +int main(int argc, char *argv[]) +{ + if (argc < 2) { + puts("usage: minit <command>"); + exit(1); + } + + int rc = mount("proc", "/proc", "proc", 0, NULL); + if (rc) + puts("warning: unable to mount proc!"); + + rc = mount("sysfs", "/sys", "sysfs", 0, NULL); + if (rc) { + puts("warning: unable to mount sysfs!"); + } else { + rc = mount("debugfs", "/sys/kernel/debug", "debugfs", 0, NULL); + if (rc) + puts("warning: unable to mount debugfs!"); + } + + rc = system(argv[1]); + if (rc) { + puts("the command exited with failure"); + } + + sync(); + rc = reboot(LINUX_REBOOT_CMD_HALT); + /* If we made it here something went wrong with the reboot command */ + exit(rc); +} |