From a3437967a2ae4730ba638cc80328055e9805e7c9 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 12 Apr 2018 06:40:39 +0200 Subject: [PATCH] Rely on PATH variable for running init programs Signed-off-by: David Oberhollenzer --- .gitignore | 12 ------------ configure.ac | 12 ------------ initd/runlst.c | 4 +--- scripts/Makemodule.am | 2 ++ scripts/devfs.sh.in | 26 ++++++++++++------------- scripts/{overlay.sh.in => overlay.sh} | 6 +++--- scripts/{trymount.sh.in => trymount.sh} | 2 +- services/Makemodule.am | 5 ++++- services/{agetty.in => agetty} | 2 +- services/{hostname.in => hostname} | 2 +- services/{hwclock.in => hwclock} | 2 +- services/{loopback.in => loopback} | 4 ++-- services/procfs.in | 2 +- services/{reboot.in => reboot} | 2 +- services/{shutdown.in => shutdown} | 2 +- services/sigterm.in | 2 +- services/{sync.in => sync} | 2 +- services/{sysctl.in => sysctl} | 2 +- services/sysfs.in | 2 +- services/{tmpfs.in => tmpfs} | 2 +- services/tmpfsrun | 11 +++++++++++ services/tmpfsrun.in | 11 ----------- services/tmpfsvar.in | 10 +++++----- 23 files changed, 53 insertions(+), 74 deletions(-) rename scripts/{overlay.sh.in => overlay.sh} (70%) rename scripts/{trymount.sh.in => trymount.sh} (52%) rename services/{agetty.in => agetty} (69%) rename services/{hostname.in => hostname} (63%) rename services/{hwclock.in => hwclock} (65%) rename services/{loopback.in => loopback} (59%) rename services/{reboot.in => reboot} (70%) rename services/{shutdown.in => shutdown} (71%) rename services/{sync.in => sync} (78%) rename services/{sysctl.in => sysctl} (75%) rename services/{tmpfs.in => tmpfs} (57%) create mode 100644 services/tmpfsrun delete mode 100644 services/tmpfsrun.in diff --git a/.gitignore b/.gitignore index 3e66c23..abc49fd 100644 --- a/.gitignore +++ b/.gitignore @@ -20,26 +20,14 @@ reboot shutdown killall5 -services/agetty -services/hostname -services/loopback -services/sysctl -services/hwclock -services/shutdown -services/reboot services/sigkill services/sigterm -services/sync services/devfs services/procfs services/sysfs -services/tmpfs -services/tmpfsrun services/tmpfsvar services/rootusr scripts/devfs.sh -scripts/overlay.sh -scripts/trymount.sh etc/initd.env diff --git a/configure.ac b/configure.ac index 5afbfce..761686e 100644 --- a/configure.ac +++ b/configure.ac @@ -55,26 +55,14 @@ AC_DEFINE_DIR(BINPATH, bindir, [Fully evaluated bin directory]) AC_DEFINE_DIR(SBINPATH, sbindir, [Fully evaluated sbin directory]) AC_DEFINE_DIR(ETCPATH, sysconfdir, [Fulle evaluated etc directory]) -AC_CONFIG_FILES([services/agetty]) -AC_CONFIG_FILES([services/hostname]) -AC_CONFIG_FILES([services/loopback]) -AC_CONFIG_FILES([services/sysctl]) -AC_CONFIG_FILES([services/hwclock]) -AC_CONFIG_FILES([services/reboot]) -AC_CONFIG_FILES([services/shutdown]) AC_CONFIG_FILES([services/sigkill]) AC_CONFIG_FILES([services/sigterm]) -AC_CONFIG_FILES([services/sync]) AC_CONFIG_FILES([services/sysfs]) AC_CONFIG_FILES([services/devfs]) AC_CONFIG_FILES([services/procfs]) -AC_CONFIG_FILES([services/tmpfs]) -AC_CONFIG_FILES([services/tmpfsrun]) AC_CONFIG_FILES([services/tmpfsvar]) AC_CONFIG_FILES([services/rootusr]) AC_CONFIG_FILES([scripts/devfs.sh]) -AC_CONFIG_FILES([scripts/overlay.sh]) -AC_CONFIG_FILES([scripts/trymount.sh]) AC_CONFIG_FILES([etc/initd.env]) AC_OUTPUT([Makefile]) diff --git a/initd/runlst.c b/initd/runlst.c index 933daeb..d1311a4 100644 --- a/initd/runlst.c +++ b/initd/runlst.c @@ -24,8 +24,6 @@ #include "init.h" -extern char **environ; - static int child_setup(const char *ctty) { sigset_t mask; @@ -65,7 +63,7 @@ static NORETURN void argv_exec(exec_t *e) argv[i] = ptr; argv[i] = NULL; - execve(argv[0], argv, environ); + execvp(argv[0], argv); perror(argv[0]); exit(EXIT_FAILURE); } diff --git a/scripts/Makemodule.am b/scripts/Makemodule.am index 6832788..dd3fa0b 100644 --- a/scripts/Makemodule.am +++ b/scripts/Makemodule.am @@ -3,3 +3,5 @@ helper_SCRIPTS += scripts/devfs.sh scripts/trymount.sh if PYGOSCFG helper_SCRIPTS += scripts/overlay.sh endif + +EXTRA_DIST += scripts/trymount.sh scripts/overlay.sh diff --git a/scripts/devfs.sh.in b/scripts/devfs.sh.in index a39d3ea..af002f6 100644 --- a/scripts/devfs.sh.in +++ b/scripts/devfs.sh.in @@ -1,20 +1,20 @@ #!/bin/sh -@SBINPATH@/mount -t devtmpfs none /dev +mount -t devtmpfs none /dev -[ -c /dev/console ] || @SBINPATH@/mknod -m 600 /dev/console c 5 1 -[ -c /dev/tty ] || @SBINPATH@/mknod -m 666 /dev/tty c 5 0 -[ -c /dev/null ] || @SBINPATH@/mknod -m 666 /dev/null c 1 3 -[ -c /dev/kmsg ] || @SBINPATH@/mknod -m 660 /dev/kmsg c 1 11 -[ -e /dev/fd ] || @BINPATH@/ln -snf /proc/self/fd /dev/fd -[ -e /dev/stdin ] || @BINPATH@/ln -snf /proc/self/fd/0 /dev/stdin -[ -e /dev/stdout ] || @BINPATH@/ln -snf /proc/self/fd/1 /dev/stdout -[ -e /dev/stderr ] || @BINPATH@/ln -snf /proc/self/fd/2 /dev/stderr -[ -e /proc/kcore ] && @BINPATH@/ln -snf /proc/kcore /dev/core +[ -c /dev/console ] || mknod -m 600 /dev/console c 5 1 +[ -c /dev/tty ] || mknod -m 666 /dev/tty c 5 0 +[ -c /dev/null ] || mknod -m 666 /dev/null c 1 3 +[ -c /dev/kmsg ] || mknod -m 660 /dev/kmsg c 1 11 +[ -e /dev/fd ] || ln -snf /proc/self/fd /dev/fd +[ -e /dev/stdin ] || ln -snf /proc/self/fd/0 /dev/stdin +[ -e /dev/stdout ] || ln -snf /proc/self/fd/1 /dev/stdout +[ -e /dev/stderr ] || ln -snf /proc/self/fd/2 /dev/stderr +[ -e /proc/kcore ] && ln -snf /proc/kcore /dev/core -@BINPATH@/mkdir -p /dev/mqueue -m 1777 -@BINPATH@/mkdir -p /dev/pts -m 0755 -@BINPATH@/mkdir -p /dev/shm -m 1777 +mkdir -p /dev/mqueue -m 1777 +mkdir -p /dev/pts -m 0755 +mkdir -p /dev/shm -m 1777 @SCRIPTDIR@/trymount.sh "/dev/mqueue" "mqueue" "noexec,nosuid,nodev" @SCRIPTDIR@/trymount.sh "/dev/pts" "devpts" "noexec,nosuid,gid=5,mode=0620" diff --git a/scripts/overlay.sh.in b/scripts/overlay.sh similarity index 70% rename from scripts/overlay.sh.in rename to scripts/overlay.sh index b53eea7..090671c 100644 --- a/scripts/overlay.sh.in +++ b/scripts/overlay.sh @@ -11,11 +11,11 @@ fi if [ -d "$lower" ]; then if [ -d "$upper" ]; then - @BINPATH@/mkdir -p "$work" - @SBINPATH@/mount -t overlay overlay \ + mkdir -p "$work" + mount -t overlay overlay \ -olowerdir=${lower},upperdir=${upper},workdir=${work} \ ${target} else - @SBINPATH@/mount --bind "$lower" "$target" + mount --bind "$lower" "$target" fi fi diff --git a/scripts/trymount.sh.in b/scripts/trymount.sh similarity index 52% rename from scripts/trymount.sh.in rename to scripts/trymount.sh index a382792..9be77f6 100644 --- a/scripts/trymount.sh.in +++ b/scripts/trymount.sh @@ -1,7 +1,7 @@ #!/bin/sh if [ -d "$1" ]; then - if @BINPATH@/grep -qsE "[[:space:]]+$2$" "/proc/filesystems"; then + if grep -qsE "[[:space:]]+$2$" "/proc/filesystems"; then mount -n -t "$2" -o "$3" "$2" "$1" fi fi diff --git a/services/Makemodule.am b/services/Makemodule.am index 5f3c1bb..3c714a6 100644 --- a/services/Makemodule.am +++ b/services/Makemodule.am @@ -10,4 +10,7 @@ if PYGOSCFG init_DATA += services/rootusr services/tmpfsrun services/tmpfsvar endif -EXTRA_DIST += services/sysinit services/vfs +EXTRA_DIST += services/sysinit services/vfs services/agetty services/hostname +EXTRA_DIST += services/hwclock services/loopback services/reboot +EXTRA_DIST += services/shutdown services/sync services/sysctl services/tmpfs +EXTRA_DIST += services/tmpfsrun diff --git a/services/agetty.in b/services/agetty similarity index 69% rename from services/agetty.in rename to services/agetty index c4f78ad..b4dc70d 100644 --- a/services/agetty.in +++ b/services/agetty @@ -1,5 +1,5 @@ description agetty on %0 -exec "@SBINPATH@/agetty" %0 linux +exec agetty %0 linux type respawn target boot after sysinit diff --git a/services/hostname.in b/services/hostname similarity index 63% rename from services/hostname.in rename to services/hostname index 678e07e..d0daa23 100644 --- a/services/hostname.in +++ b/services/hostname @@ -1,5 +1,5 @@ description reload hostname -exec "@BINPATH@/hostname" --file /etc/hostname +exec hostname --file /etc/hostname type wait target boot before sysinit diff --git a/services/hwclock.in b/services/hwclock similarity index 65% rename from services/hwclock.in rename to services/hwclock index af3a4e4..eeafe8b 100644 --- a/services/hwclock.in +++ b/services/hwclock @@ -1,5 +1,5 @@ description restore time from RTC -exec "@SBINPATH@/hwclock" --hctosys --utc +exec hwclock --hctosys --utc type wait target boot before sysinit diff --git a/services/loopback.in b/services/loopback similarity index 59% rename from services/loopback.in rename to services/loopback index 9e41ae1..5a77a6f 100644 --- a/services/loopback.in +++ b/services/loopback @@ -5,6 +5,6 @@ before sysinit after hwclock hostname vfs exec { - "@SBINPATH@/ip" addr add 127.0.0.1/8 dev lo brd + - "@SBINPATH@/ip" link set lo up + ip addr add 127.0.0.1/8 dev lo brd + + ip link set lo up } diff --git a/services/procfs.in b/services/procfs.in index 9124792..8c0743b 100644 --- a/services/procfs.in +++ b/services/procfs.in @@ -4,6 +4,6 @@ target boot before vfs exec { - "@SBINPATH@/mount" -t proc proc /proc + mount -t proc proc /proc "@SCRIPTDIR@/trymount.sh" /proc/sys/fs/binfmt_misc binfmt_misc nodev,noexec,nosuid } diff --git a/services/reboot.in b/services/reboot similarity index 70% rename from services/reboot.in rename to services/reboot index da11e2a..65a8eac 100644 --- a/services/reboot.in +++ b/services/reboot @@ -1,5 +1,5 @@ description system reboot -exec "@SBINPATH@/shutdown" -nrf +exec shutdown -nrf type wait target reboot after sync sigkill sigterm diff --git a/services/shutdown.in b/services/shutdown similarity index 71% rename from services/shutdown.in rename to services/shutdown index 6c28621..679ffbd 100644 --- a/services/shutdown.in +++ b/services/shutdown @@ -1,5 +1,5 @@ description system shutdown -exec "@SBINPATH@/shutdown" -npf +exec shutdown -npf type wait target shutdown after sync sigkill sigterm diff --git a/services/sigterm.in b/services/sigterm.in index cb408f2..7e77fba 100644 --- a/services/sigterm.in +++ b/services/sigterm.in @@ -5,5 +5,5 @@ before sigkill sync reboot shutdown exec { "@SCRIPTDIR@/killall5" 15 - "@BINPATH@/sleep" 5 + sleep 5 } diff --git a/services/sync.in b/services/sync similarity index 78% rename from services/sync.in rename to services/sync index 7f02287..d7217f9 100644 --- a/services/sync.in +++ b/services/sync @@ -1,5 +1,5 @@ description sync -exec "@BINPATH@/sync" +exec sync type wait target %0 after sigkill sigterm diff --git a/services/sysctl.in b/services/sysctl similarity index 75% rename from services/sysctl.in rename to services/sysctl index e2e6eaa..a5ee62b 100755 --- a/services/sysctl.in +++ b/services/sysctl @@ -1,5 +1,5 @@ description configure kernel paramters -exec "@SBINPATH@/sysctl" --system +exec sysctl --system type wait target boot before sysinit diff --git a/services/sysfs.in b/services/sysfs.in index 21938fb..8eebd0a 100644 --- a/services/sysfs.in +++ b/services/sysfs.in @@ -5,7 +5,7 @@ after procfs before vfs exec { - "@SBINPATH@/mount" -t sysfs sysfs /sys + mount -t sysfs sysfs /sys "@SCRIPTDIR@/trymount.sh" /sys/kernel/security securityfs nodev,noexec,nosuid "@SCRIPTDIR@/trymount.sh" /sys/kernel/config configfs nodev,noexec,nosuid "@SCRIPTDIR@/trymount.sh" /sys/fs/fuse/connections fusectl nodev,noexec,nosuid diff --git a/services/tmpfs.in b/services/tmpfs similarity index 57% rename from services/tmpfs.in rename to services/tmpfs index 1aa48cc..411a42b 100644 --- a/services/tmpfs.in +++ b/services/tmpfs @@ -2,4 +2,4 @@ description "mount /tmp" type wait target boot before vfs -exec "@SBINPATH@/mount" -t tmpfs none /tmp +exec mount -t tmpfs none /tmp diff --git a/services/tmpfsrun b/services/tmpfsrun new file mode 100644 index 0000000..07dbd0a --- /dev/null +++ b/services/tmpfsrun @@ -0,0 +1,11 @@ +description "mount /run" +type wait +target boot +before vfs +after tmpfsvar +exec { + mount -t tmpfs none /run + mkdir /run/lock -m 0755 + ln -s /run /var/run + ln -s /run/lock /var/lock +} diff --git a/services/tmpfsrun.in b/services/tmpfsrun.in deleted file mode 100644 index c88a914..0000000 --- a/services/tmpfsrun.in +++ /dev/null @@ -1,11 +0,0 @@ -description "mount /run" -type wait -target boot -before vfs -after tmpfsvar -exec { - "@SBINPATH@/mount" -t tmpfs none /run - "@BINPATH@/mkdir" /run/lock -m 0755 - "@BINPATH@/ln" -s /run /var/run - "@BINPATH@/ln" -s /run/lock /var/lock -} diff --git a/services/tmpfsvar.in b/services/tmpfsvar.in index be7e563..5f45ecd 100644 --- a/services/tmpfsvar.in +++ b/services/tmpfsvar.in @@ -3,10 +3,10 @@ type wait target boot before vfs exec { - "@SBINPATH@/mount" -t tmpfs none /var - "@BINPATH@/mkdir" /var/log -m 0755 - "@BINPATH@/mkdir" /var/spool -m 0755 - "@BINPATH@/mkdir" /var/lib -m 0755 - "@BINPATH@/mkdir" /var/tmp -m 0755 + mount -t tmpfs none /var + mkdir /var/log -m 0755 + mkdir /var/spool -m 0755 + mkdir /var/lib -m 0755 + mkdir /var/tmp -m 0755 "@SCRIPTDIR@/overlay.sh" var_lib /var/lib }