diff options
| author | m0 <dev@kthread.dev> | 2026-08-23 06:01:22 +0200 |
|---|---|---|
| committer | m0 <dev@kthread.dev> | 2026-08-23 06:01:22 +0200 |
| commit | f0dd2170866d3a93c0ddf031c7d294b303c8b1b4 (patch) | |
| tree | 8ef023ade4e8b9dfdc935e0faa6cee579dfc115d | |
| parent | fucking idiot (diff) | |
| download | 4suite-f0dd2170866d3a93c0ddf031c7d294b303c8b1b4.tar.gz 4suite-f0dd2170866d3a93c0ddf031c7d294b303c8b1b4.zip | |
4rc: move to golang
| -rw-r--r-- | 4rc/4rc.c | 112 | ||||
| -rw-r--r-- | 4rc/README.md | 3 | ||||
| -rw-r--r-- | 4rc/build.ninja | 41 | ||||
| -rw-r--r-- | 4rc/config.h | 4 | ||||
| -rw-r--r-- | 4rc/config.mk | 5 |
5 files changed, 2 insertions, 163 deletions
diff --git a/4rc/4rc.c b/4rc/4rc.c deleted file mode 100644 index 35a85d3..0000000 --- a/4rc/4rc.c +++ /dev/null @@ -1,112 +0,0 @@ -#define _DEFAULT_SOURCE -#define _POSIX_C_SOURCE 200809L - -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <string.h> -#include <sys/mount.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <unistd.h> - -void create_vfs(void) { - if (mkdir("/proc", 0755) != 0 && errno != EEXIST) { - perror("proc"); - } - if (mkdir("/sys", 0755) != 0 && errno != EEXIST) { - perror("sys"); - } - if (mkdir("/dev", 0755) != 0 && errno != EEXIST) { - perror("dev"); - } - if (mkdir("/run", 0755) != 0 && errno != EEXIST) { - perror("run"); - } -} - -void mount_vfs(void) { - if (mount("proc", "/proc", "proc", - MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0 && - errno != EBUSY) { - perror("mount /proc"); - } - - if (mount("sys", "/sys", "sysfs", - MS_NOSUID | MS_NODEV | MS_NOEXEC | MS_RELATIME, NULL) != 0 && - errno != EBUSY) { - perror("mount /sys"); - } - - if (mount("dev", "/dev", "devtmpfs", MS_NOSUID | MS_RELATIME, "mode=755") != - 0 && - errno != EBUSY) { - perror("mount /dev"); - } - - if (mount("run", "/run", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME, - "mode=755") != 0 && - errno != EBUSY) { - 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 && - errno != EBUSY) { - perror("mount /dev/pts"); - } - - if (mount("shm", "/dev/shm", "tmpfs", MS_NOSUID | MS_NODEV | MS_RELATIME, - "mode=1777") != 0 && - errno != EBUSY) { - perror("mount /dev/shm"); - } -} - -void set_hostname(void) { - char buf[256]; - int fd = open("/etc/hostname", O_RDONLY); - - if (fd < 0) { - perror("open /etc/hostname"); - return; - } - - ssize_t bytes_read = read(fd, buf, sizeof(buf) - 1); - close(fd); - - if (bytes_read > 0) { - buf[bytes_read] = '\0'; - size_t len = strcspn(buf, "\r\n "); - buf[len] = '\0'; - - if (sethostname(buf, len) != 0) { - perror("sethostname"); - } - } -} - -int main(void) { - create_vfs(); - mount_vfs(); - - int fd = open("/dev/console", O_RDWR); - - if (fd >= 0) { - dup2(fd, 0); - dup2(fd, 1); - dup2(fd, 2); - if (fd > 2) { - close(fd); - } - } else { - perror("console"); - } - - set_hostname(); - - return 0; -} diff --git a/4rc/README.md b/4rc/README.md index 9309fc9..753b709 100644 --- a/4rc/README.md +++ b/4rc/README.md @@ -1,3 +1,4 @@ # 4rc: service manager that larps as being functional -service manager, not much else to explain other for now.. +service manager, not much else to explain other for now... +you need the go toolchain for this, refer either to [go.dev](https://go.dev/doc/install) or install it through your distribution's package manager, if available. diff --git a/4rc/build.ninja b/4rc/build.ninja deleted file mode 100644 index cce3f53..0000000 --- a/4rc/build.ninja +++ /dev/null @@ -1,41 +0,0 @@ -# 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 deleted file mode 100644 index 6b3aeb1..0000000 --- a/4rc/config.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef CONFIG_H -#define CONFIG_H - -#endif // CONFIG_H diff --git a/4rc/config.mk b/4rc/config.mk deleted file mode 100644 index ab7e752..0000000 --- a/4rc/config.mk +++ /dev/null @@ -1,5 +0,0 @@ -PREFIX = /usr/local - -CC = musl-gcc -CFLAGS = -std=c99 -Wextra -Wall -Os -fhardened -LDFLAGS = -s -static |
