[LinuxPPS] [RFC] PPS: Implementing LinuxPPS API with new syscalls

Reg Clemens reg at dwf.com
Fri Jun 8 20:59:22 CEST 2007


> 
> All the code I looked at defines the PPS handle as a variable and not
> as a pointer, in fact in NTP tree we have:
> 

>    ntpd/refclock_jupiter.c:	pps_handle_t pps_handle;	/* pps handle 
> 
you missed one thing, t_pps_handle is a typedef (all the t_ things are)

typedef pps_unit_t* pps_handle_t; /* pps handlebars */

as to the actual question here, there are two distinct versions of time_pps_create
floating arround.  The one in Linux assumes that the pointer passed to it in fact
points to some existing location, viz:

        if (time_pps_create(num, &instance->pps_h) < 0) { 
which expects the code

/* create PPS handle from file descriptor */                                                   
static __inline int time_pps_create(int filedes, pps_handle_t *handle)                           
{                                                                                                
       int error;                                                                                
                                                                                                
       error = ioctl(filedes, PPS_IOC_CREATE, 0);                                                
       if (error < 0) {                                                                          
               *handle = -1;                                                                     
               return (-1);                                                                      
       }                                                                                         
       *handle = filedes;                                                                        
       return (0);                                                                               
}                                                                                                

But there are some previous SunOS and FreeBSD versions that DONT expect
the pointer to be pointing at anything, viz

time_pps_create(
        int filedes,            /* file descriptor */
        pps_handle_t *handle    /* ppsapi handle */
        )
{
        /*
         * Check for valid arguments and attach PPS signal.
         */
        if (!handle) {
                errno = EFAULT;
                return (-1);    /* null pointer */
        }

        /*
         * Allocate and initialize default unit structure.
         */
        *handle = malloc(sizeof(pps_unit_t));
        if (!(*handle)) {
                errno = EBADF;
                return (-1);    /* what, no memory? */
        }
        memset(*handle, 0, sizeof(pps_unit_t));
        (*handle)->filedes = filedes;
        (*handle)->params.api_version = PPS_API_VERS_1;
        (*handle)->params.mode = PPS_CAPTUREASSERT | PPS_TSFMT_TSPEC;
        if (ioctl(filedes, PPS_IOC_CREATE, 0) < 0) {
                free(handle);
                return (-1);
        }
        return (0);
}

which allocate space on their own.  So I was wrong on the destroy thing for
Linux.  I have at least 10 old timepps.h file floating around, and I grabbed
the 'wrong one' to look at.  In fact, the previous PPSkit had allocated space
inside the kernel for some of its data, and the destroy function called an
ioctl that released this space.


-- 
                                        Reg.Clemens
                                        reg at dwf.com





More information about the LinuxPPS mailing list