Skip to content

Commit 59698db

Browse files
committed
GPS: Refactor, do not use hotplug depend and move to finit
Also remove caching of GPS data in operational, gpsd now depend on its GPS device <dev/gps0> instead of hotplug magic.
1 parent 0133532 commit 59698db

11 files changed

Lines changed: 267 additions & 532 deletions

File tree

package/feature-gps/25-gpsd.rules

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,61 @@ SUBSYSTEM!="tty", GOTO="gpsd_rules_end"
77

88
# Prolific Technology, Inc. PL2303 Serial Port [linux module: pl2303]
99
# !!! rule disabled in Debian as it matches too many other devices
10-
# ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
10+
# ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="gps%n"
1111
# ATEN International Co., Ltd UC-232A Serial Port [linux module: pl2303]
12-
ATTRS{idVendor}=="0557", ATTRS{idProduct}=="2008", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
12+
ATTRS{idVendor}=="0557", ATTRS{idProduct}=="2008", SYMLINK+="gps%n"
1313

1414
# PS-360 OEM (GPS sold with MS Street and Trips 2005) [linux module: pl2303]
15-
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="aaa0", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
15+
ATTRS{idVendor}=="067b", ATTRS{idProduct}=="aaa0", SYMLINK+="gps%n"
1616

1717
# FTDI 8U232AM / FT232 [linux module: ftdi_sio]
1818
# !!! rule disabled in Debian as it matches too many other devices
19-
# ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
19+
# ATTRS{idVendor}=="0403", ATTRS{idProduct}=="6001", SYMLINK+="gps%n"
2020

2121
# Cypress M8/CY7C64013 (Delorme uses these) [linux module: cypress_m8]
22-
ATTRS{idVendor}=="1163", ATTRS{idProduct}=="0100", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
22+
ATTRS{idVendor}=="1163", ATTRS{idProduct}=="0100", SYMLINK+="gps%n"
2323

2424
# Cypress M8/CY7C64013 (DeLorme LT-40)
25-
ATTRS{idVendor}=="1163", ATTRS{idProduct}=="0200", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
25+
ATTRS{idVendor}=="1163", ATTRS{idProduct}=="0200", SYMLINK+="gps%n"
2626

2727
# Garmin International GPSmap, various models (tested with Garmin GPS 18 USB) [linux module: garmin_gps]
28-
ATTRS{idVendor}=="091e", ATTRS{idProduct}=="0003", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
28+
ATTRS{idVendor}=="091e", ATTRS{idProduct}=="0003", SYMLINK+="gps%n"
2929

3030
# Cygnal Integrated Products, Inc. CP210x Composite Device (Used by Holux m241 and Wintec grays2 wbt-201) [linux module: cp210x]
3131
# !!! rule disabled in Debian as it matches too many other devices
32-
#ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
32+
#ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="gps%n"
3333

3434
# Cygnal Integrated Products, Inc. [linux module: cp210x]
3535
# !!! rule disabled in Debian as it matches too many other devices
36-
#ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea71", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
36+
#ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea71", SYMLINK+="gps%n"
3737

3838
# u-blox AG, u-blox 5 (tested with Navilock NL-402U) [linux module: cdc_acm]
39-
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a5", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
39+
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a5", SYMLINK+="gps%n"
4040

4141
# u-blox AG, u-blox 6 (tested with GNSS Evaluation Kit TCXO) [linux module: cdc_acm]
42-
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a6", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
42+
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a6", SYMLINK+="gps%n"
4343

4444
# u-blox AG, u-blox 7 [linux module: cdc_acm]
45-
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a7", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
45+
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a7", SYMLINK+="gps%n"
4646

4747
# u-blox AG, u-blox 8 (tested with GNSS Evaluation Kit EKV-M8N) [linux module: cdc_acm]
48-
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a8", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
48+
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a8", SYMLINK+="gps%n"
4949

5050
# u-blox AG, u-blox 9 (tested with GNSS Evaluation Kit C099-F9P) [linux module: cdc_acm]
51-
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a9", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
51+
ATTRS{idVendor}=="1546", ATTRS{idProduct}=="01a9", SYMLINK+="gps%n"
5252

5353
# MediaTek (tested with HOLUX M-1200E) [linux module: cdc_acm]
54-
ATTRS{idVendor}=="0e8d", ATTRS{idProduct}=="3329", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
54+
ATTRS{idVendor}=="0e8d", ATTRS{idProduct}=="3329", SYMLINK+="gps%n"
5555

5656
# Telit wireless solutions (tested with HE910G) [linux module: cdc_acm]
57-
ATTRS{interface}=="Telit Wireless Module Port", ATTRS{bInterfaceNumber}=="06", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
57+
ATTRS{interface}=="Telit Wireless Module Port", ATTRS{bInterfaceNumber}=="06", SYMLINK+="gps%n"
5858

59-
# u-blox AG, u-blox 8 (tested with u-blox8 GNSS Mouse Receiver / GR-801) [linux module: cdc_acm]
59+
# u-blox AG, u-blox 8 (tested with u-blox8 GNSS Mouse Receiver / GR-801) [linux module: cdc_acm]
6060
# !!! rule disabled in Debian as it matches too many other devices
61-
#ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="gps%n", RUN+="/usr/lib/udev/gpsd.hotplug"
62-
63-
ACTION=="remove", RUN+="/usr/lib/udev/gpsd.hotplug"
61+
#ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", SYMLINK+="gps%n"
6462

6563
LABEL="gpsd_rules_end"
64+
65+
# Virtio serial GPS ports (QEMU emulated GPS for testing)
66+
SUBSYSTEM=="virtio-ports", ATTR{name}=="gps0", SYMLINK+="gps0"
67+
SUBSYSTEM=="virtio-ports", ATTR{name}=="gps1", SYMLINK+="gps1"

package/feature-gps/Config.in

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
config BR2_PACKAGE_FEATURE_GPS
22
bool "Feature GPS/GNSS"
33
select BR2_PACKAGE_GPSD
4-
select BR2_PACKAGE_GPSD_MAX_CLIENT
5-
select BR2_PACKAGE_GPSD_MAX_DEV
6-
select BR2_PACKAGE_GPSD_SQUELCH
74
select BR2_PACKAGE_GPSD_ASHTECH
85
select BR2_PACKAGE_GPSD_EARTHMATE
96
select BR2_PACKAGE_GPSD_EVERMORE

package/feature-gps/feature-gps.mk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,20 @@
66

77
FEATURE_GPS_PACKAGE_VERSION = 1.0
88
FEATURE_GPS_PACKAGE_LICENSE = MIT
9+
FEATURE_GPS_DEPENDENCIES += gpsd
910

1011
define FEATURE_GPS_INSTALL_TARGET_CMDS
1112
$(INSTALL) -D -m 0644 $(FEATURE_GPS_PKGDIR)/gpsd.default \
1213
$(TARGET_DIR)/etc/default/gpsd
14+
endef
15+
16+
# Install custom udev rules as a gpsd post-install hook to ensure
17+
# they are not overwritten by gpsd during parallel or incremental builds.
18+
define FEATURE_GPS_INSTALL_UDEV_RULES
1319
$(INSTALL) -D -m 0644 $(FEATURE_GPS_PKGDIR)/25-gpsd.rules \
1420
$(TARGET_DIR)/usr/lib/udev/rules.d/25-gpsd.rules
1521
endef
22+
GPSD_POST_INSTALL_TARGET_HOOKS += FEATURE_GPS_INSTALL_UDEV_RULES
1623

1724
define FEATURE_GPS_LINUX_CONFIG_FIXUPS
1825
$(call KCONFIG_SET_OPT,CONFIG_USB_ACM,m)
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
From 9ba3bc688c45a0c9e761c6c8bd0be83d6570c9dc Mon Sep 17 00:00:00 2001
2+
From: =?UTF-8?q?Mattias=20Walstr=C3=B6m?= <lazzer@gmail.com>
3+
Date: Fri, 27 Feb 2026 16:58:12 +0100
4+
Subject: [PATCH] Always log to syslog
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
Organization: Wires
9+
10+
Signed-off-by: Mattias Walström <lazzer@gmail.com>
11+
---
12+
gpsd/libgpsd_core.c | 13 ++-----------
13+
1 file changed, 2 insertions(+), 11 deletions(-)
14+
15+
diff --git a/gpsd/libgpsd_core.c b/gpsd/libgpsd_core.c
16+
index 982f822b8..c53c64838 100644
17+
--- a/gpsd/libgpsd_core.c
18+
+++ b/gpsd/libgpsd_core.c
19+
@@ -180,17 +180,8 @@ static void gpsd_vlog(const int errlevel,
20+
// this was crazy expensive, just fix the bad log calls
21+
// gps_visibilize(outbuf, outlen, buf, strlen(buf));
22+
23+
- if (getpid() == getsid(getpid())) {
24+
- // I think this calls syslog() only when daemonized
25+
- syslog(level, "%s", outbuf);
26+
- } else if (NULL != errout->report) {
27+
- // we are a thread, use report()?
28+
- // FIXME: is POSIX syslog() thread safe?
29+
- errout->report(outbuf);
30+
- } else {
31+
- // foreground, use stderr?
32+
- (void)fputs(outbuf, stderr);
33+
- }
34+
+ // always log to syslog, even with -N
35+
+ syslog(level, "%s", outbuf);
36+
gpsd_release_reporting_lock();
37+
#endif // !SQUELCH_ENABLE
38+
}
39+
--
40+
2.43.0
41+

src/confd/src/hardware.c

Lines changed: 71 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#define XPATH_BASE_ "/ietf-hardware:hardware"
1818
#define HOSTAPD_CONF "/etc/hostapd-%s.conf"
1919
#define HOSTAPD_CONF_NEXT HOSTAPD_CONF"+"
20+
#define GPSD_CONF "/etc/finit.d/available/gpsd.conf"
21+
#define GPSD_CONF_NEXT GPSD_CONF"+"
22+
#define GPSD_MAX_DEVICES 4
2023

2124
static int dir_cb(const char *fpath, const struct stat *sb, int typeflag, struct FTW *ftwbuf)
2225
{
@@ -593,6 +596,7 @@ int hardware_change(sr_session_ctx_t *session, struct lyd_node *config, struct l
593596
{
594597
struct lyd_node *difs = NULL, *dif = NULL;
595598
int rc = SR_ERR_OK;
599+
int gps_changed = 0;
596600

597601
if (!lydx_find_xpathf(diff, XPATH_BASE_))
598602
return SR_ERR_OK;
@@ -707,13 +711,76 @@ int hardware_change(sr_session_ctx_t *session, struct lyd_node *config, struct l
707711
wifi_iface_count = 0;
708712
}
709713
} else if (!strcmp(class, "infix-hardware:gps")) {
710-
if (event != SR_EV_DONE)
711-
continue;
712-
713-
systemf("initctl -nbq touch statd");
714+
gps_changed = 1;
714715
}
715716
}
716717

718+
if (gps_changed) {
719+
const char *gps_names[GPSD_MAX_DEVICES] = { NULL };
720+
struct lyd_node *cifs, *comp;
721+
int num_gps = 0;
722+
723+
switch (event) {
724+
case SR_EV_UPDATE:
725+
case SR_EV_ENABLED:
726+
case SR_EV_RPC:
727+
break;
728+
729+
case SR_EV_ABORT:
730+
unlink(GPSD_CONF_NEXT);
731+
break;
732+
733+
case SR_EV_CHANGE:
734+
cifs = lydx_get_descendant(config, "hardware", "component", NULL);
735+
LYX_LIST_FOR_EACH(cifs, comp, "component") {
736+
const char *cls = lydx_get_cattr(comp, "class");
737+
738+
if (strcmp(cls, "infix-hardware:gps"))
739+
continue;
740+
if (num_gps < GPSD_MAX_DEVICES)
741+
gps_names[num_gps] = lydx_get_cattr(comp, "name");
742+
else
743+
return SR_ERR_INTERNAL;
744+
num_gps++;
745+
}
746+
if (num_gps > 0) {
747+
FILE *fp;
748+
749+
fp = fopen(GPSD_CONF_NEXT, "w");
750+
if (!fp) {
751+
ERROR("Could not open " GPSD_CONF_NEXT);
752+
return SR_ERR_INTERNAL;
753+
}
754+
int i;
755+
756+
fprintf(fp, "# Generated by confd, do not edit.\n");
757+
fprintf(fp, "service");
758+
fprintf(fp, " <!");
759+
for (i = 0; i < num_gps && i < GPSD_MAX_DEVICES; i++)
760+
fprintf(fp, "%sdev/%s", i ? "," : "", gps_names[i]);
761+
fprintf(fp, ">");
762+
fprintf(fp, " pid:!/run/gpsd.pid");
763+
fprintf(fp, " env:-/etc/default/gpsd \\\n");
764+
fprintf(fp, "\t[2345] gpsd -n");
765+
for (i = 0; i < num_gps && i < GPSD_MAX_DEVICES; i++)
766+
fprintf(fp, " /dev/%s", gps_names[i]);
767+
fprintf(fp, " -P /run/gpsd.pid -- GPS Daemon\n");
768+
fclose(fp);
769+
}
770+
break;
771+
772+
case SR_EV_DONE:
773+
if (fexist(GPSD_CONF_NEXT)) {
774+
unlink(GPSD_CONF);
775+
rename(GPSD_CONF_NEXT, GPSD_CONF);
776+
systemf("initctl -nbq enable gpsd");
777+
} else {
778+
unlink(GPSD_CONF);
779+
systemf("initctl -nbq disable gpsd");
780+
}
781+
break;
782+
}
783+
}
717784
err:
718785

719786
return rc;

src/statd/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ DISTCLEANFILES = *~ *.d
22
ACLOCAL_AMFLAGS = -I m4
33

44
sbin_PROGRAMS = statd
5-
statd_SOURCES = statd.c shared.c shared.h journal.c journal_retention.c journal.h gpsd.c gpsd.h
5+
statd_SOURCES = statd.c shared.c shared.h journal.c journal_retention.c journal.h
66
statd_CPPFLAGS = -D_DEFAULT_SOURCE -D_GNU_SOURCE
77
statd_CFLAGS = -W -Wall -Wextra
88
statd_CFLAGS += $(jansson_CFLAGS) $(libyang_CFLAGS) $(sysrepo_CFLAGS)

0 commit comments

Comments
 (0)