diff options
Diffstat (limited to 'src/initrd/halt.montecarlo')
-rwxr-xr-x | src/initrd/halt.montecarlo | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/initrd/halt.montecarlo b/src/initrd/halt.montecarlo new file mode 100755 index 0000000..67dac17 --- /dev/null +++ b/src/initrd/halt.montecarlo | |||
@@ -0,0 +1,39 @@ | |||
1 | #!/bin/bash | ||
2 | |||
3 | cmd=${0##*/} | ||
4 | dashf= | ||
5 | for arg in "$@"; do | ||
6 | case "$arg" in -*f*) dashf=1 ;; esac | ||
7 | case "$arg" in -*p*) [ "$cmd" = halt ] && cmd=poweroff ;; esac | ||
8 | done | ||
9 | |||
10 | [ "$dashf" ] || exec -a "$0" /sbin/halt.distrib "$@" | ||
11 | |||
12 | read pids < /run/sendsigs.omit.d/samizdat | ||
13 | for p in $pids; do | ||
14 | if [ -e /proc/$p/root -a ! /proc/$p/root -ef / ]; then | ||
15 | initramfs=/proc/$p/root | ||
16 | break | ||
17 | fi | ||
18 | done | ||
19 | |||
20 | panic() | ||
21 | { | ||
22 | set -x | ||
23 | sync | ||
24 | exec -a "$0" /sbin/halt.distrib "$@" | ||
25 | } | ||
26 | |||
27 | [ "$initramfs" ] || panic | ||
28 | |||
29 | cp /sbin/init $initramfs/telinit | ||
30 | |||
31 | # Apparently, linux does not allow a direct bind mount of a file on | ||
32 | # the initramfs. Therefore, copy the file from the initramfs and bind | ||
33 | # mount the copy. | ||
34 | |||
35 | mount -o remount,exec /run | ||
36 | cp $initramfs/lib/samizdat/init.shutdown /run/ && mount --bind /run/init.shutdown /sbin/init || panic | ||
37 | |||
38 | echo $cmd -f > $initramfs/halt | ||
39 | $initramfs/telinit u | ||