[LinuxPPS] [PATCH] time_pps_readlink()

Udo van den Heuvel udovdh at xs4all.nl
Sat Aug 26 19:14:37 CEST 2006


Rodolfo Giometti wrote:
> On Fri, Aug 25, 2006 at 08:03:51PM +0200, Udo van den Heuvel wrote:
>> --- a/ntpd/refclock_nmea.c      2006-05-22 16:39:06.000000000 +0200
>> +++ b/ntpd/refclock_nmea.c      2006-05-22 16:39:54.000000000 +0200
>> @@ -139,6 +139,9 @@
>>  	register struct nmeaunit *up;
>>  	struct refclockproc *pp;
>>  	int fd;
>> +#ifdef PPS_HAVE_FINDSOURCE
>> +	char id[40], path[40];
> 
> I think is better using "LINUXPPS_MAX_NAME_LEN" define instead of "40"
> (see "ppstest.c").

I guess the valoe of 32 of that constant is OK. Just a long name.. :-)

>> +	/* Get the PPS source's real name */
>> +	time_pps_readlink(link, 40, path, 40);
> 
> Where do you init the "link" variable? In "ppstest.c" I did:

I think this is my big mistake.

>         char id[STRING_LEN] = "",               /* no ID string by default   */
>              path[STRING_LEN],
>              link[STRING_LEN] = "/dev/gps0";    /* just a default device */

I corrected it now.

> Mmm... doing like this is correct but you are using the internal
> rappresentation of "handle" variable. I think you should define
> another variable to be used as open/close flag so you can significally
> reduce the #ifdef lines since the new flag can be used for both
> LinuxPPS and the current PPS API.

Hmmm. I would have to look into that so I can understand what you mean.
Making the patch smaller and smaller and better is a good goal.
Please enlighten.

BTW: ntp 4.2.2p3 now works with the attached patch.

Thanks,
Udo
-------------- next part --------------
--- a/ntpd/refclock_nmea.c      2006-05-22 16:39:06.000000000 +0200
+++ b/ntpd/refclock_nmea.c      2006-05-22 16:39:54.000000000 +0200
@@ -139,6 +139,11 @@
 	register struct nmeaunit *up;
 	struct refclockproc *pp;
 	int fd;
+#ifdef PPS_HAVE_FINDPATH
+	char id[LINUXPPS_MAX_NAME_LEN] = "",
+	     path[LINUXPPS_MAX_NAME_LEN],
+             link[LINUXPPS_MAX_NAME_LEN] = "/dev/gps0";    /* just a default device */
+#endif	/* PPS_HAVE_FINDPATH */
 	char device[20];
 
 	/*
@@ -230,8 +235,24 @@
 	 * Start the PPSAPI interface if it is there. Default to use
 	 * the assert edge and do not enable the kernel hardpps.
 	 */
+#ifdef PPS_HAVE_FINDPATH
+	/* Get the PPS source's real name */
+	time_pps_readlink(link, LINUXPPS_MAX_NAME_LEN, path, LINUXPPS_MAX_NAME_LEN);
+
+	/* Try to find the source */
+	fd = time_pps_findpath(path, LINUXPPS_MAX_NAME_LEN, id, LINUXPPS_MAX_NAME_LEN);
+	if (fd < 0) {
+		msyslog(LOG_ERR, "refclock: cannot find PPS path \"%s\" in the system", path);
+		return 1;
+	}
+	msyslog(LOG_INFO, "refclock: found PPS source \"%s\" at id #%d on \"%s\"", path, fd, id);
+#endif	/* PPS_HAVE_FINDPATH */
 	if (time_pps_create(fd, &up->handle) < 0) {
+#ifdef PPS_HAVE_FINDPATH
+		up->handle.socket = -1;
+#else
 		up->handle = 0;
+#endif	/* PPS_HAVE_FINDPATH */
 		msyslog(LOG_ERR,
 		    "refclock_nmea: time_pps_create failed: %m");
 		return (1);
@@ -257,7 +278,9 @@
 	pp = peer->procptr;
 	up = (struct nmeaunit *)pp->unitptr;
 #ifdef HAVE_PPSAPI
+#ifndef PPS_HAVE_FINDPATH
 	if (up->handle != 0)
+#endif /* PPS_HAVE_FINDPATH */
 		time_pps_destroy(up->handle);
 #endif /* HAVE_PPSAPI */
 	io_closeclock(&pp->io);
@@ -366,7 +389,11 @@
 	/*
 	 * Convert the timespec nanoseconds field to ntp l_fp units.
 	 */ 
+#ifdef PPS_HAVE_FINDPATH
+	if (up->handle.socket == -1)
+#else
 	if (up->handle == 0)
+#endif	/* PPS_HAVE_FINDPATH */
 		return (0);
 	timeout.tv_sec = 0;
 	timeout.tv_nsec = 0;


More information about the LinuxPPS mailing list