summaryrefslogtreecommitdiff
path: root/src/initrd/halt.montecarlo
diff options
context:
space:
mode:
Diffstat (limited to 'src/initrd/halt.montecarlo')
-rwxr-xr-xsrc/initrd/halt.montecarlo39
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
3cmd=${0##*/}
4dashf=
5for arg in "$@"; do
6 case "$arg" in -*f*) dashf=1 ;; esac
7 case "$arg" in -*p*) [ "$cmd" = halt ] && cmd=poweroff ;; esac
8done
9
10[ "$dashf" ] || exec -a "$0" /sbin/halt.distrib "$@"
11
12read pids < /run/sendsigs.omit.d/samizdat
13for 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
18done
19
20panic()
21{
22 set -x
23 sync
24 exec -a "$0" /sbin/halt.distrib "$@"
25}
26
27[ "$initramfs" ] || panic
28
29cp /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
35mount -o remount,exec /run
36cp $initramfs/lib/samizdat/init.shutdown /run/ && mount --bind /run/init.shutdown /sbin/init || panic
37
38echo $cmd -f > $initramfs/halt
39$initramfs/telinit u