Skip to content

Instantly share code, notes, and snippets.

@rofl0r
Created August 6, 2013 21:15
Star You must be signed in to star a gist
Save rofl0r/6168719 to your computer and use it in GitHub Desktop.
minimal init daemon by rich felker, author of musl libc
#define _XOPEN_SOURCE 700
#include <signal.h>
#include <unistd.h>
int main()
{
sigset_t set;
int status;
if (getpid() != 1) return 1;
sigfillset(&set);
sigprocmask(SIG_BLOCK, &set, 0);
if (fork()) for (;;) wait(&status);
sigprocmask(SIG_UNBLOCK, &set, 0);
setsid();
setpgid(0, 0);
return execve("/etc/rc", (char *[]){ "rc", 0 }, (char *[]){ 0 });
}
@yurayko
Copy link

yurayko commented Nov 25, 2023

Is it not possible to straight up execute the /etc/rc script? Just by adding init=/etc/rc to the kernel command line?

You need a always running daemon, who will be reap a zombie. It is single work for init.
If you redirect this job to /etc/rc, you got a systemd again.
You cannot start an another daemon from /etc/rc for this. Zombie go to process with PID 1. /etc/rc have a PID 1 in your case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment