summaryrefslogtreecommitdiff
path: root/gpsd.hotplug
blob: 69fa00def0466625f4a91998e623ab6c701a6393 (plain)
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
#!/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"
#    DEVNAME = the full name of the USB device that was just activated
#
# It will accept from /etc/sysconfig/gpsd the following config variables:
#
#    CONTROL_SOCKET = location of the gpsd control socket
#    OPTIONS = options to be passed to gpsd on launch
#
# It hands off to gpsdctl for the actual communication with the daemon.
#
# Do not introduce bashims into this script, as we want it to continue to
# work under Ubuntu.
#
# 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/conf.d/gpsd ]; then
  . /etc/conf.d/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 "$DEVNAME" ]
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
} &