Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
init: more changes
Browse files Browse the repository at this point in the history
More groundwork for new changes.
  • Loading branch information
dylanaraps committed Aug 28, 2021
1 parent f07af7f commit 558b3d6
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 19 deletions.
3 changes: 2 additions & 1 deletion bin/kpow.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ int main (int argc, char *argv[]) {
return 0;

case 'r':
case 's':
reboot(RB_AUTOBOOT);
return 0;

default:
printf("usage: kpow r[eboot]|p[oweroff]\n");
printf("usage: kpow r[eboot]|p[oweroff]|s[hutdown]\n");
return 1;
}
}
4 changes: 4 additions & 0 deletions etc/rc.conf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ CONFIG_INIT=busybox
# is up to the user to spawn gettys, etc.
CONFIG_SERVICE=runit

# (runit and s6 only)
# The service directory to use.
CONVIG_SERVICE_DIR=/var/service

# The device manager to run during the init process. This is killed once boot
# is complete for a supervised version to take its place. Valid values are
# currently 'mdevd', 'mdev' (default) or 'udevd'.
Expand Down
12 changes: 6 additions & 6 deletions lib/init/rc.boot
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ log "Mounting pseudo filesystems..."; {
}

log "Loading rc.conf settings..."; {
[ -f /etc/rc.conf ] && . /etc/rc.conf
load_conf
}

log "Starting device manager..."; {
case ${CONFIG_DEV:=mdev} in
case $CONFIG_DEV in
udevd)
udevd -d
udevadm trigger -c add -t subsystems
Expand Down Expand Up @@ -108,7 +108,7 @@ log "Loading sysctl settings..."; {
}

log "Killing device manager to make way for service..."; {
case ${CONFIG_DEV:=mdev} in
case $CONFIG_DEV in
udevd)
udevadm control --exit
;;
Expand All @@ -135,13 +135,13 @@ IFS=. read -r boot_time _ < /proc/uptime
log "Boot stage completed in ${boot_time}s..."

log "Replacing rc.boot with service manager..."; {
case ${CONFIG_SERVICE:=runit} in
case $CONFIG_SERVICE in
s6)
run_exec s6-svscan /var/service
run_exec s6-svscan "$CONFIG_SERVICE_DIR"
;;

runit)
run_exec respawn /usr/bin/runsvdir -P /var/service 'log: ...............................................................................................................................................................................................................................................................'
run_exec respawn /usr/bin/runsvdir -P "$CONFIG_SERVICE_DIR" 'log: ...............................................................................................................................................................................................................................................................'
;;
esac
}
Expand Down
11 changes: 10 additions & 1 deletion lib/init/rc.lib
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ sos() {
/bin/sh
}

load_conf() {
[ -f /etc/rc.conf ] && . /etc/rc.conf

: "${CONFIG_INIT:=busybox}"
: "${CONFIG_SERVICE:=runit}"
: "${CONFIG_SERVICE_DIR:=/var/service}"
: "${CONFIG_DEV:=mdev}"
}

run_hook() {
for file in /usr/lib/init/rc.d/*."$1" /etc/rc.d/*."$1"; do
[ -f "$file" ] || continue
Expand All @@ -57,7 +66,7 @@ run_hook() {
}

run_exec() {
case ${CONFIG_INIT:=busybox} in
case $CONFIG_INIT in
busybox)
# busybox init does not handle signals until this process ends so we
# cannot use 'exec' here without breaking the reboot and poweroff
Expand Down
1 change: 1 addition & 0 deletions lib/init/rc.reboot
17 changes: 6 additions & 11 deletions lib/init/rc.shutdown
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,23 @@
. /usr/lib/init/rc.lib

log "Loading rc.conf settings..."; {
[ -f /etc/rc.conf ] && . /etc/rc.conf
load_conf
}

log "Running shutdown pre hooks..."; {
run_hook pre.shutdown
}

log "Waiting for services to stop..."; {
: "${CONFIG_SERVICE_DIR:=/var/service}"

case ${CONFIG_SERVICE:=runit} in
runit)
sv force-shutdown /var/service/*
sv force-shutdown "$CONFIG_SERVICE_DIR/"*
;;

s6)
s6-svscanctl -t /var/service
s6-svscanctl -t "$CONFIG_SERVICE_DIR"
;;
esac
}
Expand Down Expand Up @@ -60,11 +62,4 @@ log "Running shutdown post hooks..."; {
run_hook post.shutdown
}

# Run 'kpow' to signal to the kernel that we want to reboot or poweroff the
# system. These will only run when '$1' contains a valid action. When busybox
# init is used for example, this code is ignored entirely as it handles this
# itself.
case $1 in
reboot) kpow r ;;
poweroff) kpow p ;;
esac
kpow "${0##*/rc.}"

0 comments on commit 558b3d6

Please sign in to comment.