diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-02-02 12:23:29 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-02-02 12:23:29 -0500 |
commit | ef39b1cd848a006751b1d30c931056a5790e3116 (patch) | |
tree | e43e1f9872ecbe62b0e5459e6ecff4b46d821f16 /serial.c | |
parent | 4ef555df8055cf12f23530e18e3bfdd51d20e26f (diff) | |
download | gpsd-ef39b1cd848a006751b1d30c931056a5790e3116.tar.gz |
Now we open with nonblock, set CLOCAL, and then turn off nonblock.
All regression tests pass.
Diffstat (limited to 'serial.c')
-rw-r--r-- | serial.c | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -457,18 +457,23 @@ int gpsd_serial_open(struct gps_device_t *session) } else #endif /* BLUEZ */ { + /* + * We open with O_NONBLOCK because we want to now get hung if + * the clocal flag is off, but we don't want to stay in that mode. + */ if ((session->gpsdata.gps_fd = - open(session->gpsdata.dev.path, (int)(mode | O_NOCTTY))) == -1) { + open(session->gpsdata.dev.path, (int)(mode | O_NONBLOCK | O_NOCTTY))) == -1) { gpsd_report(&session->context->errout, LOG_ERROR, "device open failed: %s - retrying read-only\n", strerror(errno)); if ((session->gpsdata.gps_fd = - open(session->gpsdata.dev.path, O_RDONLY | O_NOCTTY)) == -1) { + open(session->gpsdata.dev.path, O_RDONLY | O_NONBLOCK | O_NOCTTY)) == -1) { gpsd_report(&session->context->errout, LOG_ERROR, "read-only device open failed: %s\n", strerror(errno)); return -1; } + gpsd_report(&session->context->errout, LOG_PROG, "file device open success: %s\n", strerror(errno)); @@ -569,6 +574,14 @@ int gpsd_serial_open(struct gps_device_t *session) ); } + /* Switch back to blocking I/O now that CLOCAL is set. */ + { + int oldfl = fcntl(session->gpsdata.gps_fd, F_GETFL); + if (oldfl != -1) + fcntl(session->gpsdata.gps_fd, F_SETFL, oldfl & ~O_NONBLOCK); + } + + /* required so parity field won't be '\0' if saved speed matches */ if (session->sourcetype <= source_blockdev) { session->gpsdata.dev.parity = 'N'; |