diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2011-03-23 19:57:23 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2011-03-23 19:57:23 -0400 |
commit | ad026c269991cf552eb4f9f165c6283abc6b6d3d (patch) | |
tree | b207fd8fe7075f7f75c2286762ca1f21831a6595 /ntpshm.c | |
parent | 3f25d3ca832c25889fd8910665ad257c7a19cd93 (diff) | |
download | gpsd-ad026c269991cf552eb4f9f165c6283abc6b6d3d.tar.gz |
Add some explanatory comments about where root privs are needed.
Add conditioned-out code as a demonstration of how to spin the thread
inexpensively until a device is open.
Diffstat (limited to 'ntpshm.c')
-rw-r--r-- | ntpshm.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -434,7 +434,7 @@ static int init_kernel_pps(struct gps_device_t *session) { gpsd_report(LOG_INF, "KPPS gps_fd not a tty\n"); return -1; } - /* Attach the line PPS discpline, so no need to ldattach */ + /* Attach the line PPS discipline, so no need to ldattach */ /* This activates the magic /dev/pps0 device */ if ( 0 > ioctl(session->gpsdata.gps_fd, TIOCSETD, &ldisc)) { gpsd_report(LOG_INF, "KPPS cannot set PPS line discipline: %d\n" @@ -442,7 +442,6 @@ static int init_kernel_pps(struct gps_device_t *session) { return -1; } - /* uh, oh, magic file names!, this is not how RFC2783 was designed */ /* need to look in /sys/devices/virtual/pps/pps?/path * (/sys/class/pps/pps?/path is just a link to that) @@ -484,12 +483,14 @@ static int init_kernel_pps(struct gps_device_t *session) { /* contruct the magic device path */ (void)snprintf(path, sizeof(path), "/dev/pps%c", pps_num); + /* root privs are required for this device open */ int ret = open(path, O_RDWR); if ( 0 > ret ) { gpsd_report(LOG_INF, "KPPS cannot open %s: %d\n" , path, errno); return -1; } + /* root privs are not required past this point */ if ( 0 > time_pps_create(ret, &kernelpps_handle )) { gpsd_report(LOG_INF, "KPPS time_pps_create(%d,) failed: %d\n" @@ -517,7 +518,7 @@ static int init_kernel_pps(struct gps_device_t *session) { } return kernelpps_handle; } -#endif +#endif /* defined(HAVE_SYS_TIMEPPS_H) */ /*@-mustfreefresh -type@ -unrecog*/ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) @@ -579,6 +580,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) * /tmp/chrony.ttyXX.sock */ + /* root privs are required for this device open */ chronyfd = socket(AF_UNIX, SOCK_DGRAM, 0); if (chronyfd < 0) { gpsd_report(LOG_PROG, "PPS can not open chrony socket: %s\n", @@ -594,7 +596,17 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) /* end chrony */ +#ifdef __UNUSED__ + /* wait for the session to go active - makes this safe to call early */ + while (session->gpsdata.gps_fd == -1) { + /* should probably remove this one code is verified */ + gpsd_report(LOG_PROG, "PPS thread awaiting device activation\n"); + (void)sleep(1); + } +#endif /* __UNUSED__ */ + #if defined(HAVE_SYS_TIMEPPS_H) + /* some operations in init_kernel_pps() require root privs */ int kernelpps_handle = init_kernel_pps( session ); if ( 0 <= kernelpps_handle ) { gpsd_report(LOG_WARN, "KPPS kernel PPS will be used\n"); |