aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/serial.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/src/serial.c b/src/serial.c
index 66ee7564..44032263 100644
--- a/src/serial.c
+++ b/src/serial.c
@@ -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) {