aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile6
-rw-r--r--minit.c40
3 files changed, 47 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..97c86d6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/minit
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..a07604c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,6 @@
+TARGET?=x86_64-linux-musl
+CFLAGS?=-Os -s
+CC:=zig cc -target $(TARGET)
+
+minit: minit.c
+ $(CC) $(CFLAGS) -o minit minit.c
diff --git a/minit.c b/minit.c
new file mode 100644
index 0000000..7ea9688
--- /dev/null
+++ b/minit.c
@@ -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);
+}