tinit: new port - mkports - recipes for building multiple softwares with mk(1)
 (HTM) git clone git://z3bra.org/mkports
 (DIR) Log
 (DIR) Files
 (DIR) Refs
       ---
 (DIR) commit fe67dd318fb3685d1aae2e6b554e8656a41fa66f
 (DIR) parent 1f7d868b6c66bf8d4a34ffb424f5bc273b8e6d3d
 (HTM) Author: z3bra <willyatmailoodotorg>
       Date:   Mon, 18 Jan 2016 16:51:08 +0100
       
       init: new port
       
       Diffstat:
         A init/init.c                         |      24 ++++++++++++++++++++++++
         A init/mkfile                         |      22 ++++++++++++++++++++++
         A init/power.subr                     |      23 +++++++++++++++++++++++
         A init/rc                             |      51 +++++++++++++++++++++++++++++++
       
       4 files changed, 120 insertions(+), 0 deletions(-)
       ---
 (DIR) diff --git a/init/init.c b/init/init.c
       t@@ -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 });
       +}
 (DIR) diff --git a/init/mkfile b/init/mkfile
       t@@ -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
 (DIR) diff --git a/init/power.subr b/init/power.subr
       t@@ -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
 (DIR) diff --git a/init/rc b/init/rc
       t@@ -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 &