summaryrefslogtreecommitdiffstats
path: root/smgl/init.d/init.d/devices
blob: 824eea720bad0955b3159a2bdefbfbe7b5e20161 (plain) (blame)
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/bin/bash

PROGRAM=/bin/false
RUNLEVEL=DEV
ESSENTIAL=yes

. /etc/init.d/smgl_init
. /etc/sysconfig/devices

start_devfs()
{
  if ! [ -e /dev/.devfsd ]
  then echo "Mounting devfs on /dev"
       mount -n -t devfs devfs /dev
       evaluate_retval
  fi

  echo "Telling init to reopen file descriptors"
  kill -USR1 1

  if [ ! -x "/sbin/devfsd" ] ; then
    ln -sf /proc/self/fd /dev/fd
    ln -sf /dev/fd/0 /dev/stdin
    ln -sf /dev/fd/1 /dev/stdout
    ln -sf /dev/fd/2 /dev/stderr
  fi
}

udev_mknodes()
{
# eudev creates these; errors if they are already present
UD=`/bin/udevadm --version`
if [[ $UD < '220' ]];then
  if [ ! -d $udev_root/fd ]; then
    ln -fs /proc/self/fd $udev_root/fd
  fi
  ln -s /dev/fd/0 $udev_root/stdin
  ln -s /dev/fd/1 $udev_root/stdout
  ln -s /dev/fd/2 $udev_root/stderr
fi
  mkdir $udev_root/shm
  mkdir $udev_root/pts
}

start_udev()
{ (
  . /etc/udev/udev.conf
  echo "Checking if devtmpfs or ramfs is used for $udev_root ..."
  if findmnt devtmpfs > /dev/null 2>&1; then
    echo "devtmpfs is used for $udev_root"
  else
    echo "ramfs is used for $udev_root"
    echo "Mounting ramfs at $udev_root"
    mount -n -t ramfs none $udev_root
  fi
  # create some needed stuff
  udev_mknodes

  # kernel 2.6.15-rc1 and higher don't use hotplug
  if [[ $(printf "%s\n%s\n" "$(uname -r)" "2.6.15" | sort -V | head -n 1) \
        = 2.6.15 ]]; then
    echo "don't need hotplug for this kernel"
    builtin echo > /proc/sys/kernel/hotplug
  else
      # Now uses udevsend as the hotplug multiplexer
    echo "Setting udevsend as hotplug agent"
    sysctl -w kernel.hotplug="/sbin/udevsend" > /dev/null 2>&1
    echo "Creating initial udev device nodes"
    /sbin/udevstart
  fi

  if [ -f /etc/udev/udev.missing ]; then
    echo "Processing /etc/udev/udev.missing"
    cd /dev
    while read line; do
      if [ "${line:0:1}" == "#" ]; then continue; fi
      for ((i=0; i<7; i++)); do
        val[$i]=${line%%:*}
        line=${line#*:}
      done
      if [ "${val[1]}" == "d" ]; then
        mkdir ${val[0]}
      else
        mknod ${val[0]} ${val[1]} ${val[2]} ${val[3]}
      fi
      chmod ${val[4]} ${val[0]}
      chown ${val[5]}:${val[6]} ${val[0]}
    done < /etc/udev/udev.missing
    cd /
  fi
  echo "Telling init to reopen file descriptors"
  kill -USR1 1
) }

start_static_udev()
{ (
  . /etc/udev/udev.conf
  # create some needed stuff - and insist on it
  udev_mknodes

  # kernel 2.6.15-rc1 and higher don't use hotplug
  if [[ $(printf "%s\n%s\n" "$(uname -r)" "2.6.15" | sort -V | head -n 1) \
        = 2.6.15 ]]; then
    echo "don't need hotplug for this kernel"
    builtin echo > /proc/sys/kernel/hotplug
  else
      # Now uses udevsend as the hotplug multiplexer
    echo "Setting udevsend as hotplug agent"
    sysctl -w kernel.hotplug="/sbin/udevsend" > /dev/null 2>&1
    echo "Creating initial udev device nodes"
    /sbin/udevstart
  fi

  if [ -f /etc/udev/udev.missing ]; then
    echo "Processing /etc/udev/udev.missing"
    cd /dev
    while read line; do
      if [ "${line:0:1}" == "#" ]; then continue; fi
      for ((i=0; i<7; i++)); do
        val[$i]=${line%%:*}
        line=${line#*:}
      done
      if [ "${val[1]}" == "d" ]; then
        mkdir -p ${val[0]}
      else
        mknod ${val[0]} ${val[1]} ${val[2]} ${val[3]}
      fi
      chmod ${val[4]} ${val[0]}
      chown ${val[5]}:${val[6]} ${val[0]}
    done < /etc/udev/udev.missing
    cd /
  fi
) }

start_static()
{
   exit 0
}

start()
{
  # mount proc
  echo "Mounting /proc"
  mount -n -t proc proc /proc
  # mount sys
  echo "Mounting /sys"
  mount -n -t sysfs sysfs /sys
  # mount run
  echo "Mounting /run"
  mount -n -o size=${RUN_SIZE:-50%} -t tmpfs tmpfs /run
  eval "start_$DEVICES"
}

stop() { exit 0; }
restart() { exit 3; }
reload() { exit 3; }
force_reload() { exit 3; }
status() { exit 3; }

usage()
{
  echo "Usage: $0 {start|stop}"
  echo "Warning: Do not run this script manually!"
}