[ltp] New Mwave/ACP modem driver scripts

Thomas Hood linux-thinkpad@www.bm-soft.com
Sun, 31 Dec 2000 16:02:38 -0500


This is a multi-part message in MIME format.
--------------87940E61BE4989669B572234
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

My website, which is usually at 
   http://panopticon.csustan.edu/thood/tp600lnx.htm
is offline for a while, so I attach new versions
of my mwavem support scripts for Debian to this message.

Here is a description of the scripts.

First, /usr/sbin/mwavemd is a daemon wrapper script for
the mwavem support program.  Its purpose is to maintain a
/var/run file, to run setserial after the DSP has booted,
and to log its actions.

/etc/init.d/mwavem is a script to start and stop the modem
daemon.  On start it runs mwavemd.  On stop it kills mwavemd.

/etc/modutils/mwavem is a fragment of the /etc/modules.conf
file which leads the module loader to load the mwavedd module
when it is required.

Finally, /etc/apm/event.d/mwavem is a script which does
/etc/init.d/mwavem stop on suspend and /etc/init.d/mwavem
start on resume.  This script could be improved (e.g., so that
it kills processes using the ACP modem serial port before
unloading the driver) but I'll worry about that later.

--
Thomas

P.S. Note that the tpctl home page has moved from panopticon
to http://tpctl.sourceforge.net/tpctlhome.htm .
--------------87940E61BE4989669B572234
Content-Type: text/plain; charset=us-ascii;
 name="modutils_mwavem"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="modutils_mwavem"

alias char-major-96 mwavedd



--------------87940E61BE4989669B572234
Content-Type: text/plain; charset=us-ascii;
 name="init.d_mwavem"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="init.d_mwavem"

#!/bin/sh

PIDFILE=/var/run/mwavemd.pid
MWAVEM="/usr/local/bin/mwavem"
DEV="/dev/ttyS1"

case "$1" in
start)
	echo -n "Starting Mwave modem: "
	start-stop-daemon --start --startas /usr/sbin/mwavemd --background --pidfile $PIDFILE -- $MWAVEM $DEV
	[ $? -ne 0 ] && exit 1
	# Wait for pidfile to be created, indicating that the daemon is ready
	for w in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 timeout; do
		if [ "$w" = "timeout" ]; then
			echo "(timed out)."
			exit 1
		fi
		if [ -f $PIDFILE ]; then
			echo "(daemon:) mwavemd."
			exit 0
		fi
		sleep 1
	done
	exit 2   # We shouldn't reach here
	;;
stop)
	echo -n "Stopping Mwave modem: "
	( start-stop-daemon --stop --quiet --pidfile $PIDFILE && echo -n "(daemon:) mwavemd " ) || ( start-stop-daemon --stop --quiet --exec $MWAVEM && echo -n "(process:) mwavem " ) || echo -n "(no Mwave process running) "
	rm -f $PIDFILE   # in case it was left behind by some murdered mwavemd
	lsmod | grep -q -s '^mwavedd' > /dev/null 2>&1
	if [ $? -ne 0 ]; then # module not present
		echo "(and module not loaded)."
		exit 0
	fi
	# Module present.
	# Try to remove it.
	for w in 1 2 3 4 giveup; do
		if [ "$w" = "giveup" ]; then
			echo "(could not remove module mwavedd)."
			exit 1
		fi
		rmmod mwavedd >> /dev/null 2>&1
		if [ $? -eq 0 ]; then
			echo "(module:) mwavedd."
			exit 0
		fi
		sleep 1
	done
	exit 2   # We shouldn't reach here
	;;
restart)
	$0 stop && $0 start
	;;
esac


--------------87940E61BE4989669B572234
Content-Type: text/plain; charset=us-ascii;
 name="event.d_mwavem"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="event.d_mwavem"

#!/bin/sh

case "$1" in
suspend)
	/etc/init.d/mwavem stop | logger -t '/etc/apm/event.d/mwavem'
	;;
resume)
	/etc/init.d/mwavem start | logger -t '/etc/apm/event.d/mwavem'
	;;
esac


--------------87940E61BE4989669B572234
Content-Type: text/plain; charset=us-ascii;
 name="mwavemd"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="mwavemd"

#!/bin/sh
# /usr/sbin/mwavemd
# This script runs the Mwave modem support program and configures the serial
# port driver for the Mwave modem serial interface; then it creates a process
# i.d. file under /var/run.  Having done this it waits for a signal. 
# When it receives a SIGTERM, it deletes its process i.d. file, kills the
# modem support process and exits once the latter is dead.

if [ "$2" = "" ]; then
	echo "mwavemd: Requires two arguments"
	exit 1
fi

# The Mwave support daemon executable
MWAVEM=$1

# The serial device used to access the Mwave modem
DEV=$2

# Delete any old pidfile
rm -f /var/run/mwavemd.pid

trap 'logger -t mwavemd "Passing SIGTERM to modem support process ..." ; killall -v $MWAVEM 2>&1 | logger -t mwavemd ; trap - 15' 15

# Note that creation of the pidfile is the signal that the modem is ready to use
logger -t mwavemd 'Starting modem support process ...'
$MWAVEM | awk -W interactive '/STARTED/ { print ; print "... started. Now setserial'"'"'ing '"$DEV".'" ; system("setserial '"$DEV"' autoconfig") ; system("echo '"$$"' >| /var/run/mwavemd.pid") ; exit } { print }' | logger -t mwavemd &

# Wait for our child, the Mwave modem support process, to complete.
# This wait will be interrupted by a SIGTERM signal, which will cause
# the trap command set above to be executed.  The bash man page currently
# (Dec 2000) says that the wait will "return" when such a signal is received;
# but what actually happens is that the wait resumes.  That is why the trap
# command has to kill the child processes---otherwise we will wait forever.
wait

# In case the man page is (or becomes) right and the wait above "returns"
# on receipt of a singal, let us wait again for the death of our children.
wait

# Deletion of the pidfile indicates that the killing is complete
rm -f /var/run/mwavemd.pid

exit 0


--------------87940E61BE4989669B572234--

----- The Linux ThinkPad mailing list -----
The linux-thinkpad mailing list home page is at:
http://www.bm-soft.com/~bm/tp_mailing.html