minimal init daemon by rich felker, author of musl libc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 }); | |
} |
... explicitly licensing it under the following terms (standard MIT license)
#include <sys/wait.h>
should be added after the third line to stop the warnings.
I concur with ktr in regards to disliking those particular species.
@startredirect wtf r u talking about
i have no words
i have no words
same here.
For those confused, all this code does is:
- Get the process ID of the current process.
- If the process ID is not 1, return 1 (error).
- Fill the signal set with all current signals.
- Block all signals via the
SIG_BLOCK
constant. - If a fork is successful, wait for the child to exit.
- Unblock all signals.
- Set the session ID of the process to the process ID.
- Execute the
/etc/rc
script.
Is it not possible to straight up execute the /etc/rc script? Just by adding init=/etc/rc to the kernel command line?
Just go outside instead of turning on your computer. It uses 0B of disk space
I'm 100% sure this is way too slow. We need to write this in assembly. So that it'll fit in 1 sector of a drive.
I like shell scripts that don't need to be recompiled... A mount -a && /etc/rc
works just fine
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
License?