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 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
From: Jonas Genannt <jonas.genannt@capi2name.de>
Subject: setserial rc.serial patch
Index: setserial/rc.serial
===================================================================
--- setserial.orig/rc.serial 2006-06-20 10:02:58.000000000 +0200
+++ setserial/rc.serial 2006-06-20 10:30:35.000000000 +0200
@@ -1,134 +1,192 @@
-#
+#! /bin/sh
# /etc/rc.serial
# Initializes the serial ports on your system
-#
+### BEGIN INIT INFO
+# Provides: setserial
+# Required-Start: $remote_fs
+# Required-Stop: $remote_fs
+# Default-Start: S
+# Default-Stop: 0 1 6
+# Short-Description: controls configuration of serial ports
+# Description: Set and/or report the configuration information
+# associated with a serial port. This information
+# includes what I/O port and which IRQ a particular
+# serial port is using.
+### END INIT INFO
# chkconfig: 2345 50 75
# description: This initializes the settings of the serial port
#
-# FILE_VERSION: 19981128
-#
-# Distributed with setserial and the serial driver. We need to use the
-# FILE_VERSION field to assure that we don't overwrite a newer rc.serial
-# file with a newer one.
+# Distributed with setserial version 2.15
#
-# XXXX For now, the autosave feature doesn't work if you are
+# XXXX note: as of 2.15, the autosave feature doesn't work if you are
# using the multiport feature; it doesn't save the multiport configuration
# (for now). Autosave also doesn't work for the hayes devices.
-# Will fix later...
+#Will fix later...
#
#
+# Note that this has been changed so that if /etc/serial.conf exists,
+# this script does not configure the ports. It uses
+# /var/lib/setserial/autoserial.conf # instead, which is handled by another
+# init.d script. However, the script is still used for module loads and
+# unloads, even if serial.conf exists.
+#
-RCLOCKFILE=/var/lock/subsys/serial
-DIRS="/lib/modules/`uname -r`/misc /lib/modules /usr/lib/modules ."
-PATH=/bin:/sbin:/usr/bin
-DRIVER=serial
-DRIVER_NAME=serial
-MODULE_REGEXP="serial\b"
-
-ALLDEVS="/dev/ttyS?"
-if /bin/ls /dev/ttyS?? >& /dev/null ; then
- ALLDEVS="$ALLDEVS /dev/ttyS??"
-fi
+SETSERIAL=/bin/setserial
+modconf=/var/run/setserial.conf
+autoconfig=/var/lib/setserial/autoserial.conf
+etcconfig=/etc/serial.conf
-SETSERIAL=""
-if test -x /bin/setserial ; then
- SETSERIAL=/bin/setserial
-elif test -x /sbin/setserial ; then
- SETSERIAL=/sbin/setserial
-fi
+# If the serial executable has been removed abort the configuration
+[ -x ${SETSERIAL} ] || exit 0
#
-# See if the serial driver is loaded
+# make sure that a serial device is loaded...
+# insmod -k serial 2>/dev/null
#
-LOADED=""
-if test -f /proc/devices; then
- if grep -q " ttyS$" /proc/devices ; then
- LOADED="yes"
- else
- LOADED="no"
- fi
-fi
#
-# Find the serial driver
+# Support devfs when it arrives.
#
-for i in $DIRS
-do
- if test -z "$MODULE" -a -f $i/$DRIVER.o ; then
- MODULE=$i/$DRIVER.o
+if /bin/ls /dev/tts 2> /dev/null 1>&2 ; then
+ ALLDEVS="/dev/tts/*"
+else
+ # No devfs - old naming scheme
+ ALLDEVS="/dev/ttyS?"
+ if /bin/ls /dev/ttyS?? 2> /dev/null 1>&2 ; then
+ ALLDEVS="$ALLDEVS /dev/ttyS??"
fi
-done
-
-if ! test -f /proc/modules ; then
- MODULE=""
fi
#
# Handle System V init conventions...
#
case $1 in
-start)
+start | restart | force-reload )
action="start";
+ [ -f ${etcconfig} ] && exit 0
;;
stop)
action="stop";
+ [ -f ${etcconfig} ] && exit 0
+ ;;
+status)
+ action="status";
+ ;;
+modload)
+ action="modload";
+ ;;
+modsave)
+ action="modsave";
;;
*)
action="start";
+ [ -f ${etcconfig} ] && exit 0
esac
+if test $action = modload ; then
+ echo "Restoring persistent state of serial.o module due to module reload... "
+ if test -f ${modconf} ; then
+ while read device args
+ do
+ case "$device" in
+ ""|\#*)
+ continue
+ ;;
+ esac
+ ${SETSERIAL} -z $device $args
+ done < ${modconf}
+ else
+ echo "Warning - no module state found (ok if this is at bootup)"
+ echo "Using the bootup configuration instead."
+ action="start";
+ fi
+ exit 0
+fi
+
if test $action = stop ; then
- if test -n ${SETSERIAL} -a "$LOADED" != "no" -a \
- `head -1 /etc/serial.conf`X = "###AUTOSAVE###X" ; then
- echo -n "Saving state of serial devices... "
- grep "^#" /etc/serial.conf > /etc/.serial.conf.new
- ${SETSERIAL} -G -g ${ALLDEVS} >> /etc/.serial.conf.new
- mv /etc/serial.conf /etc/.serial.conf.old
- mv /etc/.serial.conf.new /etc/serial.conf
- echo "done."
+ if [ -e ${etcconfig} ]; then
+ #nothing to do
+ dummy=0;
+ elif test "`sed 1q $autoconfig`X" = "###AUTOSAVE###X" ; then
+ echo -n "Saving state of known serial devices... "
+ grep "^#" $autoconfig > ${autoconfig}.new
+ ${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown\|pcmcia" >> ${autoconfig}.new
+ echo -n "backing up $autoconfig"
+ mv $autoconfig ${autoconfig}.old
+ mv ${autoconfig}.new $autoconfig
+ echo " done."
+ elif test "`sed 1q $autoconfig`X" = "###AUTOSAVE-FULL###X" ; then
+ echo -n "Saving state (including unknowns) of serial devices... "
+ grep "^#" $autoconfig > ${autoconfig}.new
+ ${SETSERIAL} -G -g ${ALLDEVS} | grep -v "pcmcia" >> ${autoconfig}.new
+ echo -n "backing up $autoconfig"
+ mv $autoconfig ${autoconfig}.old
+ mv ${autoconfig}.new $autoconfig
+ echo " done."
+ elif test "`sed 1q $autoconfig`X" = "###AUTOSAVE-ONCE###X" ; then
+ echo -n "Saving state of known serial devices... "
+ echo "###PORT STATE GENERATED USING AUTOSAVE-ONCE###" > ${autoconfig}.new
+ grep "^#" $autoconfig >> ${autoconfig}.new
+ ${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown\|pcmcia" >> ${autoconfig}.new
+ echo -n "backing up $autoconfig"
+ mv $autoconfig ${autoconfig}.old
+ mv ${autoconfig}.new $autoconfig
+ echo " done."
fi
- if test -n $MODULE ; then
- module=`grep $MODULE_REGEXP /proc/modules | awk '{print $1}'`
- if test -z "$module" ; then
- echo "The $DRIVER_NAME driver is not loaded."
- rm -f ${RCLOCKFILE}
- exit 0
- fi
- if rmmod $module ; then :; else
- echo "The $DRIVER_NAME driver could NOT be unloaded."
- exit 1;
- fi
- echo "The $DRIVER_NAME driver has been unloaded."
- fi
- rm -f ${RCLOCKFILE}
exit 0
fi
#
-# If not stop, it must be a start....
+# Is it Start
#
-if test -n $MODULE -a "$LOADED" != "yes" ; then
- if insmod -fm $MODULE $DRIVER_ARG \
- > /tmp/$DRIVER.map 2> /tmp/$DRIVER.$$; then :;
- else
- echo "Couldn't load $DRIVER_NAME driver."
- echo "See error logs in /tmp/$DRIVER.$$"
- exit 1
- fi
- /bin/rm -f /tmp/$DRIVER.$$
-fi
-
-if test -f /etc/serial.conf ; then
- if test -n ${SETSERIAL} ; then
- grep -v ^# < /etc/serial.conf | while read device args
- do
- ${SETSERIAL} -z $device $args
- done
- fi
-else
- echo "###AUTOSAVE###" > /etc/serial.conf
+if test $action = start ; then
+ outmsg=""
+ echo "Loading the saved-state of the serial devices... "
+ rm -f ${modconf}
+
+ if test -f $etcconfig ; then
+ readfrom=$etcconfig;
+ else
+ readfrom=$autoconfig;
+ fi
+ if test -f $readfrom ; then
+ while read device args
+ do
+ case "$device" in
+ "#KERNEL")
+ outmsg="... handled by kernel"
+ continue
+ ;;
+ ""|\#*)
+ continue
+ ;;
+ esac
+ outmsg=""
+ ${SETSERIAL} -z $device $args
+ ${SETSERIAL} -bg $device
+ done < $readfrom
+ if test ! "$outmsg" = "" ; then
+ echo $outmsg
+ fi
+
+ else
+ echo "###AUTOSAVE###" > $autoconfig
+ fi
+fi
+
+if test $action = modsave ; then
+ echo -n "Saving serial.o state to emulate module data persistence... "
+ rm -f ${modconf}
+ ${SETSERIAL} -G -g ${ALLDEVS} | grep -v "uart unknown\|pcmcia" > ${modconf}
+ echo "done."
+ exit 0
+fi
+
+if test $action = status ; then
+ echo "Status of serial devices: ${ALLDEVS}"
+ for d in ${ALLDEVS}; do
+ ${SETSERIAL} -a ${d}
+ done
+ exit 0
fi
-
-touch ${RCLOCKFILE}
-${SETSERIAL} -bg ${ALLDEVS}
|