summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-01-10 11:14:06 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-01-10 11:14:06 -0500
commit97f62022a64456ca3b49cb3dfc242d8b4c02adfb (patch)
tree16bbe8f515feaa1887f99446540fd998498bf68f
parent32e99f3888c6b5690bb7ee18a6e6ad9ff1a3f87d (diff)
downloadgpsd-97f62022a64456ca3b49cb3dfc242d8b4c02adfb.tar.gz
Block other processes from using our serial devices while we have them open.
Also, make a multiple-open exception for ptys. Otherwise our regression-test framework goes bust.
-rw-r--r--serial.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/serial.c b/serial.c
index 75effe1b..d2bb3665 100644
--- a/serial.c
+++ b/serial.c
@@ -5,6 +5,7 @@
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/ioctl.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
@@ -372,7 +373,13 @@ int gpsd_open(struct gps_device_t *session)
#endif /* BLUEZ */
{
#ifdef __linux__
- if (anyopen(session->gpsdata.dev.path)) {
+ /*
+ * Don't touch devices already opened by another process. We
+ * have to make an exception for ptys, which are intentionally
+ * opened by nother process on the master side, otherwise we'll
+ * break all our regression tests.
+ */
+ if (session->sourcetype != source_pty && anyopen(session->gpsdata.dev.path)) {
gpsd_report(LOG_ERROR,
"%s already opened by another process\n",
session->gpsdata.dev.path);
@@ -397,6 +404,13 @@ int gpsd_open(struct gps_device_t *session)
}
}
+ /*
+ * Try to block other processes from using this device while we
+ * have it open (later opens should return EBUSY). Won't work
+ * against anything with root privileges, alas.
+ */
+ (void)ioctl(session->gpsdata.gps_fd, TIOCEXCL);
+
#ifdef FIXED_PORT_SPEED
session->saved_baud = FIXED_PORT_SPEED;
#endif