[LinuxPPS] PPS/ntpd fails on fresh startup
Luca Bertagnolio
time at berta.com
Wed Oct 15 12:14:26 CEST 2008
On Wed, Oct 15, 2008 at 12:08 PM, Rodolfo Giometti
<giometti at enneenne.com> wrote:
> Luca, what exactly the refclock_open() does with such parameter? And
> how it is defined inside the code?
there you go:
/*
* refclock_open - open serial port for reference clock
*
* This routine opens a serial port for I/O and sets default options. It
* returns the file descriptor if success and zero if failure.
*/
int
refclock_open(
char *dev, /* device name pointer */
u_int speed, /* serial port speed (code) */
u_int lflags /* line discipline flags */
)
{
int fd;
int omode;
/*
* Open serial port and set default options
*/
omode = O_RDWR;
#ifdef O_NONBLOCK
omode |= O_NONBLOCK;
#endif
#ifdef O_NOCTTY
omode |= O_NOCTTY;
#endif
fd = open(dev, omode, 0777);
if (fd < 0) {
msyslog(LOG_ERR, "refclock_open %s: %m", dev);
return (0);
}
if (!refclock_setup(fd, speed, lflags)) {
close(fd);
return (0);
}
if (!refclock_ioctl(fd, lflags)) {
close(fd);
return (0);
}
return (fd);
}
refclock_ioctl is defined as such:
/*
* refclock_ioctl - set serial port control functions
*
* This routine attempts to hide the internal, system-specific details
* of serial ports. It can handle POSIX (termios), SYSV (termio) and BSD
* (sgtty) interfaces with varying degrees of success. The routine sets
* up optional features such as tty_clk. The routine returns 1 if
* success and 0 if failure.
*/
int
refclock_ioctl(
int fd, /* file descriptor */
u_int lflags /* line discipline flags */
)
{
/*
* simply return 1 if no UNIX line discipline is supported
*/
#if !defined SYS_VXWORKS && !defined SYS_WINNT
#if defined(HAVE_TERMIOS) || defined(HAVE_SYSV_TTYS) || defined(HAVE_BSD_TTYS)
#ifdef DEBUG
if (debug)
printf("refclock_ioctl: fd %d flags 0x%x\n", fd,
lflags);
#endif
#ifdef TTYCLK
/*
* The TTYCLK option provides timestamping at the driver level.
* It requires the tty_clk streams module and System V STREAMS
* support. If not available, don't complain.
*/
if (lflags & (LDISC_CLK | LDISC_CLKPPS | LDISC_ACTS)) {
int rval = 0;
if (ioctl(fd, I_PUSH, "clk") < 0) {
msyslog(LOG_NOTICE,
"refclock_ioctl fd %d I_PUSH: %m", fd);
return (0);
#ifdef CLK_SETSTR
} else {
char *str;
if (lflags & LDISC_CLKPPS)
str = "\377";
else if (lflags & LDISC_ACTS)
str = "*";
else
str = "\n";
if (ioctl(fd, CLK_SETSTR, str) < 0) {
msyslog(LOG_ERR,
"refclock_ioctl fd %d CLK_SETSTR: %m", fd);
return (0);
}
#endif /*CLK_SETSTR */
}
}
#endif /* TTYCLK */
#endif /* HAVE_TERMIOS || HAVE_SYSV_TTYS || HAVE_BSD_TTYS */
#endif /* SYS_VXWORKS SYS_WINNT */
return (1);
}
and this is there is some reference to LDISC flags and their use in
the true ioctl.
HTH --L
More information about the LinuxPPS
mailing list