summaryrefslogtreecommitdiff
path: root/src/initrd/halt.montecarlo
blob: 67dac17b622da1f0ad545b89c1c7d65dff21c467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/bin/bash

cmd=${0##*/}
dashf=
for arg in "$@"; do
  case "$arg" in -*f*) dashf=1 ;; esac
  case "$arg" in -*p*) [ "$cmd" = halt ] && cmd=poweroff ;; esac
done

[ "$dashf" ] || exec -a "$0" /sbin/halt.distrib "$@"

read pids < /run/sendsigs.omit.d/samizdat
for p in $pids; do
  if [ -e /proc/$p/root -a ! /proc/$p/root -ef / ]; then
    initramfs=/proc/$p/root
    break
  fi
done

panic()
{
  set -x
  sync
  exec -a "$0" /sbin/halt.distrib "$@"
}

[ "$initramfs" ] || panic

cp /sbin/init $initramfs/telinit

# Apparently, linux does not allow a direct bind mount of a file on
# the initramfs.  Therefore, copy the file from the initramfs and bind
# mount the copy.

mount -o remount,exec /run
cp $initramfs/lib/samizdat/init.shutdown /run/ && mount --bind /run/init.shutdown /sbin/init || panic

echo $cmd -f > $initramfs/halt
$initramfs/telinit u