summaryrefslogtreecommitdiff
path: root/4rc
diff options
context:
space:
mode:
Diffstat (limited to '4rc')
-rwxr-xr-x4rc/4rcbin0 -> 17872 bytes
-rw-r--r--4rc/4rc.c56
-rw-r--r--4rc/README.md5
-rw-r--r--4rc/build.ninja41
-rw-r--r--4rc/config.h4
-rw-r--r--4rc/config.mk5
6 files changed, 111 insertions, 0 deletions
diff --git a/4rc/4rc b/4rc/4rc
new file mode 100755
index 0000000..1df6d60
--- /dev/null
+++ b/4rc/4rc
Binary files differ
diff --git a/4rc/4rc.c b/4rc/4rc.c
new file mode 100644
index 0000000..68a5d9f
--- /dev/null
+++ b/4rc/4rc.c
@@ -0,0 +1,56 @@
+#define _POSIX_C_SOURCE 200809L
+
+#include <stdio.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+void create_vfs(void) {
+ mkdir("/proc", 0755);
+ mkdir("/sys", 0755);
+ mkdir("/dev", 0755);
+ mkdir("/run", 0755);
+}
+
+void mount_vfs(void) {
+ if (mount("proc", "/proc", "proc",
+ MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0) {
+ perror("mount /proc");
+ }
+
+ if (mount("sys", "/sys", "sysfs",
+ MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0) {
+ perror("mount /sys");
+ }
+
+ if (mount("dev", "/dev", "devtmpfs", MS_NOSUID | MS_RELATIME, "mode=755") !=
+ 0) {
+ perror("mount /dev");
+ }
+
+ if (mount("run", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME,
+ "mode=755") != 0) {
+ perror("mount /run");
+ }
+
+ mkdir("/dev/pts", 0755);
+ mkdir("/dev/shm", 1777);
+
+ if (mount("devpts", "/dev/pts", "devpts",
+ MS_NOSUID | MS_NOEXEC | MS_RELATIME, "gid=5,mode=620") != 0) {
+ perror("mount /dev/pts");
+ }
+
+ if (mount("shm", "/dev/shm", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME,
+ "mode=1777") != 0) {
+ perror("mount /dev/shm");
+ }
+}
+
+int main(void) {
+ create_vfs();
+ mount_vfs();
+
+ return 0;
+}
diff --git a/4rc/README.md b/4rc/README.md
new file mode 100644
index 0000000..44fbde5
--- /dev/null
+++ b/4rc/README.md
@@ -0,0 +1,5 @@
+# 4init: minimal but functional init
+
+It's only purpose is to manage processes, it by defaults calls 4rc, but you can change that in `config.h`, it's started as PID 1, and if it crashes, the kernel will panic, read the article in Wikipedia if you want to know more.
+
+Inspired by [rofl0r](https://gist.github.com/rofl0r/6168719)'s minimal init. \ No newline at end of file
diff --git a/4rc/build.ninja b/4rc/build.ninja
new file mode 100644
index 0000000..cce3f53
--- /dev/null
+++ b/4rc/build.ninja
@@ -0,0 +1,41 @@
+# this file was generated from a makefile by shinobi
+build __shin_always_build__: phony
+
+build all: phony 4rc
+
+rule r1
+ command = musl-gcc -s -static -o 4rc 4rc.o
+ generator = 1
+
+build 4rc: r1 4rc.o
+ description = build 4rc
+
+rule r2
+ command = musl-gcc -std=c99 -Wextra -Wall -Os -fhardened -c -o 4rc.o 4rc.c
+ generator = 1
+
+build 4rc.o: r2 4rc.c config.h
+ description = build 4rc.o
+
+rule r3
+ command = sh -c 'mkdir -pv /usr/local/bin' && sh -c 'cp -fv 4rc /usr/local/bin'
+ generator = 1
+
+build install: r3
+ description = build install
+
+rule r4
+ command = rm -f /usr/local/bin/4rc
+ generator = 1
+
+build uninstall: r4
+ description = build uninstall
+
+rule r5
+ command = rm -f 4rc.o 4rc
+ generator = 1
+
+build clean: r5
+ description = build clean
+
+default all
diff --git a/4rc/config.h b/4rc/config.h
new file mode 100644
index 0000000..6b3aeb1
--- /dev/null
+++ b/4rc/config.h
@@ -0,0 +1,4 @@
+#ifndef CONFIG_H
+#define CONFIG_H
+
+#endif // CONFIG_H
diff --git a/4rc/config.mk b/4rc/config.mk
new file mode 100644
index 0000000..ab7e752
--- /dev/null
+++ b/4rc/config.mk
@@ -0,0 +1,5 @@
+PREFIX = /usr/local
+
+CC = musl-gcc
+CFLAGS = -std=c99 -Wextra -Wall -Os -fhardened
+LDFLAGS = -s -static