Commit c0fadc97af

c0fadc97af8d639fd2cf0bd09ceb06764111c204

Unsigned

Ilkay Alakay <ilkay@exherbo.domain.foo> · 2026-09-30 12:54 UTC

ilkay/iinitt: create repository

Layout: unified · split

Makefile added +18
@@ -0,0 +1,18 @@
1all: program1 program2 program3
2
3program1: iinitt.c
4 gcc iinitt.c -o iinitt
5program2: reboot.c
6 gcc reboot.c -o reboot
7program3: poweroff.c
8 gcc poweroff.c -o poweroff
9
10install: all
11 mkdir -p /sbin
12 mv iinitt /sbin/
13 mv reboot /sbin/
14 mv poweroff /sbin/
15 chmod 777 /sbin/{iinitt,reboot,poweroff}
16
17clean:
18 rm -rf /sbin/iinitt /sbin/reboot /sbin/poweroff
README.md added +22
@@ -0,0 +1,22 @@
1# iinitt
2ilkay(s/own) init
3a suckless init - without runlevels, and with only one configuration file
4
5# dependencies
6you need eudev (or udev from systemd) and your own list of hardware modules, the init does not have any modprobing protocols/services, see https://iinitt.nekoweb.org; p2.1. ELogind (or ConsoleKit) is also a need for TTYs (the system will boot up but it will gonna use /dev/console) and/or DE/WM sessions.
7
8# installation
9make -j$(nproc) && (#) make install
10*manually;*
11@ first compile the code:
12$ gcc iinitt.c -o iinitt
13@ then move the init executable to /sbin:
14'# mv iinitt /sbin
15!!@!! make sure that executable is not a dynamic executable!
16@ make the executable r/w/e:
17'# chmod 777 /sbin/iinitt
18!!@!! then boot with the kernel parameters:
19init=/sbin/iinitt
20
21# wiki
22https://iinitt.nekoweb.org/
iinitt.c added +151
@@ -0,0 +1,151 @@
1// Ilkay Alakay <ilkay@astronix.org>. Licensed under GNU GPLv3<.0>
2// requires Eudev!!! <https://github.com/ilkayBedrock/eudev-iinitt>
3#include <stdio.h>
4#include <unistd.h>
5#include <sys/mount.h>
6#include <sys/wait.h>
7#include <sys/types.h>
8#include <sys/stat.h>
9#include <stdlib.h>
10#include <signal.h>
11#include <sys/reboot.h>
12#include <string.h>
13
14void start_service(char *path){
15 pid_t pid = fork();
16 if (pid < 0){
17 perror("fork failed");
18 return;
19 }
20 if (pid == 0) {
21 setsid();
22 execl(path, path, NULL);
23 perror("exec failed");
24 exit(1);
25 }
26}
27
28void start_dbus(){
29 pid_t pid = fork();
30 if (pid < 0) {
31 perror("fork failed");
32 return;
33 }
34 if (pid == 0){
35 setsid();
36 execl("/usr/bin/dbus-daemon", "dbus-daemon", "--system", "--nofork", NULL);
37 perror("dbus-daemon failed");
38 exit(1);
39 }
40}
41
42void start_getty(){
43 pid_t pid = fork();
44 if (pid < 0) {
45 perror("fork failed");
46 return;
47 }
48 if (pid == 0){
49 setsid();
50 execl("/sbin/agetty", "agetty", "--noreset", "--noclear",
51 "--issue-file=/etc/issue:/etc/issue.d:/run/issue.d:/usr/lib/issue.d - ${TERM}", NULL);
52 perror("agetty failed");
53 exit(1);
54 }
55}
56
57void do_reboot(){
58 write(1, "iinitt: rebooting...\n", strlen("iinitt: rebooting...\n"));
59 sync();
60 mount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
61 sync();
62 reboot(RB_AUTOBOOT);
63}
64
65void do_poweroff(){
66 write(1, "iinitt: shutting down root...\n", strlen("iinitt: shutting down root...\n"));
67 sync();
68 mount(NULL, "/", NULL, MS_REMOUNT | MS_RDONLY, NULL);
69 sync();
70 reboot(RB_POWER_OFF);
71}
72
73void handle_signal(int sig){
74 if (sig == SIGTERM){
75 do_poweroff();
76 }
77 if (sig == SIGINT){
78 do_reboot();
79 }
80}
81
82int main(){
83 signal(SIGPIPE, SIG_IGN);
84 signal(SIGTERM, handle_signal);
85 signal(SIGINT, handle_signal);
86 reboot(RB_ENABLE_CAD);
87
88 printf("\033[2J\033[H");
89 printf("iinitt v5.4.1: ilkay STARTING...\n");
90 umask(022);
91
92 if (mount(NULL, "/", NULL, MS_REMOUNT, NULL) < 0) {
93 perror("Failed to remount rootfs RW");
94 }
95 mount("proc", "/proc", "proc", 0, "");
96 mount("sysfs", "/sys", "sysfs", 0, "");
97 mount("devtmpfs", "/dev", "devtmpfs", 0, "");
98 mkdir("/run", 0755);
99 mount("tmpfs", "/run", "tmpfs", 0, "");
100 mkdir("/tmp", 1777);
101 mount("tmpfs", "/tmp", "tmpfs", 0, "");
102 mkdir("/run/dbus", 0755);
103 mkdir("/dev/pts", 0755);
104 mount("devpts", "/dev/pts", "devpts", 0, "");
105
106 pid_t udev_pid = fork();
107 if (udev_pid == 0){
108 execl("/sbin/udevd", "udevd", "--daemon", NULL);
109 perror("udevd");
110 exit(1);
111 }
112 sleep(1);
113 if (fork() == 0){
114 execl("/sbin/udevadm", "udevadm", "trigger", "--action=add", NULL);
115 perror("udevadm trigger");
116 exit(1);
117 }
118 wait(NULL);
119
120 if (fork() == 0){
121 execl("/sbin/udevadm", "udevadm", "settle", NULL);
122 perror("udevadm settle");
123 exit(1);
124 }
125 wait(NULL);
126
127 printf("Filesystems, eudev daemon and /run dir mounted/started successfully\n");
128
129 start_dbus();
130 sleep(1);
131
132 start_service("/usr/sbin/NetworkManager");
133 sleep(1);
134 start_service("/usr/libexec/elogind");
135 sleep(1);
136 start_service("/usr/bin/syslog-ng");
137 start_service("/usr/bin/chronyd");
138 start_service("/usr/bin/crond");
139 start_service("/bin/bash");
140
141 while (1){
142 pid_t pid;
143 int status;
144 while ((pid = waitpid(-1, &status, WNOHANG)) > 0){
145 printf("iinitt: process %d exited\n", pid);
146 }
147 sleep(1);
148 }
149
150 return 0;
151}
poweroff.c added +14
@@ -0,0 +1,14 @@
1// Ilkay Alakay <ilkayxda@aol.com>. Published under GNU GPLv3(.0)
2#include <signal.h>
3#include <unistd.h>
4#include <stdio.h>
5
6int main() {
7 if (geteuid() != 0) {
8 fprintf(stderr, "iinitt: please run this program as root\n");
9 return 1;
10 }
11
12 kill(1, SIGTERM);
13 return 0;
14}
reboot.c added +14
@@ -0,0 +1,14 @@
1// Ilkay Alakay <ilkayxda@aol.com>. Published under GNU GPLv3(.0)
2#include <stdio.h>
3#include <signal.h>
4#include <unistd.h>
5
6int main() {
7 if (geteuid() != 0) {
8 fprintf(stderr, "iinitt: please run this program as root\n");
9 return 1;
10 }
11
12 kill(1, SIGINT);
13 return 0;
14}