Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | ### BEGIN INIT INFO |
| 4 | # Provides: udev |
| 5 | # Required-Start: mountvirtfs |
| 6 | # Required-Stop: |
| 7 | # Default-Start: S |
| 8 | # Default-Stop: |
| 9 | # Short-Description: Start udevd, populate /dev and load drivers. |
| 10 | ### END INIT INFO |
| 11 | |
| 12 | . /etc/init.d/functions |
| 13 | |
| 14 | export TZ=/etc/localtime |
| 15 | |
| 16 | [ -d /sys/class ] || exit 1 |
| 17 | [ -r /proc/mounts ] || exit 1 |
| 18 | [ -x @UDEVD@ ] || exit 1 |
| 19 | [ -f /etc/default/udev-cache ] && . /etc/default/udev-cache |
| 20 | [ -f /etc/udev/udev.conf ] && . /etc/udev/udev.conf |
| 21 | |
| 22 | readfile () { |
| 23 | filename=$1 |
| 24 | READDATA="" |
| 25 | if [ -r $filename ]; then |
| 26 | while read line; do |
| 27 | READDATA="$READDATA$line" |
| 28 | done < $filename |
| 29 | fi |
| 30 | } |
| 31 | |
| 32 | case "$1" in |
| 33 | start) |
| 34 | export ACTION=add |
| 35 | # propagate /dev from /sys |
| 36 | echo "Starting udev" |
| 37 | |
| 38 | # mount the devtmpfs on /dev, if not already done |
| 39 | LANG=C awk '$2 == "/dev" && ($3 == "devtmpfs") { exit 1 }' /proc/mounts && { |
| 40 | mount -n -o mode=0755 -t devtmpfs none "/dev" |
| 41 | } |
| 42 | [ -e /dev/pts ] || mkdir -m 0755 /dev/pts |
| 43 | [ -e /dev/shm ] || mkdir -m 1777 /dev/shm |
| 44 | mount -a -t tmpfs 2>/dev/null |
| 45 | |
| 46 | # cache handling |
| 47 | if [ "$DEVCACHE" != "" ]; then |
| 48 | readfile /proc/version |
| 49 | VERSION="$READDATA" |
| 50 | readfile /proc/cmdline |
| 51 | CMDLINE="$READDATA" |
| 52 | readfile /proc/devices |
| 53 | DEVICES="$READDATA" |
| 54 | readfile /proc/atags |
| 55 | ATAGS="$READDATA" |
| 56 | |
| 57 | if [ -e $DEVCACHE ]; then |
| 58 | readfile /etc/udev/cache.data |
| 59 | if [ "$READDATA" = "$VERSION$CMDLINE$DEVICES$ATAGS" ]; then |
| 60 | (cd /; tar xf $DEVCACHE > /dev/null 2>&1) |
| 61 | not_first_boot=1 |
| 62 | [ "$VERBOSE" != "no" ] && echo "udev: using cache file $DEVCACHE" |
| 63 | [ -e /dev/shm/udev.cache ] && rm -f /dev/shm/udev.cache |
| 64 | else |
| 65 | echo "$VERSION$CMDLINE$DEVICES$ATAGS" > /dev/shm/udev.cache |
| 66 | fi |
| 67 | else |
| 68 | echo "$VERSION$CMDLINE$DEVICES$ATAGS" > /dev/shm/udev.cache |
| 69 | fi |
| 70 | fi |
| 71 | |
| 72 | # make_extra_nodes |
| 73 | killproc systemd-udevd > "/dev/null" 2>&1 |
| 74 | |
| 75 | # trigger the sorted events |
| 76 | echo -e '\000\000\000\000' > /proc/sys/kernel/hotplug |
| 77 | @UDEVD@ -d |
| 78 | |
| 79 | udevadm control --env=STARTUP=1 |
| 80 | if [ "$not_first_boot" != "" ];then |
| 81 | udevadm trigger --action=add --subsystem-nomatch=tty --subsystem-nomatch=mem --subsystem-nomatch=vc --subsystem-nomatch=vtconsole --subsystem-nomatch=misc --subsystem-nomatch=dcon --subsystem-nomatch=pci_bus --subsystem-nomatch=graphics --subsystem-nomatch=backlight --subsystem-nomatch=video4linux --subsystem-nomatch=platform |
| 82 | (udevadm settle --timeout=3; udevadm control --env=STARTUP=)& |
| 83 | else |
| 84 | udevadm trigger --action=add |
| 85 | udevadm settle |
| 86 | fi |
| 87 | ;; |
| 88 | stop) |
| 89 | echo "Stopping udevd" |
| 90 | start-stop-daemon --stop --name systemd-udevd --quiet |
| 91 | ;; |
| 92 | restart) |
| 93 | $0 stop |
| 94 | sleep 1 |
| 95 | $0 start |
| 96 | ;; |
| 97 | status) |
| 98 | status systemd-udevd |
| 99 | ;; |
| 100 | *) |
| 101 | echo "Usage: $0 {start|stop|status|restart}" |
| 102 | exit 1 |
| 103 | esac |
| 104 | exit 0 |