Lines Matching +full:pps +full:- +full:channel
2 * ntp_ppsdev.c - PPS-device support
6 * ---------------------------------------------------------------------
7 * Helper code to work around (or with) a Linux 'specialty': PPS devices
8 * are created via attaching the PPS line discipline to a TTY. This
9 * creates new pps devices, and the PPS API is *not* available through
12 * Findig the PPS device associated with a TTY is possible but needs
17 * the device or symlink to the PPS device with the given name exists,
19 * ---------------------------------------------------------------------
40 /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
43 /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
67 /* ------------------------------------------------------------------ */
79 if (NULL != pxdir->dir) in xdirClose()
80 closedir(pxdir->dir); /* closes the internal FD, too! */ in xdirClose()
81 else if (-1 != pxdir->dfd) in xdirClose()
82 close(pxdir->dfd); /* otherwise _we_ have to do it */ in xdirClose()
83 pxdir->dfd = -1; in xdirClose()
84 pxdir->dir = NULL; in xdirClose()
95 * it's ok to keep the value around -- even if we should do in xdirOpenAt()
99 pxdir->dir = NULL; in xdirOpenAt()
100 if (-1 == (pxdir->dfd = openat(fdo, path, OModeD))) in xdirOpenAt()
102 if (NULL == (pxdir->dir = fdopendir(pxdir->dfd))) in xdirOpenAt()
111 /* --------------------------------------------------------------------
116 * of 4096 bytes when you 'stat' them -- but reading gives EOF after a
130 if (-1 == (dfd = openat(rfd, path, OModeF)) || -1 == fstat(dfd, &sb)) in readFileAt()
138 while (rdlen > 0 && ret[rdlen - 1] <= ' ') in readFileAt()
139 --rdlen; in readFileAt()
145 if (-1 != dfd) in readFileAt()
150 /* --------------------------------------------------------------------
167 if (-1 == fstatat(xdir.dfd, dent->d_name, in findDevByDevId()
173 if (-1 == asprintf(&name, "/dev/%s", dent->d_name)) in findDevByDevId()
183 /* --------------------------------------------------------------------
197 if (-1 != fstat(fd, psb)) { in getCharDevId()
198 rc = S_ISCHR(psb->st_mode); in getCharDevId()
200 *out = psb->st_rdev; in getCharDevId()
207 /* --------------------------------------------------------------------
208 * given the dir-fd of a pps instance dir in the linux sysfs tree, get
209 * the device IDs for the PPS device and the associated TTY.
227 if ((-1 == stat(bufp, &sb)) || !S_ISCHR(sb.st_mode)) in getPpsTuple()
232 /* 'dev' holds the device ID of the PPS device as 'major:minor' in getPpsTuple()
234 * the PPS device itself, as in 'path' above??? But nooooo.... in getPpsTuple()
252 /* --------------------------------------------------------------------
253 * for a given (TTY) device id, lookup the corresponding PPS device id
256 * ouput parameter to the PPS dev id and return true...
269 if (!xdirOpenAt(&ClassDir, AT_FDCWD, "/sys/class/pps")) in findPpsDevId()
274 /* If the entry is not a referring to a PPS device or in findPpsDevId()
277 if (strncmp("pps", dent->d_name, 3)) in findPpsDevId()
279 fdDevDir = openat(ClassDir.dfd, dent->d_name, OModeD); in findPpsDevId()
280 if (-1 == fdDevDir) in findPpsDevId()
299 /* --------------------------------------------------------------------
300 * Return the path to a PPS device related to tghe TT fd given. The
301 * function might even try to instantiate such a PPS device when
302 * running es effective root. Returns NULL if no PPS device can be
319 /* If we find a matching PPS device ID, return the path to the in findMatchingPpsDev()
328 /* 'magic' PPS support -- try to instantiate missing PPS devices in findMatchingPpsDev()
329 * on-the-fly. Our mileage may vary -- running as root at that in findMatchingPpsDev()
330 * moment is vital for success. (We *can* create the PPS device in findMatchingPpsDev()
334 /* If we're root, try to push the PPS LDISC to the tty FD. If in findMatchingPpsDev()
337 if ((0 != geteuid()) || (-1 == ioctl(fdtty, TIOCSETD, &ldisc))) in findMatchingPpsDev()
339 msyslog(LOG_INFO, "auto-instantiated PPS device for device %u:%u", in findMatchingPpsDev()
342 /* We really should find a matching PPS device now. And since in findMatchingPpsDev()
352 * PPS device. If that does not work, we just have to live with in findMatchingPpsDev()
355 if (-1 == (fdpps = open(dpath, OModeF))) { in findMatchingPpsDev()
356 msyslog(LOG_ERR, "could not open auto-created '%s': %m", dpath); in findMatchingPpsDev()
359 if (-1 == fchmod(fdpps, sb.st_mode)) { in findMatchingPpsDev()
360 msyslog(LOG_ERR, "could not chmod auto-created '%s': %m", dpath); in findMatchingPpsDev()
362 if (-1 == fchown(fdpps, sb.st_uid, sb.st_gid)) { in findMatchingPpsDev()
363 msyslog(LOG_ERR, "could not chown auto-created '%s': %m", dpath); in findMatchingPpsDev()
375 /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
376 #endif /* linux PPS device matcher */
377 /* -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- */
384 int ttyfd , /* current tty FD, or -1 */ in ppsdev_reopen()
385 int ppsfd , /* current pps FD, or -1 */ in ppsdev_reopen()
386 const char *ppspath, /* path to pps device, or NULL */ in ppsdev_reopen()
387 int omode , /* open mode for pps device */ in ppsdev_reopen()
388 int oflags ) /* openn flags for pps device */ in ppsdev_reopen()
390 int retfd = -1; in ppsdev_reopen()
404 if (-1 == retfd) { in ppsdev_reopen()
408 ppspath, (retfd != -1 ? "succeeded" : "failed")); in ppsdev_reopen()
414 if ((-1 == retfd) && (-1 != ttyfd)) { in ppsdev_reopen()
419 xpath, (retfd != -1 ? "succeeded" : "failed")); in ppsdev_reopen()
425 /* BSDs and probably SOLARIS can use the TTY fd for the PPS API, in ppsdev_reopen()
426 * and so does Windows where the PPS API is implemented via an in ppsdev_reopen()
431 if (-1 == retfd) in ppsdev_reopen()
433 if (-1 == retfd) in ppsdev_reopen()
436 /* Close the old pps FD, but only if the new pps FD is neither in ppsdev_reopen()
437 * the tty FD nor the existing pps FD! in ppsdev_reopen()
447 int ttyfd, /* current tty FD, or -1 */ in ppsdev_close()
448 int ppsfd) /* current pps FD, or -1 */ in ppsdev_close()
450 /* The pps fd might be the same as the tty fd. We close the pps in ppsdev_close()
451 * channel only if it's valid and _NOT_ the tty itself: in ppsdev_close()
453 if ((-1 != ppsfd) && (ttyfd != ppsfd)) in ppsdev_close()
456 /* --*-- that's all folks --*-- */