summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--layout/initramfs/bin/.empty0
-rwxr-xr-xlayout/initramfs/init16
-rw-r--r--sub/initramfs/Makefile10
-rw-r--r--sub/initramfs/kill.c55
4 files changed, 77 insertions, 4 deletions
diff --git a/layout/initramfs/bin/.empty b/layout/initramfs/bin/.empty
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/layout/initramfs/bin/.empty
diff --git a/layout/initramfs/init b/layout/initramfs/init
index 7c4c681..e34ff9f 100755
--- a/layout/initramfs/init
+++ b/layout/initramfs/init
@@ -4,7 +4,7 @@
# Since our rootfs shouldn't require a coldplug to be found,
# we could do away with the initramfs, but we leave it as an example.
-/command/export PATH /command
+/command/export PATH /command:/bin
/command/cd /
if { s6-echo "\n initramfs (minimal)\n" }
@@ -12,7 +12,19 @@ if { s6-mount -wt sysfs sys /sys }
if { s6-mount -wt proc proc /proc }
if { s6-mount -wt devtmpfs dev /dev }
-if { pipeline { mdevd-coldplug } mdevd }
+
+piperw 4 5
+background
+{
+ fdclose 4
+ mdevd -D 5
+}
+importas -u MDEVDPID !
+fdclose 5
+if -n { fdmove 0 4 forstdin -x 1 -- i exit 1 } # readiness notif.
+fdclose 4
+if { mdevd-coldplug }
+if { kill $MDEVDPID }
if { s6-mount -rt ext4 /dev/%%PARTITION%%1 /rootfs }
diff --git a/sub/initramfs/Makefile b/sub/initramfs/Makefile
index f175735..debab53 100644
--- a/sub/initramfs/Makefile
+++ b/sub/initramfs/Makefile
@@ -1,11 +1,17 @@
# The initramfs
-INITRAMFS_SKARNET_LIST := cd execlineb export if redirfd s6-echo s6-mount mdevd-coldplug mdevd
+INITRAMFS_SKARNET_LIST := background cd execlineb export fdclose fdmove forstdin if importas piperw pipeline redirfd s6-echo s6-mount mdevd-coldplug mdevd
-$(OUTPUT)/tmp/.lh_initramfs_installed: $(OUTPUT)/tmp/.lh_layout_copied $(OUTPUT)/build-host/.lh_skarnet_installed
+$(OUTPUT)/tmp/.lh_initramfs_installed: $(OUTPUT)/tmp/.lh_layout_copied $(OUTPUT)/build-host/.lh_skarnet_installed $(OUTPUT)/initramfs/bin/kill
for i in $(INITRAMFS_SKARNET_LIST) ; do cp -f -L $(OUTPUT)/rootfs/command/$$i $(OUTPUT)/initramfs/command/$$i ; done
exec setuidgid $(NORMALUSER) touch $@
+$(OUTPUT)/initramfs/bin/kill: $(OUTPUT)/tmp/kill
+ exec cp -f $< $@
+
+$(OUTPUT)/tmp/kill: $(OUTPUT)/build-host/.lh_skarnet_installed sub/initramfs/kill.c $(OUTPUT)/build-host/bin/muslgcc
+ exec setuidgid $(NORMALUSER) $(OUTPUT)/build-host/bin/muslgcc -O2 -pipe -s -static -fomit-frame-pointer -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables -Wa,--noexecstack -fno-stack-protector -ffunction-sections -fdata-sections -Wl,--sort-section=alignment -Wl,--sort-common -Wl,--gc-sections -o $@ -I$(OUTPUT)/rootfs/package/prog/skalibs/include -L$(OUTPUT)/rootfs/package/prog/skalibs/library sub/initramfs/kill.c -lskarnet
+
$(OUTPUT)/initramfs.img.gz: $(OUTPUT)/tmp/.lh_initramfs_installed
cd $(OUTPUT)/initramfs && find . | cpio -o --format=newc > ../initramfs.img && cd .. && rm -f $@ && gzip -9 initramfs.img
diff --git a/sub/initramfs/kill.c b/sub/initramfs/kill.c
new file mode 100644
index 0000000..9279a77
--- /dev/null
+++ b/sub/initramfs/kill.c
@@ -0,0 +1,55 @@
+ /* GPLv2 license. */
+
+#include <skalibs/nonposix.h>
+#include <signal.h>
+#include <skalibs/types.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/sig.h>
+#include <skalibs/nsig.h>
+
+#define USAGE "kill [ -s SIGNAME ] pids..."
+#define dieusage() strerr_dieusage(100, USAGE)
+
+int main (int argc, char const *const *argv)
+{
+ int sig = 15 ;
+ PROG = "kill" ;
+ {
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ int opt = subgetopt_r(argc, argv, "s:", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 's':
+ {
+ sig = sig_number(l.arg) ;
+ if (!sig)
+ {
+ unsigned int u ;
+ if (!uint0_scan(l.arg, &u)) dieusage() ;
+ if (u > SKALIBS_NSIG) dieusage() ;
+ sig = u ;
+ }
+ break ;
+ }
+ default : dieusage() ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ }
+ if (!argc) dieusage() ;
+
+ {
+ pid_t pids[argc] ;
+ for (unsigned int i = 0 ; i < argc ; i++)
+ if (!pid0_scan(argv[i], pids + i)) dieusage() ;
+ for (unsigned int i = 0 ; i < argc ; i++)
+ if (kill(pids[i], sig) < 0)
+ strerr_warnwu2sys("kill pid ", argv[i]) ;
+ }
+ return 0 ;
+}
+