diff options
author | Gary E. Miller <gem@rellim.com> | 2010-12-10 23:12:08 -0800 |
---|---|---|
committer | Gary E. Miller <gem@rellim.com> | 2010-12-10 23:12:08 -0800 |
commit | e17ec6cd98e1014c2294097c2ac71bd0fd329a52 (patch) | |
tree | 4ac97df288f8c746e1d70f31254d530875f04030 /libgpsd_core.c | |
parent | e4df9e0e6ffbb38babd0a2d96c8e42dd2affd3fe (diff) | |
download | gpsd-e17ec6cd98e1014c2294097c2ac71bd0fd329a52.tar.gz |
Allow for multiple chrony sockets.
Some people want to run more than one GPS at a time for time keeping
purposes. This creates a unique chrony socket file name for each GPS.
When run as root, the socket is: /var/run/chrony.ttyXX.sock
When non root the socket is: /tmp/chrony.ttyXX.sock
Diffstat (limited to 'libgpsd_core.c')
-rw-r--r-- | libgpsd_core.c | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/libgpsd_core.c b/libgpsd_core.c index ec6e4df8..ba98f592 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -295,26 +295,34 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) /* open the chrony socket */ struct sockaddr_un s; int chronyfd; - char chrony_path[PATH_MAX]; + char chrony_path[PATH_MAX] = ""; gpsd_report(LOG_PROG, "PPS Create Thread gpsd_ppsmonitor\n"); if( 0 == getuid() ) { /* only root can use /var/run */ - strcpy( chrony_path, "/var/run/chrony.sock"); + strcpy( chrony_path, "/var/run/chrony"); } else { - strcpy( chrony_path, "/tmp/chrony.sock"); + strcpy( chrony_path, "/tmp/chrony"); } /*@i1@*/s.sun_family = AF_UNIX; - (void)snprintf(s.sun_path, sizeof (s.sun_path), "%s", chrony_path); + (void)snprintf(s.sun_path, sizeof (s.sun_path), "%s.%s.sock", chrony_path, + basename(session->gpsdata.dev.path)); + /* the socket will be either, for root: + * /var/run/chrony.ttyXX.sock + * or for non-root: + * /tmp/chrony.ttyXX.sock + */ chronyfd = socket(AF_UNIX, SOCK_DGRAM, 0); if (chronyfd < 0) { - gpsd_report(LOG_PROG, "PPS can not open chrony socket: %s\n", chrony_path); + gpsd_report(LOG_PROG, "PPS can not open chrony socket: %s\n", + s.sun_path); } else if (connect(chronyfd, (struct sockaddr *)&s, sizeof (s))) { (void)close(chronyfd); chronyfd = -1; - gpsd_report(LOG_PROG, "PPS can not connect chrony socket: %s\n", chrony_path); + gpsd_report(LOG_PROG, "PPS can not connect chrony socket: %s\n", + s.sun_path); } /* end chrony */ |