modified version of felker's init
This commit is contained in:
@@ -0,0 +1,19 @@
|
|||||||
|
|
||||||
|
SRCS = $(wildcard *.c)
|
||||||
|
OBJS = $(SRCS:%.c=%.o)
|
||||||
|
|
||||||
|
CFLAGS = -O2 -static
|
||||||
|
LDFLAGS = -s
|
||||||
|
|
||||||
|
all: init respawn
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f init respawn $(OBJS)
|
||||||
|
|
||||||
|
$(OBJS):
|
||||||
|
|
||||||
|
%: %.o
|
||||||
|
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $<
|
||||||
|
|
||||||
|
%.o: %.c
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <spawn.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
if (getpid() != 1) return 1;
|
||||||
|
|
||||||
|
sigset_t set, old;
|
||||||
|
sigfillset(&set);
|
||||||
|
sigprocmask(SIG_BLOCK, &set, &old);
|
||||||
|
|
||||||
|
posix_spawnattr_t attr;
|
||||||
|
posix_spawnattr_init(&attr);
|
||||||
|
posix_spawnattr_setsigmask(&attr, &old);
|
||||||
|
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSID|POSIX_SPAWN_SETSIGMASK);
|
||||||
|
|
||||||
|
posix_spawn(0, "/etc/rc", 0, &attr,
|
||||||
|
((char *[]){ "rc", 0 }),
|
||||||
|
((char *[]){ 0 }));
|
||||||
|
|
||||||
|
for (;;) wait(0);
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# /etc/rc — this file will be called directly by /sbin/init
|
||||||
|
# it is safest to use absolute paths here because
|
||||||
|
# /etc/profile is not yet loaded
|
||||||
|
/bin/dmesg -n 1
|
||||||
|
/bin/echo "Mounting required filesystems"
|
||||||
|
/bin/mount -t sysfs sysfs /sys
|
||||||
|
/bin/mount -t proc proc /proc
|
||||||
|
/bin/echo "Mounting fstab filesystems"
|
||||||
|
/bin/mount -a
|
||||||
|
/bin/echo "Remounting root as read/write"
|
||||||
|
/bin/mount / -o remount,rw
|
||||||
|
/bin/echo "Mounting /dev/shm"
|
||||||
|
[ -d /dev/shm ] || /bin/mkdir /dev/shm
|
||||||
|
/bin/mount -t tmpfs tmpfs /dev/shm
|
||||||
|
/bin/echo "Mounting /dev/pts"
|
||||||
|
[ -d /dev/pts ] || /bin/mkdir /dev/pts
|
||||||
|
/bin/mount -t devpts devpts /dev/pts
|
||||||
|
/bin/echo "Mounting /tmp"
|
||||||
|
/bin/mount -t tmpfs tmpfs /tmp
|
||||||
|
/bin/echo "Starting mdev"
|
||||||
|
/bin/echo /sbin/mdev > /proc/sys/kernel/hotplug
|
||||||
|
/sbin/mdev -s
|
||||||
|
/bin/echo "Executing init scripts"
|
||||||
|
for FILE in /etc/rc.d/*; do
|
||||||
|
[ -x /etc/rc.d/$FILE ] && /etc/rc.d/$FILE start
|
||||||
|
done
|
||||||
|
echo "System booted with $(/bin/cat /proc/cmdline)"
|
||||||
|
/bin/echo "Spawning TTY"
|
||||||
|
/sbin/respawn /bin/busybox getty 38400 /dev/tty0
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# /sbin/reboot
|
||||||
|
for FILE in /etc/rc.d/*; do
|
||||||
|
[ -x /etc/rc.d/$FILE ] && /etc/rc.d/$FILE stop
|
||||||
|
done
|
||||||
|
sync
|
||||||
|
mount / -o remount,ro
|
||||||
|
echo b >/proc/sysrq-trigger
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <spawn.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
sigset_t set, old;
|
||||||
|
sigfillset(&set);
|
||||||
|
sigprocmask(SIG_BLOCK, &set, &old);
|
||||||
|
|
||||||
|
posix_spawnattr_t attr;
|
||||||
|
posix_spawnattr_init(&attr);
|
||||||
|
posix_spawnattr_setsigmask(&attr, &old);
|
||||||
|
posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSID|POSIX_SPAWN_SETSIGMASK);
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
extern char **environ;
|
||||||
|
pid_t pid;
|
||||||
|
if (posix_spawn(&pid, argv[1], 0, &attr, argv+1, environ))
|
||||||
|
nanosleep(&(struct timespec){.tv_nsec=100000000}, 0);
|
||||||
|
waitpid(pid, 0, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user