serial: Open devie in non-blocking mode and then switch to blocking

There are some serial ports that apparently block during the open in
some circumstances.  We don't want that.  We want to either open it
immediately, or fail fast.

Change-Id: I626b138574bc50f4f4b09c4d609f3623ff512dff
This commit is contained in:
Harald Welte 2016-12-23 22:49:39 +01:00
parent a0f74f218b
commit 1db37820aa
1 changed files with 17 additions and 3 deletions

View File

@ -59,16 +59,30 @@
int
osmo_serial_init(const char *dev, speed_t baudrate)
{
int rc, fd=0, v24;
int rc, fd=0, v24, flags;
struct termios tio;
/* Open device */
fd = open(dev, O_RDWR | O_NOCTTY);
/* Use nonblock as the device might block otherwise */
fd = open(dev, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK);
if (fd < 0) {
dbg_perror("open");
return -errno;
}
/* now put it into blcoking mode */
flags = fcntl(fd, F_GETFL, 0);
if (flags < 0) {
dbg_perror("fcntl get flags");
return -1;
}
flags &= ~O_NONBLOCK;
rc = fcntl(fd, F_SETFL, flags);
if (rc != 0) {
dbg_perror("fcntl set flags");
return -1;
}
/* Configure serial interface */
rc = tcgetattr(fd, &tio);
if (rc < 0) {