/
rootdelayd
executable file
·114 lines (82 loc) · 2 KB
/
rootdelayd
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#!/bin/bash -efu
. shell-error
. shell-locks
. initrd-sh-functions
message_time=1
disabled="/.initrd/rootdelay/disabled"
period=1
while :; do
if [ -e "$disabled" ] || rootdelay_paused; then
sleep $period
continue
fi
if [ -z "${__initrd_initenv-}" ] && [ -f /.initrd/initenv ]; then
fd_rlock 90 /.initrd/initenv
. /.initrd/initenv
fd_unlock 90
if [ -z "${__initrd_initenv-}" ]; then
# Waiting for cmdline service
sleep 0.2
continue
fi
[ "${RDLOG-}" != 'console' ] &&
logfile=/var/log/$PROG.log ||
logfile=/dev/console
exec >>"$logfile" 2>&1
fi
if [ -n "${RDSHELL-}" ]; then
mkdir -p -- "$disabled"
fd_lock 90 /dev/console
rdshell "Emergency shell" &
continue
fi
first_iter=
now="$(timestamp boottime raw)"
now="${now%.*}"
consmsg="/.initrd/rootdelay/message"
if [ ! -f "$_rootdelay_timestamp" ]; then
first_iter=1
deadline=$(( $now + $ROOTDELAY ))
mkdir -p -- "${_rootdelay_timestamp%/*}"
echo $deadline > "$_rootdelay_timestamp"
else
readline deadline "$_rootdelay_timestamp"
fi
deadline="${deadline:-$now}"
delay=$(( $deadline - $now ))
if [ "$delay" -le 0 ]; then
if ! resume_checked; then
set_resume_checked
echo $(( $now + $ROOTDELAY )) > "$_rootdelay_timestamp"
sleep $period
continue
fi
msg=
[ ! -f "$consmsg" ] ||
msg="$(cat "$consmsg")"
msg="${msg:-The waiting time expired!}"
fd_lock 90 /dev/console
# Disallow console access
if [ "${PANIC-}" = "0" ]; then
{
PROG=initramfs
message "$msg"
message "Disallow console access (panic=0). reboot."
} >/dev/console 2>&1 90<&- ||:
reboot -f
fi
mkdir -p -- "$disabled"
rdshell "$msg" &
continue
fi
if [ -z "${QUIET-}" ] && [ -z "$first_iter" ] && [ $(( $delay % 15 )) -eq 0 ]; then
fd_lock 90 /dev/console
resume_checked &&
msg="Waiting for root ${ROOT:+($ROOT) }..." ||
msg="Waiting for resume device ${RESUME:+($RESUME) }..."
PROG=initramfs \
message "$msg" >/dev/console 2>&1 90<&- ||:
fd_unlock 90
fi
sleep $period
done