Skip to content

Commit 49a0c6c

Browse files
committed
Refactor gps
1 parent 8fcb118 commit 49a0c6c

5 files changed

Lines changed: 71 additions & 17 deletions

File tree

package/feature-gps/feature-gps.mk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ define FEATURE_GPS_INSTALL_TARGET_CMDS
1212
$(TARGET_DIR)/etc/default/gpsd
1313
$(INSTALL) -D -m 0644 $(FEATURE_GPS_PKGDIR)/25-gpsd.rules \
1414
$(TARGET_DIR)/usr/lib/udev/rules.d/25-gpsd.rules
15-
$(INSTALL) -D -m 0644 $(FEATURE_GPS_PKGDIR)/gpsd.conf \
16-
$(TARGET_DIR)/etc/finit.d/available/gpsd.conf
1715
endef
1816

1917
define FEATURE_GPS_LINUX_CONFIG_FIXUPS

package/feature-gps/gpsd.conf

Lines changed: 0 additions & 4 deletions
This file was deleted.

package/feature-gps/gpsd.default

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
GPSD_OPTIONS="-n /dev/gps0"
1+
GPSD_OPTIONS="-n"

src/confd/src/hardware.c

Lines changed: 69 additions & 7 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,7 +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;
596-
int num_gps = 0;
599+
int gps_changed = 0;
597600

598601
if (!lydx_find_xpathf(diff, XPATH_BASE_))
599602
return SR_ERR_OK;
@@ -709,15 +712,74 @@ int hardware_change(sr_session_ctx_t *session, struct lyd_node *config, struct l
709712
wifi_iface_list = NULL;
710713
wifi_iface_count = 0;
711714
} else if (!strcmp(class, "infix-hardware:gps")) {
712-
if (event != SR_EV_DONE)
713-
continue;
714-
num_gps++;
715-
systemf("initctl -nbq enable gpsd");
715+
gps_changed = 1;
716716
}
717717
}
718718

719-
if (!num_gps && event == SR_EV_DONE)
720-
systemf("initctl -nbq disable gpsd");
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+
}
721783
err:
722784

723785
return rc;

src/statd/statd.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ static int subscribe_to_all(struct statd *statd)
453453

454454
int main(int argc, char *argv[])
455455
{
456-
struct ev_signal sigint_watcher, sigusr1_watcher, sighup_watcher;
456+
struct ev_signal sigint_watcher, sigusr1_watcher;
457457
int log_opts = LOG_PID | LOG_NDELAY;
458458
struct statd statd = {};
459459
const char *env;
@@ -514,8 +514,6 @@ int main(int argc, char *argv[])
514514
sigusr1_watcher.data = &statd;
515515
ev_signal_start(statd.ev_loop, &sigusr1_watcher);
516516

517-
ev_signal_start(statd.ev_loop, &sighup_watcher);
518-
519517
err = journal_start(&statd.journal, statd.sr_query_ses);
520518
if (err) {
521519
sr_session_stop(statd.sr_query_ses);

0 commit comments

Comments
 (0)