summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--SConstruct8
-rwxr-xr-xgpsd.hotplug124
-rw-r--r--gpsd.hotplug.wrapper37
-rw-r--r--gpsd.rules1
-rw-r--r--gpsdctl.c1
-rw-r--r--packaging/rpm/gpsd.spec.in2
6 files changed, 39 insertions, 134 deletions
diff --git a/SConstruct b/SConstruct
index 1fffde7c..fcf8d62a 100644
--- a/SConstruct
+++ b/SConstruct
@@ -916,7 +916,7 @@ for (name, help, default) in pathopts:
headerinstall = [ env.Install(includedir, x) for x in ("libgpsmm.h", "gps.h")]
binaryinstall = []
-binaryinstall.append(env.Install(sbindir, gpsd))
+binaryinstall.append(env.Install(sbindir, [gpsd, gpsdctl]))
binaryinstall.append(env.Install(bindir, [gpsdecode, gpsctl, gpspipe, gpxlogger, lcdgps]))
if ncurseslibs:
binaryinstall.append(env.Install(bindir, [cgps, gpsmon]))
@@ -1244,12 +1244,12 @@ env.Command('www/pydoc/index.html', python_progs + glob.glob("*.py") + glob.glo
Utility('udev-install', '', [
'cp $SRCDIR/gpsd.rules /lib/udev/rules.d/25-gpsd.rules',
- 'cp $SRCDIR/gpsd.hotplug $SRCDIR/gpsd.hotplug.wrapper /lib/udev/',
- 'chmod a+x /lib/udev/gpsd.hotplug /lib/udev/gpsd.hotplug.wrapper',
+ 'cp $SRCDIR/gpsd.hotplug.wrapper /lib/udev/',
+ 'chmod a+x /lib/udev/gpsd.hotplug.wrapper',
])
Utility('udev-uninstall', '', [
- 'rm -f /lib/udev/{gpsd.hotplug,gpsd.hotplug.wrapper}',
+ 'rm -f /lib/udev/gpsd.hotplug.wrapper',
'rm -f /lib/udev/rules.d/25-gpsd.rules',
])
diff --git a/gpsd.hotplug b/gpsd.hotplug
deleted file mode 100755
index 805f9419..00000000
--- a/gpsd.hotplug
+++ /dev/null
@@ -1,124 +0,0 @@
-#!/usr/bin/python
-#
-# This file is Copyright (c) 2010 by the GPSD project
-# BSD terms apply: see the file COPYING in the distribution root for details.
-#
-# Hotplug script for gpsd by Eric S. Raymond, March 2005
-# This script is part of the gpsd distribution: see http://gpsd.berlios.de
-# Can be called like "gpsd.hotplug [add|remove] /dev/ttyUSB0" for test
-# purposes.
-import sys, time, os, syslog, glob, socket, stat
-
-CONTROL_SOCKET = os.getenv('GPSD_SOCKET') or "/var/run/gpsd.sock"
-GPSD_OPTIONS = os.getenv('GPSD_OPTIONS') or ""
-
-WHEREAMI = __file__
-
-def gpsd_control_connect(complain=True):
- "Acquire a connection to the GPSD control socket."
- if not os.path.exists(CONTROL_SOCKET):
- syslog.syslog("socket %s doesn't exist" % CONTROL_SOCKET)
- return None
- try:
- sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0)
- sock.connect(CONTROL_SOCKET)
- except socket.error, msg:
- if complain:
- syslog.syslog("socket %s creation failure: %s" % (CONTROL_SOCKET, msg))
- if sock:
- sock.close()
- sock = None
- #else:
- # syslog.syslog("socket %s created OK" % CONTROL_SOCKET)
- return sock
-
-def gpsd_control(action, argument):
- "Pass a command to gpsd; start the daemon if not already running."
- syslog.syslog("gpsd_control(action=%s, arg=%s)" % (action, argument))
- connect = gpsd_control_connect(complain=False)
- if connect:
- syslog.syslog("reached a running gpsd")
- elif action == 'add':
- gpsdcmd = "gpsd %s -F %s" % (GPSD_OPTIONS, CONTROL_SOCKET)
- syslog.syslog("launching %s" % gpsdcmd)
- os.system(gpsdcmd)
- connect = gpsd_control_connect(complain=True)
- if not connect:
- syslog.syslog("can't reach gpsd")
- return None
- # We've got a live connection to the gpsd control socket. No
- # need to parse the response, because gpsd will lock on to the
- # device if it's really a GPS and ignore it if it's not.
- if action == 'add':
- # Force the group-read & group-write bits on, so gpsd will still be
- # able to use this device after dropping root privileges.
- os.chmod(argument, stat.S_IMODE(os.stat(argument)[stat.ST_MODE])|0660)
- connect.sendall("+%s\r\n" % argument)
- connect.recv(12)
- elif action == 'remove':
- connect.sendall("-%s\r\n" % argument)
- connect.recv(12)
- elif action == 'send':
- connect.sendall("%s\r\n" % argument)
- connect.recv(12)
- connect.close()
- #syslog.syslog("gpsd_control ends")
- return action
-
-def hotplug(action, devpath):
- #syslog.syslog("ACTION=%s DEVPATH=%s" % (action,devpath))
- if not devpath:
- syslog.syslog("No device")
- else:
- subnodes = glob.glob("/sys" + devpath + "/*")
- subnodes = map(os.path.basename, subnodes)
- subnodes = filter(lambda s: s.startswith("ttyUSB"), subnodes)
- if len(subnodes) == 0:
- syslog.syslog("no ttyUSB device under " + devpath)
- return
- elif len(subnodes) > 1:
- syslog.syslog("too many ttyUSB devices under " + devpath)
- return
- else:
- tty = "/dev/" + subnodes[0]
-
- syslog.syslog("waiting for " + tty)
- while not os.path.exists(tty):
- time.sleep(1)
- syslog.syslog(tty + " has gone active")
-
- gpsd_control(action, tty)
-
- remover = os.getenv("REMOVER")
- #syslog.syslog("REMOVER=%s" % remover)
- fp = open(remover, "w")
- fp.write(WHEREAMI + " remove " + tty)
- fp.close()
- os.chmod(remover, stat.S_IRUSR|stat.S_IXUSR|stat.S_IRGRP|stat.S_IXGRP)
- return
-
-if __name__ == '__main__':
- # In recent versions of udev, the gpsd script runs in series with
- # the task that creates the real /dev/ttyUSB0 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.
- pid = os.fork()
- if not pid:
- syslog.openlog('gpsd.hotplug', 0, syslog.LOG_DAEMON)
- try:
- if len(sys.argv) == 1: # Called as hotplug script
- hotplug(os.getenv("ACTION"), os.getenv("DEVPATH"))
- else: # Called by hand for testing
- gpsd_control(sys.argv[1], sys.argv[2])
- except:
- (exc_type, exc_value, exc_traceback) = sys.exc_info()
- syslog.syslog("gpsd.hotplug: exception %s yields %s" % (exc_type, exc_value))
- raise exc_type, exc_value, exc_traceback
- #syslog.syslog("gpsd.hotplug ends")
- syslog.closelog()
-
diff --git a/gpsd.hotplug.wrapper b/gpsd.hotplug.wrapper
index 29902154..9b3de453 100644
--- a/gpsd.hotplug.wrapper
+++ b/gpsd.hotplug.wrapper
@@ -1,5 +1,10 @@
#!/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.
@@ -27,12 +32,36 @@ fi
if [ "$ACTION" = "remove" ] ; then
if echo $DEVLINKS | grep -q /dev/gps; then
- exec /lib/udev/gpsd.hotplug "$ACTION" "$DEVNAME"
+ :
+ else
+ exit 0
fi
- exit 0
fi
-if [ -x /usr/bin/python ]; then
- exec /lib/udev/gpsd.hotplug "$ACTION" "$DEVNAME"
+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
+} &
diff --git a/gpsd.rules b/gpsd.rules
index 80c6609e..bf315290 100644
--- a/gpsd.rules
+++ b/gpsd.rules
@@ -15,7 +15,6 @@
#
# /lib/udev/rules.d/25-gpsd.rules
# /lib/udev/gpsd.hotplug.wrapper
-# /lib/udev/gpsd.hotplug
#
# Setting the link in /lib/udev/rules.d activates the rule and determines
# when to run it on boot (similar to init.d processing).
diff --git a/gpsdctl.c b/gpsdctl.c
index ba17ab81..08a78216 100644
--- a/gpsdctl.c
+++ b/gpsdctl.c
@@ -117,6 +117,7 @@ static int gpsd_control(char *action, char *argument)
int main(int argc, char *argv[])
{
+ openlog("gpsdctl", 0, LOG_DAEMON);
if (argc != 3) {
(void)syslog(LOG_ERR, "requires action and argument (%d)", argc);
exit(1);
diff --git a/packaging/rpm/gpsd.spec.in b/packaging/rpm/gpsd.spec.in
index eee1337b..4c00189c 100644
--- a/packaging/rpm/gpsd.spec.in
+++ b/packaging/rpm/gpsd.spec.in
@@ -132,7 +132,7 @@ find $RPM_BUILD_ROOT
# hotplug script
%{__install} -d -m 0755 $RPM_BUILD_ROOT/lib/udev
-%{__install} -p -m 0755 gpsd.hotplug gpsd.hotplug.wrapper $RPM_BUILD_ROOT/lib/udev
+%{__install} -p -m 0755 gpsd.hotplug.wrapper $RPM_BUILD_ROOT/lib/udev
# remove .la files
#rm -f $RPM_BUILD_ROOT%{_libdir}/libgps*.la