mkports

recipes for building multiple softwares with mk(1)
git clone git://z3bra.org/mkports
Log | Files | Refs

commit fe67dd318fb3685d1aae2e6b554e8656a41fa66f
parent 1f7d868b6c66bf8d4a34ffb424f5bc273b8e6d3d
Author: z3bra <willyatmailoodotorg>
Date:   Mon Jan 18 16:51:08 2016

init: new port

Diffstat:
 init/init.c     | 24 ++++++++++++++++++++++++
 init/mkfile     | 22 ++++++++++++++++++++++
 init/power.subr | 22 ++++++++++++++++++++++
 init/rc         | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/init/init.c b/init/init.c @@ -0,0 +1,24 @@ +#include <signal.h> +#include <unistd.h> +#include <sys/wait.h> + +int main () { + sigset_t set; + pid_t pid; + int c; + + if (getpid () != 1) return 1; + + sigfillset (&set); + sigprocmask (SIG_BLOCK, &set, 0); + + pid = fork (); + if (pid < 0) return 1; + if (pid > 0) for (;;) wait (&c); /* orphans */ + + sigprocmask (SIG_UNBLOCK, &set, 0); + + setsid (); + setpgid (0, 0); + return execve ("/sbin/rc", (char * []){ "go", 0 }, (char * []){ 0 }); +} diff --git a/init/mkfile b/init/mkfile @@ -0,0 +1,22 @@ +pkg = init +ver = 0.1 + +<../config.mk +<../default.mk + +build:QV: fetch patch + mkdir -p $pkg-$ver + cp init.c $pkg-$ver/init.c + cd $pkg-$ver + $CC $CFLAGS init.c $LDFLAGS -o init + +install:QV: build + mkdir -p $destdir/sbin + mkdir -p $destdir/libexec + cp $pkg-$ver/init $destdir/sbin/init + cp rc $destdir/sbin/rc + cp power.subr $destdir/libexec/power.subr + chmod 750 $destdir/sbin/rc + chmod 750 $destdir/libexec/power.subr + ln -sf /libexec/power.subr $destdir/sbin/reboot + ln -sf /libexec/power.subr $destdir/sbin/poweroff diff --git a/init/power.subr b/init/power.subr @@ -0,0 +1,22 @@ +#!/bin/sh + +echo system is going down + +echo remounting / read-only +/bin/mount -o remount,ro / + +echo unmounting filesystems +/bin/umount -a + +echo terminating all processes +/bin/killall5 -s TERM +/bin/sleep 2 +/bin/killall5 -s KILL + +/bin/sync +wait + +case $(basename $0) in + reboot) /bin/halt -r ;; + poweroff) /bin/halt -p ;; +esac+ \ No newline at end of file diff --git a/init/rc b/init/rc @@ -0,0 +1,51 @@ +#!/bin/sh + +umask 022 + +echo +echo +echo booting your setup +echo +echo + +/bin/ctrlaltdel -s + +echo mounting virtual filesystem +/bin/mount -n -t proc -o nosuid,noexec,nodev proc /proc +/bin/mount -n -t sysfs -o nosuid,noexec,nodev sys /sys +/bin/mount -n -t tmpfs -o nosuid,mode=0755 dev /dev + +/bin/mkdir -p /dev/pts /dev/shm +/bin/mount -n -t devpts -o gid=5,mode=0620 devpts /dev/pts +/bin/mount -n -t tpmfs -o mode=1777,nosuid,nodev shm /dev/shm + +echo remouting / read-only +/bin/mount -o remount,ro / + +echo running smdev +/bin/smdev -s + +echo setting smdev as the kernel hotplug +echo /bin/smdev > /proc/sys/kernel/hotplug + +/bin/ln -sf /proc/self/fd /dev/fd +/bin/ln -sf /proc/self/fd/0 /dev/stdin +/bin/ln -sf /proc/self/fd/1 /dev/stdout +/bin/ln -sf /proc/self/fd/2 /dev/stderr + +echo mounting filesystem from fstab +/bin/mount -a +ln -sf /proc/mounts /etc/mtab + +echo naming machine \$distro +/bin/hostname \$distro + +> /var/run/utmp + +echo remounting / read-write +/bin/mount -o remount,rw / + +echo +/bin/respawn /bin/getty /dev/tty0 & +/bin/respawn /bin/getty /dev/tty1 & +/bin/respawn /bin/getty /dev/tty2 &