From a8530221aa3e2d0d6feb991ebc9e2e25e2fd0d09 Mon Sep 17 00:00:00 2001 From: Aminda Suomalainen Date: Fri, 19 Jul 2024 10:13:55 +0300 Subject: [PATCH] systemd: move gpsd nmea socket from gpsd to geoclue --- etc/geoclue/conf.d/gpsd.conf | 4 ++-- .../system/geoclue.service.d/gpsd-socket.conf | 21 +++++++++++++++++++ .../gpsd.service.d/aminda-additions.conf | 7 ------- 3 files changed, 23 insertions(+), 9 deletions(-) create mode 100644 etc/systemd/system/geoclue.service.d/gpsd-socket.conf diff --git a/etc/geoclue/conf.d/gpsd.conf b/etc/geoclue/conf.d/gpsd.conf index b7479262..db7ab919 100644 --- a/etc/geoclue/conf.d/gpsd.conf +++ b/etc/geoclue/conf.d/gpsd.conf @@ -1,4 +1,4 @@ [network-nmea] enable=true -# Refer to ../../systemd/system/gpsd.service.d/aminda-additions.conf -nmea-socket=/var/run/gps-share.sock +# Refer to ../../systemd/system/geoclue.service.d/gpsd-socket.conf +nmea-socket=/tmp/gps-share.sock diff --git a/etc/systemd/system/geoclue.service.d/gpsd-socket.conf b/etc/systemd/system/geoclue.service.d/gpsd-socket.conf new file mode 100644 index 00000000..c9315203 --- /dev/null +++ b/etc/systemd/system/geoclue.service.d/gpsd-socket.conf @@ -0,0 +1,21 @@ +# systemd drop-in for ensuring geoclue has a socket to get GPS location from + +# Weak dependency of geoclue pulling gpsd on so gpspipe might work? +[Unit] +Wants=gpsd.service gpsd.socket + +# NOTE: /tmp is not /tmp, because the unit has systemd PrivateTmp. And +# SELINUX dislikes this, so +# ausearch -c 'geoclue' --raw | audit2allow -M my-geoclue +# semodule -X 300 -i my-geoclue.pp + +[Service] +# Handle failure situation of the socket not going away (ExecStartPost=) +ExecStartPre=-/tmp/gps-share.sock +# Creating a socket for geoclue to connect to +# Credit: @schnell at https://gitlab.freedesktop.org/geoclue/geoclue/-/issues/145#note_1772702 +ExecStartPost=/bin/sh -c "(gpspipe --nmea | ( read; read; read; cat ) | ncat --verbose --keep-open --listen --unixsock /tmp/gps-share.sock&)" +# In case of clean shutdown, remove the socket for restart +ExecStopPost=-/usr/bin/rm -vf /tmp/gps-share.sock + +# vim: filetype=systemd diff --git a/etc/systemd/system/gpsd.service.d/aminda-additions.conf b/etc/systemd/system/gpsd.service.d/aminda-additions.conf index 59a4c8f4..de79b941 100644 --- a/etc/systemd/system/gpsd.service.d/aminda-additions.conf +++ b/etc/systemd/system/gpsd.service.d/aminda-additions.conf @@ -6,17 +6,10 @@ Type=exec EnvironmentFile=-/etc/gpsd.aminda.conf # Kernel module possibly required for USB GPS devices especially with Chrony? ExecStartPre=-/usr/sbin/modprobe pps_ldisc -# Handle failure situation of the socket not going away (ExecStartPost=) -ExecStartPre=-/usr/bin/rm -vf /var/run/gps-share.sock # Empty ExecStart= before the actual ExecStart= removes the original # ExecStart= line ExecStart= ExecStart=/usr/sbin/gpsd /dev/gps0 --nowait --foreground $AMINDAGPSD -# Creating a socket for geoclue to connect to -# Credit: @schnell at https://gitlab.freedesktop.org/geoclue/geoclue/-/issues/145#note_1772702 -ExecStartPost=/bin/sh -c "(sleep 5 && gpspipe --nmea | ( read; read; read; cat ) | ncat --verbose --keep-open --listen --unixsock /var/run/gps-share.sock&)" -# In case of clean shutdown, remove the socket for restart -ExecStopPost=-/usr/bin/rm -vf /var/run/gps-share.sock # Missing from the original unit, will reconnect all GPS says man gpsd ExecReload=/usr/bin/killall -HUP gpsd # Avoiding systemd considering the unit as failed.