From a3437967a2ae4730ba638cc80328055e9805e7c9 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Thu, 12 Apr 2018 06:40:39 +0200 Subject: 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 | 21 +++++++++++++++++++++ scripts/overlay.sh.in | 21 --------------------- scripts/trymount.sh | 7 +++++++ scripts/trymount.sh.in | 7 ------- services/Makemodule.am | 5 ++++- services/agetty | 6 ++++++ services/agetty.in | 6 ------ services/hostname | 6 ++++++ services/hostname.in | 6 ------ services/hwclock | 6 ++++++ services/hwclock.in | 6 ------ services/loopback | 10 ++++++++++ services/loopback.in | 10 ---------- services/procfs.in | 2 +- services/reboot | 5 +++++ services/reboot.in | 5 ----- services/shutdown | 5 +++++ services/shutdown.in | 5 ----- services/sigterm.in | 2 +- services/sync | 6 ++++++ services/sync.in | 6 ------ services/sysctl | 6 ++++++ services/sysctl.in | 6 ------ services/sysfs.in | 2 +- services/tmpfs | 5 +++++ services/tmpfs.in | 5 ----- services/tmpfsrun | 11 +++++++++++ services/tmpfsrun.in | 11 ----------- services/tmpfsvar.in | 10 +++++----- 34 files changed, 122 insertions(+), 143 deletions(-) create mode 100644 scripts/overlay.sh delete mode 100644 scripts/overlay.sh.in create mode 100644 scripts/trymount.sh delete mode 100644 scripts/trymount.sh.in create mode 100644 services/agetty delete mode 100644 services/agetty.in create mode 100644 services/hostname delete mode 100644 services/hostname.in create mode 100644 services/hwclock delete mode 100644 services/hwclock.in create mode 100644 services/loopback delete mode 100644 services/loopback.in create mode 100644 services/reboot delete mode 100644 services/reboot.in create mode 100644 services/shutdown delete mode 100644 services/shutdown.in create mode 100644 services/sync delete mode 100644 services/sync.in create mode 100755 services/sysctl delete mode 100755 services/sysctl.in create mode 100644 services/tmpfs delete mode 100644 services/tmpfs.in 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 b/scripts/overlay.sh new file mode 100644 index 0000000..090671c --- /dev/null +++ b/scripts/overlay.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +lower=/cfg/preserve/${1} +upper=/cfg/overlay/${1} +work=/cfg/overlay/${1}_work +target=${2} + +if [ ! -d "$target" ]; then + exit +fi + +if [ -d "$lower" ]; then + if [ -d "$upper" ]; then + mkdir -p "$work" + mount -t overlay overlay \ + -olowerdir=${lower},upperdir=${upper},workdir=${work} \ + ${target} + else + mount --bind "$lower" "$target" + fi +fi diff --git a/scripts/overlay.sh.in b/scripts/overlay.sh.in deleted file mode 100644 index b53eea7..0000000 --- a/scripts/overlay.sh.in +++ /dev/null @@ -1,21 +0,0 @@ -#!/bin/sh - -lower=/cfg/preserve/${1} -upper=/cfg/overlay/${1} -work=/cfg/overlay/${1}_work -target=${2} - -if [ ! -d "$target" ]; then - exit -fi - -if [ -d "$lower" ]; then - if [ -d "$upper" ]; then - @BINPATH@/mkdir -p "$work" - @SBINPATH@/mount -t overlay overlay \ - -olowerdir=${lower},upperdir=${upper},workdir=${work} \ - ${target} - else - @SBINPATH@/mount --bind "$lower" "$target" - fi -fi diff --git a/scripts/trymount.sh b/scripts/trymount.sh new file mode 100644 index 0000000..9be77f6 --- /dev/null +++ b/scripts/trymount.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +if [ -d "$1" ]; then + if grep -qsE "[[:space:]]+$2$" "/proc/filesystems"; then + mount -n -t "$2" -o "$3" "$2" "$1" + fi +fi diff --git a/scripts/trymount.sh.in b/scripts/trymount.sh.in deleted file mode 100644 index a382792..0000000 --- a/scripts/trymount.sh.in +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh - -if [ -d "$1" ]; then - if @BINPATH@/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 b/services/agetty new file mode 100644 index 0000000..b4dc70d --- /dev/null +++ b/services/agetty @@ -0,0 +1,6 @@ +description agetty on %0 +exec agetty %0 linux +type respawn +target boot +after sysinit +tty "/dev/%0" diff --git a/services/agetty.in b/services/agetty.in deleted file mode 100644 index c4f78ad..0000000 --- a/services/agetty.in +++ /dev/null @@ -1,6 +0,0 @@ -description agetty on %0 -exec "@SBINPATH@/agetty" %0 linux -type respawn -target boot -after sysinit -tty "/dev/%0" diff --git a/services/hostname b/services/hostname new file mode 100644 index 0000000..d0daa23 --- /dev/null +++ b/services/hostname @@ -0,0 +1,6 @@ +description reload hostname +exec hostname --file /etc/hostname +type wait +target boot +before sysinit +after hwclock vfs diff --git a/services/hostname.in b/services/hostname.in deleted file mode 100644 index 678e07e..0000000 --- a/services/hostname.in +++ /dev/null @@ -1,6 +0,0 @@ -description reload hostname -exec "@BINPATH@/hostname" --file /etc/hostname -type wait -target boot -before sysinit -after hwclock vfs diff --git a/services/hwclock b/services/hwclock new file mode 100644 index 0000000..eeafe8b --- /dev/null +++ b/services/hwclock @@ -0,0 +1,6 @@ +description restore time from RTC +exec hwclock --hctosys --utc +type wait +target boot +before sysinit +after vfs diff --git a/services/hwclock.in b/services/hwclock.in deleted file mode 100644 index af3a4e4..0000000 --- a/services/hwclock.in +++ /dev/null @@ -1,6 +0,0 @@ -description restore time from RTC -exec "@SBINPATH@/hwclock" --hctosys --utc -type wait -target boot -before sysinit -after vfs diff --git a/services/loopback b/services/loopback new file mode 100644 index 0000000..5a77a6f --- /dev/null +++ b/services/loopback @@ -0,0 +1,10 @@ +description configure network loopback device +type wait +target boot +before sysinit +after hwclock hostname vfs + +exec { + ip addr add 127.0.0.1/8 dev lo brd + + ip link set lo up +} diff --git a/services/loopback.in b/services/loopback.in deleted file mode 100644 index 9e41ae1..0000000 --- a/services/loopback.in +++ /dev/null @@ -1,10 +0,0 @@ -description configure network loopback device -type wait -target boot -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 -} 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 b/services/reboot new file mode 100644 index 0000000..65a8eac --- /dev/null +++ b/services/reboot @@ -0,0 +1,5 @@ +description system reboot +exec shutdown -nrf +type wait +target reboot +after sync sigkill sigterm diff --git a/services/reboot.in b/services/reboot.in deleted file mode 100644 index da11e2a..0000000 --- a/services/reboot.in +++ /dev/null @@ -1,5 +0,0 @@ -description system reboot -exec "@SBINPATH@/shutdown" -nrf -type wait -target reboot -after sync sigkill sigterm diff --git a/services/shutdown b/services/shutdown new file mode 100644 index 0000000..679ffbd --- /dev/null +++ b/services/shutdown @@ -0,0 +1,5 @@ +description system shutdown +exec shutdown -npf +type wait +target shutdown +after sync sigkill sigterm diff --git a/services/shutdown.in b/services/shutdown.in deleted file mode 100644 index 6c28621..0000000 --- a/services/shutdown.in +++ /dev/null @@ -1,5 +0,0 @@ -description system shutdown -exec "@SBINPATH@/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 b/services/sync new file mode 100644 index 0000000..d7217f9 --- /dev/null +++ b/services/sync @@ -0,0 +1,6 @@ +description sync +exec sync +type wait +target %0 +after sigkill sigterm +before reboot shutdown diff --git a/services/sync.in b/services/sync.in deleted file mode 100644 index 7f02287..0000000 --- a/services/sync.in +++ /dev/null @@ -1,6 +0,0 @@ -description sync -exec "@BINPATH@/sync" -type wait -target %0 -after sigkill sigterm -before reboot shutdown diff --git a/services/sysctl b/services/sysctl new file mode 100755 index 0000000..a5ee62b --- /dev/null +++ b/services/sysctl @@ -0,0 +1,6 @@ +description configure kernel paramters +exec sysctl --system +type wait +target boot +before sysinit +after hwclock hostname vfs diff --git a/services/sysctl.in b/services/sysctl.in deleted file mode 100755 index e2e6eaa..0000000 --- a/services/sysctl.in +++ /dev/null @@ -1,6 +0,0 @@ -description configure kernel paramters -exec "@SBINPATH@/sysctl" --system -type wait -target boot -before sysinit -after hwclock hostname vfs 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 b/services/tmpfs new file mode 100644 index 0000000..411a42b --- /dev/null +++ b/services/tmpfs @@ -0,0 +1,5 @@ +description "mount /tmp" +type wait +target boot +before vfs +exec mount -t tmpfs none /tmp diff --git a/services/tmpfs.in b/services/tmpfs.in deleted file mode 100644 index 1aa48cc..0000000 --- a/services/tmpfs.in +++ /dev/null @@ -1,5 +0,0 @@ -description "mount /tmp" -type wait -target boot -before vfs -exec "@SBINPATH@/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 } -- cgit v1.2.3