diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-06-25 04:58:52 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-06-25 04:58:52 -0400 |
commit | 711a3f84129445b2d21ff7233fbec9cb8db5130b (patch) | |
tree | 023c6e7f726e1b7c2971eaef1fb84973d3e57dd9 /gpsd.hotplug | |
parent | 8cb7bfa3152831fddde0a8e990b07ef43429b24e (diff) | |
download | gpsd-711a3f84129445b2d21ff7233fbec9cb8db5130b.tar.gz |
Rename gpsd.hotplug.wrapper to gpsd.hotplug.
gpsd.hotplug was previously the name of the now-removed Python script.
The udev test documented in SConstruct passes.
Diffstat (limited to 'gpsd.hotplug')
-rw-r--r-- | gpsd.hotplug | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/gpsd.hotplug b/gpsd.hotplug new file mode 100644 index 00000000..9b3de453 --- /dev/null +++ b/gpsd.hotplug @@ -0,0 +1,67 @@ +#!/bin/sh +# +# This script is the gpsd udev handler for add/remove events on matched USB +# devices. It expects to see the following environment variables: +# ACTION = either "add" or "remove" +# DEVPATH = the full name of the USB device that was just activated +# +# This file is Copyright (c) 2010 by the GPSD project +# BSD terms apply: see the file COPYING in the distribution root for details. + +PATH=/usr/sbin:$PATH +export PATH + +if [ -r /etc/default/gpsd ]; then + . /etc/default/gpsd +elif [ -r /etc/sysconfig/gpsd ]; then + . /etc/sysconfig/gpsd + GPSD_OPTIONS=$OPTIONS + GPSD_SOCKET=$CONTROL_SOCKET +fi + +if [ -n "$GPSD_OPTIONS" ]; then + export GPSD_OPTIONS +fi +if [ -n "$GPSD_SOCKET" ]; then + export GPSD_SOCKET +fi + +if [ -n "$USBAUTO" ]; then + [ "$USBAUTO" = "true" ] || exit 0 +fi + +if [ "$ACTION" = "remove" ] ; then + if echo $DEVLINKS | grep -q /dev/gps; then + : + else + exit 0 + fi +fi + +logger -t "gpsd.hotplug" -p daemon.info "$ACTION" "$DEVNAME" + +if [ -z "$DEVPATH" ] +then + logger -t gpsd.hotplug -p daemon.err "no device" + exit 0 +fi + +# In recent versions of udev, the gpsd script runs in series with +# the task that creates the real /dev/ttyUSBn device +# node. Unfortunately, the gpsd script runs BEFORE the creation of +# the node, and the node is not created until after you kill the +# gpsd script, because the gpsd script waits forever for the node +# to appear. +# +# This is a race condition, and is best fixed by running the +# actual wait/hotplug portion in the background. + +{ + logger -t gpsd.hotplug -p daemon.info "waiting for" $DEVNAME + while [ -x $DEVNAME ] + do + sleep 1 + done + logger -t gpsd.hotplug -p daemon.info $DEVNAME "is active" + gpsdctl $ACTION $DEVNAME +} & |