[LinuxPPS] ntpd with nmea.patch fails to compile if HAVE_PPSAPI is not defined
William S. Brasher
billb958 at door.net
Wed Jun 17 21:45:31 CEST 2009
This bit of code added by nmea.patch:
pps_error:
/* No luck, no PPS unit available! */
up->handle = -1;
refers to up->handle which is in the struct only if HAVE_PPSAPI is
defined. It would seem that up->handle should be wrapped in the #ifdef
HAVE_PPSAPI.
The attached patch is what I applied to ntpd and the code compiled with
and without HAVE_PPSAPI defined. The binaries seem to work, too.
-------------- next part --------------
diff -Naur ntp-4.2.4p7.org/ntpd/refclock_nmea.c ntp-4.2.4p7/ntpd/refclock_nmea.c
--- ntp-4.2.4p7.org/ntpd/refclock_nmea.c 2009-03-30 06:03:18.000000000 -0500
+++ ntp-4.2.4p7/ntpd/refclock_nmea.c 2009-06-14 14:42:21.000000000 -0500
@@ -62,6 +62,7 @@
# define DEVICE "COM%d:" /* COM 1 - 3 supported */
#else
# define DEVICE "/dev/gps%d" /* name of radio device */
+# define DEVICEPPS "/dev/pps%d" /* name of alternate PPS radio device */
#endif
#define SPEED232 B4800 /* uart speed (4800 bps) */
#define PRECISION (-9) /* precision assumed (about 2 ms) */
@@ -72,6 +73,7 @@
#define RANGEGATE 500000 /* range gate (ns) */
#define LENNMEA 75 /* min timecode length */
+#define LENPPS PPS_MAX_NAME_LEN
/*
* Tables to compute the ddd of year form icky dd/mm timecode. Viva la
@@ -231,13 +233,25 @@
* Start the PPSAPI interface if it is there. Default to use
* the assert edge and do not enable the kernel hardpps.
*/
- if (time_pps_create(fd, &up->handle) < 0) {
- up->handle = 0;
- msyslog(LOG_ERR,
- "refclock_nmea: time_pps_create failed: %m");
- return (1);
+ msyslog(LOG_ERR, "refclock_nmea: found GPS source \"%s\"", device);
+ if (time_pps_create(pp->io.fd, &up->handle) < 0) {
+ /* Try the alternate PPS device */
+ (void) sprintf(device, DEVICEPPS, unit);
+ msyslog(LOG_ERR, "refclock_nmea: try alternate PPS device \"%s\"", device);
+ fd = open(device, O_RDWR);
+ if (fd < 0)
+ goto pps_error;
+ if (time_pps_create(fd, &up->handle) < 0)
+ goto pps_error;
}
+ else (void) sprintf(device, DEVICE, unit); /* just rebuild device's name */
+ msyslog(LOG_INFO, "refclock_nmea: found PPS source \"%s\"", device);
return(nmea_ppsapi(peer, 0, 0));
+
+pps_error:
+ /* No luck, no PPS unit available! */
+ up->handle = -1;
+ msyslog(LOG_ERR, "refclock_nmea: no PPS devices found at " DEVICE " nor " DEVICEPPS ": %m", unit, unit);
#else
return (1);
#endif /* HAVE_PPSAPI */
@@ -258,7 +272,7 @@
pp = peer->procptr;
up = (struct nmeaunit *)pp->unitptr;
#ifdef HAVE_PPSAPI
- if (up->handle != 0)
+ if (up)
time_pps_destroy(up->handle);
#endif /* HAVE_PPSAPI */
io_closeclock(&pp->io);
@@ -367,7 +381,7 @@
/*
* Convert the timespec nanoseconds field to ntp l_fp units.
*/
- if (up->handle == 0)
+ if (up->handle == -1)
return (0);
timeout.tv_sec = 0;
timeout.tv_nsec = 0;
More information about the LinuxPPS
mailing list