Since the switch to systemd, the udev configuration needs to be reworked
to work properly both for hot and cold plugging.

The Fedora maintainers have kindly shared their solution here:

https://lists.gnu.org/archive/html/gpsd-users/2014-04/msg00037.html

The attached patch introduces a gpsdctl systemd service, which replaces
the hotplug wrapper script. I have successfuly tested the patch with
real hardware:

- booting without a GPS attached, and plugging in the GPS once the
system is started

- booting with a GPS attached

Cheers,
Jeremy
commit eff9cb9a8831d68a3e8c5381954e2acad6b0d5cf
Author: Jeremy Lainé <jeremy.la...@m4x.org>
Date:   Mon Aug 4 19:41:48 2014 +0200

    fix hot and cold plugging (from Fedora)

diff --git a/debian/gpsdctl@.service b/debian/gpsdctl@.service
new file mode 100644
index 0000000..d528ddc
--- /dev/null
+++ b/debian/gpsdctl@.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Manage %I for GPS daemon
+Requires=gpsd.socket
+BindsTo=dev-%i.device
+After=dev-%i.device
+
+[Service]
+Type=oneshot
+EnvironmentFile=-/etc/default/gpsd
+RemainAfterExit=yes
+ExecStart=/bin/sh -c "[ \"$USBAUTO\" = true ] && /usr/sbin/gpsdctl add /dev/%I || :"
+ExecStop=/bin/sh -c "[ \"$USBAUTO\" = true ] && /usr/sbin/gpsdctl remove /dev/%I || :"
diff --git a/debian/rules b/debian/rules
index 57b6e3f..12c7307 100755
--- a/debian/rules
+++ b/debian/rules
@@ -167,14 +167,11 @@ install-stamp: build-stamp build-static-stamp $(LIBGPS_DEBIAN_FILE_TARGETS)
 	    done
 	# install static lib
 	cp static_lib/libgps.a debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)
-	# install hotplug wrapper
-	mkdir -p debian/tmp/lib/udev
-	cp gpsd.hotplug debian/tmp/lib/udev
-	chmod 755 debian/tmp/lib/udev/gpsd.hotplug
 	cp INSTALL TROUBLESHOOTING
 	# install systemd files
 	mkdir -p debian/tmp/lib/systemd/system
 	cp systemd/* debian/tmp/lib/systemd/system
+	cp debian/gpsdctl@.service debian/tmp/lib/systemd/system
 	# fix various manpages
 	for i in cgps.1 gegps.1 lcdgps.1 xgps.1 xgpsspeed.1 gpxlogger.1; do \
 	    rm -f debian/tmp/usr/share/man/man1/$$i ;\
@@ -219,7 +216,8 @@ binary: install-stamp
 	dh_python2 -pgpsd-dbg usr/lib/gpsd/debug
 	dh_python2 -pgpsd-clients /usr/bin
 	dh_python2 -pgpsd /lib/udev/
-	cp $(CURDIR)/gpsd.rules $(CURDIR)/debian/gpsd.udev
+	# Use gpsdctl service instead of hotplug script
+	sed 's|RUN+="/lib/udev/gpsd.hotplug"|TAG+="systemd", ENV{SYSTEMD_WANTS}="gpsdctl@%k.service"|' $(CURDIR)/gpsd.rules > $(CURDIR)/debian/gpsd.udev
 	dh_installudev 
 	dh_link 
 	dh_strip  --dbg-package=$(PACKAGE_GPSDDBG)

Reply via email to