/* * 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; #ifdef O_NONBLOCK char trash[128]; /* litter bin for old input data */ #endif /* * 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); } NTP_INSIST(fd != 0); if (!refclock_setup(fd, speed, lflags)) { close(fd); return (0); } if (!refclock_ioctl(fd, lflags)) { close(fd); return (0); } #ifdef O_NONBLOCK /* * We want to make sure there is no pending trash in the input * buffer. Since we have non-blocking IO available, this is a * good moment to read and dump all available outdated stuff * that might have become toxic for the driver. */ while (read(fd, trash, sizeof(trash)) > 0 || errno == EINTR) /*NOP*/; #endif return (fd); }
/* * 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); }