Skip to content

Instantly share code, notes, and snippets.

Created August 6, 2013 21:15
Star You must be signed in to star a gist
What would you like to do?
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;
sigprocmask(SIG_BLOCK, &set, 0);
if (fork()) for (;;) wait(&status);
sigprocmask(SIG_UNBLOCK, &set, 0);
setpgid(0, 0);
return execve("/etc/rc", (char *[]){ "rc", 0 }, (char *[]){ 0 });
Copy link

oxr463 commented Jan 10, 2020


Copy link

rofl0r commented Jan 11, 2020

... explicitly licensing it under the following terms (standard MIT license)

Copy link

#include <sys/wait.h> should be added after the third line to stop the warnings.

Copy link

I concur with ktr in regards to disliking those particular species.

Copy link

rofl0r commented Jul 24, 2021

@startredirect wtf r u talking about

Copy link

i have no words

Copy link

ghost commented Jun 25, 2022

i have no words

same here.

Copy link

For those confused, all this code does is:

  1. Get the process ID of the current process.
  2. If the process ID is not 1, return 1 (error).
  3. Fill the signal set with all current signals.
  4. Block all signals via the SIG_BLOCK constant.
  5. If a fork is successful, wait for the child to exit.
  6. Unblock all signals.
  7. Set the session ID of the process to the process ID.
  8. Execute the /etc/rc script.

Copy link

Alleop5 commented Apr 3, 2023

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

Copy link

Just go outside instead of turning on your computer. It uses 0B of disk space

Copy link

Alleop5 commented May 17, 2023

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.

Copy link

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