Skip to content

Commit a2f32e4

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 fa1c11f commit a2f32e4

7 files changed

Lines changed: 194 additions & 516 deletions

File tree

package/feature-gps/25-gpsd.rules

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,59 +7,60 @@ 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 port (QEMU emulated GPS for testing)
66+
SUBSYSTEM=="virtio-ports", ATTR{name}=="gps0", SYMLINK+="gps0"

src/confd/src/hardware.c

Lines changed: 69 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;
@@ -708,13 +712,74 @@ int hardware_change(sr_session_ctx_t *session, struct lyd_node *config, struct l
708712
wifi_iface_list = NULL;
709713
wifi_iface_count = 0;
710714
} else if (!strcmp(class, "infix-hardware:gps")) {
711-
if (event != SR_EV_DONE)
712-
continue;
713-
714-
systemf("initctl -nbq touch statd");
715+
gps_changed = 1;
715716
}
716717
}
717718

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

720785
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)