~mmach/netext73/sysvinit

« back to all changes in this revision

Viewing changes to debian/src/initscripts/etc/init.d/udev

  • Committer: mmach
  • Date: 2023-11-26 16:47:13 UTC
  • Revision ID: netbit73@gmail.com-20231126164713-wzy9kmqvr8q6ydml
308

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh -e
 
2
### BEGIN INIT INFO
 
3
# Provides:          udev
 
4
# Required-Start:    mountkernfs
 
5
# Required-Stop:     umountroot
 
6
# Default-Start:     S
 
7
# Default-Stop:      0 6
 
8
# Short-Description: Start systemd-udevd, populate /dev and load drivers.
 
9
### END INIT INFO
 
10
 
 
11
PATH="/sbin:/bin"
 
12
NAME="systemd-udevd"
 
13
DAEMON="/lib/systemd/systemd-udevd"
 
14
DESC="hotplug events dispatcher"
 
15
PIDFILE="/run/udev.pid"
 
16
CTRLFILE="/run/udev/control"
 
17
OMITDIR="/run/sendsigs.omit.d"
 
18
 
 
19
# we need to unmount /dev/pts/ and remount it later over the devtmpfs
 
20
unmount_devpts() {
 
21
  if mountpoint -q /dev/pts/; then
 
22
    umount -n -l /dev/pts/
 
23
  fi
 
24
 
 
25
  if mountpoint -q /dev/shm/; then
 
26
    umount -n -l /dev/shm/
 
27
  fi
 
28
}
 
29
 
 
30
# mount a devtmpfs over /dev, if somebody did not already do it
 
31
mount_devtmpfs() {
 
32
  if grep -E -q "^[^[:space:]]+ /dev devtmpfs" /proc/mounts; then
 
33
    mount -n -o remount,nosuid,size=$tmpfs_size,mode=0755 -t devtmpfs devtmpfs /dev
 
34
    return
 
35
  fi
 
36
 
 
37
  if ! mount -n -o nosuid,size=$tmpfs_size,mode=0755 -t devtmpfs devtmpfs /dev; then
 
38
    log_failure_msg "udev requires devtmpfs support, not started"
 
39
    log_end_msg 1
 
40
  fi
 
41
 
 
42
  return 0
 
43
}
 
44
 
 
45
create_dev_makedev() {
 
46
  if [ -e /sbin/MAKEDEV ]; then
 
47
    ln -sf /sbin/MAKEDEV /dev/MAKEDEV
 
48
  else
 
49
    ln -sf /bin/true /dev/MAKEDEV
 
50
  fi
 
51
}
 
52
 
 
53
# shell version of /usr/bin/tty
 
54
my_tty() {
 
55
  [ -x /bin/readlink ] || return 0
 
56
  [ -e /proc/self/fd/0 ] || return 0
 
57
  readlink --silent /proc/self/fd/0 || true
 
58
}
 
59
 
 
60
warn_if_interactive() {
 
61
  if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then
 
62
    return
 
63
  fi
 
64
 
 
65
  TTY=$(my_tty)
 
66
  if [ -z "$TTY" -o "$TTY" = "/dev/console" -o "$TTY" = "/dev/null" ]; then
 
67
    return
 
68
  fi
 
69
 
 
70
  printf "\n\n\nIt has been detected that the command\n\n\t$0 $*\n\n"
 
71
  printf "has been run from an interactive shell.\n"
 
72
  printf "It will probably not do what you expect, so this script will wait\n"
 
73
  printf "60 seconds before continuing. Press ^C to stop it.\n"
 
74
  printf "RUNNING THIS COMMAND IS HIGHLY DISCOURAGED!\n\n\n\n"
 
75
  sleep 60
 
76
}
 
77
 
 
78
make_static_nodes() {
 
79
  [ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
 
80
  [ -x /bin/kmod ] || return 0
 
81
 
 
82
  /bin/kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 | \
 
83
  while read type name mode uid gid age arg; do
 
84
    [ -e $name ] && continue
 
85
    case "$type" in
 
86
      c|b|c!|b!) mknod -m $mode $name $type $(echo $arg | sed 's/:/ /') ;;
 
87
      d|d!) mkdir $name ;;
 
88
      *) echo "unparseable line ($type $name $mode $uid $gid $age $arg)" >&2 ;;
 
89
    esac
 
90
 
 
91
    if [ -x /sbin/restorecon ]; then
 
92
      /sbin/restorecon $name
 
93
    fi
 
94
  done
 
95
}
 
96
 
 
97
 
 
98
##############################################################################
 
99
 
 
100
 
 
101
[ -x $DAEMON ] || exit 0
 
102
 
 
103
# defaults
 
104
tmpfs_size="10M"
 
105
 
 
106
if [ -e /etc/udev/udev.conf ]; then
 
107
  . /etc/udev/udev.conf
 
108
fi
 
109
 
 
110
. /lib/lsb/init-functions
 
111
 
 
112
if [ ! -e /proc/filesystems ]; then
 
113
  log_failure_msg "udev requires a mounted procfs, not started"
 
114
  log_end_msg 1
 
115
fi
 
116
 
 
117
if ! grep -q '[[:space:]]devtmpfs$' /proc/filesystems; then
 
118
  log_failure_msg "udev requires devtmpfs support, not started"
 
119
  log_end_msg 1
 
120
fi
 
121
 
 
122
if [ ! -d /sys/class/ ]; then
 
123
  log_failure_msg "udev requires a mounted sysfs, not started"
 
124
  log_end_msg 1
 
125
fi
 
126
 
 
127
if [ ! -w /sys ]; then
 
128
  log_warning_msg "udev does not support containers, not started"
 
129
  exit 0
 
130
fi
 
131
 
 
132
if [ "$(stat -c %d/%i /)" != "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then
 
133
  # the devicenumber/inode pair of / is not the same as that of /sbin/init's
 
134
  # root, so we *are* in a chroot.
 
135
  log_warning_msg "A chroot environment has been detected, udev not started."
 
136
  exit 0
 
137
fi
 
138
 
 
139
if [ -d /sys/class/mem/null -a ! -L /sys/class/mem/null ] || \
 
140
   [ -e /sys/block -a ! -e /sys/class/block ]; then
 
141
  log_warning_msg "CONFIG_SYSFS_DEPRECATED must not be selected"
 
142
  log_warning_msg "Booting will continue in 30 seconds but many things will be broken"
 
143
  sleep 30
 
144
fi
 
145
 
 
146
# When modifying this script, do not forget that between the time that the
 
147
# new /dev has been mounted and udevadm trigger has been run there will be
 
148
# no /dev/null. This also means that you cannot use the "&" shell command.
 
149
 
 
150
case "$1" in
 
151
    start)
 
152
    if [ ! -e "/run/udev/" ]; then
 
153
        warn_if_interactive
 
154
    fi
 
155
 
 
156
    if [ -w /sys/kernel/uevent_helper ]; then
 
157
        echo > /sys/kernel/uevent_helper
 
158
    fi
 
159
 
 
160
    if ! mountpoint -q /dev/; then
 
161
        unmount_devpts
 
162
        mount_devtmpfs
 
163
        [ -d /proc/1 ] || mount -n /proc
 
164
    fi
 
165
 
 
166
    make_static_nodes
 
167
 
 
168
    # clean up parts of the database created by the initramfs udev
 
169
    udevadm info --cleanup-db
 
170
 
 
171
    # set the SELinux context for devices created in the initramfs
 
172
    [ -x /sbin/restorecon ] && /sbin/restorecon -R /dev
 
173
 
 
174
    log_daemon_msg "Starting $DESC" "$NAME"
 
175
    if start-stop-daemon --start --name $NAME --user root --quiet \
 
176
        --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile \
 
177
        --notify-await; then
 
178
        # prevents udevd to be killed by sendsigs (see #791944)
 
179
        mkdir -p $OMITDIR
 
180
        ln -sf $PIDFILE $OMITDIR/$NAME
 
181
        log_end_msg $?
 
182
    else
 
183
        log_warning_msg $?
 
184
        log_warning_msg "Waiting 15 seconds and trying to continue anyway"
 
185
        sleep 15
 
186
    fi
 
187
 
 
188
    log_action_begin_msg "Synthesizing the initial hotplug events (subsystems)"
 
189
    if udevadm trigger --type=subsystems --action=add; then
 
190
        log_action_end_msg $?
 
191
    else
 
192
        log_action_end_msg $?
 
193
    fi
 
194
    log_action_begin_msg "Synthesizing the initial hotplug events (devices)"
 
195
    if udevadm trigger --type=devices --action=add; then
 
196
        log_action_end_msg $?
 
197
    else
 
198
        log_action_end_msg $?
 
199
    fi
 
200
 
 
201
    create_dev_makedev
 
202
 
 
203
    # wait for the systemd-udevd childs to finish
 
204
    log_action_begin_msg "Waiting for /dev to be fully populated"
 
205
    if udevadm settle; then
 
206
        log_action_end_msg 0
 
207
    else
 
208
        log_action_end_msg 0 'timeout'
 
209
    fi
 
210
    ;;
 
211
 
 
212
    stop)
 
213
    log_daemon_msg "Stopping $DESC" "$NAME"
 
214
    if start-stop-daemon --stop --name $NAME --user root --quiet \
 
215
        --pidfile $PIDFILE --remove-pidfile --oknodo --retry 5; then
 
216
        # prevents cryptsetup/dmsetup hangs (see #791944)
 
217
        rm -f $CTRLFILE
 
218
        log_end_msg $?
 
219
    else
 
220
        log_end_msg $?
 
221
    fi
 
222
    ;;
 
223
 
 
224
    restart)
 
225
    log_daemon_msg "Stopping $DESC" "$NAME"
 
226
    if start-stop-daemon --stop --name $NAME --user root --quiet \
 
227
        --pidfile $PIDFILE --remove-pidfile --oknodo --retry 5; then
 
228
        # prevents cryptsetup/dmsetup hangs (see #791944)
 
229
        rm -f $CTRLFILE
 
230
        log_end_msg $?
 
231
    else
 
232
        log_end_msg $? || true
 
233
    fi
 
234
 
 
235
    log_daemon_msg "Starting $DESC" "$NAME"
 
236
    if start-stop-daemon --start --name $NAME --user root --quiet \
 
237
        --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile \
 
238
        --notify-await; then
 
239
        # prevents udevd to be killed by sendsigs (see #791944)
 
240
        mkdir -p $OMITDIR
 
241
        ln -sf $PIDFILE $OMITDIR/$NAME
 
242
        log_end_msg $?
 
243
    else
 
244
        log_end_msg $?
 
245
    fi
 
246
    ;;
 
247
 
 
248
    reload|force-reload)
 
249
    udevadm control --reload-rules
 
250
    ;;
 
251
 
 
252
    status)
 
253
    status_of_proc $DAEMON $NAME && exit 0 || exit $?
 
254
    ;;
 
255
 
 
256
    *)
 
257
    echo "Usage: /etc/init.d/udev {start|stop|restart|reload|force-reload|status}" >&2
 
258
    exit 1
 
259
    ;;
 
260
esac
 
261
 
 
262
exit 0