gpsd: add hotplug handling

The 'gpsd' offers the possibility to call the script '/etc/gpsd/device-hook'
when a GPS source was added or removed via gpsdctl.

In addition to the '/etc/gpsd/device-hook' call an event is now triggered
too after the 'gpsd' has started. This allows scripts to configurre 'gpsd'
receivers.

The following events are available for '/etc/hotplug.d/gpsd' scripts:

* ACTIVATE   via '/etc/gpsd/device-hook'
* DEACTIVATE via '/etc/gpsd/device-hook'
* STARTED    via '/etc/init.d/gpsd'

Signed-off-by: Florian Eckert <fe@dev.tdt.de>
This commit is contained in:
Florian Eckert
2025-01-30 11:55:19 +01:00
committed by Florian Eckert
parent 7ca3ffebff
commit d7fae14030
4 changed files with 46 additions and 1 deletions

View File

@@ -9,7 +9,7 @@ include $(TOPDIR)/rules.mk
PKG_NAME:=gpsd
PKG_VERSION:=3.25
PKG_RELEASE:=3
PKG_RELEASE:=4
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=@SAVANNAH/$(PKG_NAME)
@@ -141,6 +141,9 @@ define Package/gpsd/install
$(INSTALL_BIN) ./files/gpsd.init $(1)/etc/init.d/gpsd
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/sbin/gpsd $(1)/usr/sbin/
$(INSTALL_DIR) $(1)/etc/gpsd
$(INSTALL_BIN) ./files/etc/gpsd/device-hook $(1)/etc/gpsd/
endef
define Package/gpsd-clients/install

View File

@@ -0,0 +1,19 @@
#!/bin/sh
main() {
local device="$1"
local action="$2"
case "$action" in
"ACTIVATE")
env -i ACTION="$action" DEVICE="$device" \
/sbin/hotplug-call gpsd
;;
"DEACTIVATE")
env -i ACTION="$action" DEVICE="$device" \
/sbin/hotplug-call gpsd
;;
esac
}
main "$@"

View File

@@ -0,0 +1,14 @@
#!/bin/sh
gps_log() {
local level="$1"; shift
[ "$level" = "debug" ] && return
logger -p "daemon.${level}" -t "gpsd(debug)[$$]" "hotplug: $*"
}
main() {
gps_log info "$(env)"
}
main "$@"

View File

@@ -49,3 +49,12 @@ service_triggers() {
procd_add_reload_trigger "$NAME"
procd_add_validation validate_section_gpsd
}
service_started() {
local enabled
enabled="$(uci_get gpsd core enabled 0)"
[ "$enabled" = "0" ] && return
env -i ACTION="STARTED" /sbin/hotplug-call gpsd
}