summaryrefslogtreecommitdiff
path: root/serial.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-02-02 08:53:44 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-02-02 11:24:54 -0500
commit819093f0604d6cf3a2c08f2baff328543e32afe2 (patch)
tree2cd2d522083559084701807305d63ba50cb9dd1a /serial.c
parent6f16b7ffd45d933e8ad6916d5bad17140384e69c (diff)
downloadgpsd-819093f0604d6cf3a2c08f2baff328543e32afe2.tar.gz
Revert mistaken use of CLOCAL in open(2).
All regression tests pass. Hal Murray thinks we should be opening the device, setting CLOCAL with tcsetattr() , closing it, and reopening. This is a good idea in principle but doing it right will require serious preparatory surgery on the serial.c code. According to StackOverflow, the specific thing CLOCAL does is disable signaling the process on CD drop. The Modem HOWTO says this: Normally a CD (Carrier Detect) signal (on the CD wire for an external modem) is [not] required before a serial port can be opened. But if stty has negated clocal (-clocal), then the port requires CD raised for the port to open and remain open. Actually, a skilled programmer can write the program in such a way as to force the port to open even when CD and clocal say not to. So if stty shows -clocal then there might be a problem with opening the port. But for dial-in, in some cases you may want -clocal so that when the remote modem stops sending a carrier and CD drops, the port will close and terminate all processes running on it. The above is internally inconsistent without the inserted "not". The Gnu C library documentation says: Macro: tcflag_t CLOCAL If this bit is set, it indicates that the terminal is connected "locally" and that the modem status lines (such as carrier detect) should be ignored. On many systems if this bit is not set and you call open without the O_NONBLOCK flag set, open blocks until a modem connection is established. If this bit is not set and a modem disconnect is detected, a SIGHUP signal is sent to the controlling process group for the terminal (if it has one). Normally, this causes the process to exit; see 24. Signal Handling. Reading from the terminal after a disconnect causes an end-of-file condition, and writing causes an EIO error to be returned. The terminal device must be closed and reopened to clear the condition.
Diffstat (limited to 'serial.c')
-rw-r--r--serial.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/serial.c b/serial.c
index dd2c0512..9c4d4c7f 100644
--- a/serial.c
+++ b/serial.c
@@ -458,14 +458,12 @@ int gpsd_serial_open(struct gps_device_t *session)
#endif /* BLUEZ */
{
if ((session->gpsdata.gps_fd =
- open(session->gpsdata.dev.path,
- (int)(mode | CLOCAL | O_NOCTTY))) == -1) {
+ open(session->gpsdata.dev.path, (int)(mode | 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 | CLOCAL | O_NOCTTY)) == -1) {
+ open(session->gpsdata.dev.path, O_RDONLY | O_NOCTTY)) == -1) {
gpsd_report(&session->context->errout, LOG_ERROR,
"read-only device open failed: %s\n",
strerror(errno));