From 97f62022a64456ca3b49cb3dfc242d8b4c02adfb Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 10 Jan 2011 11:14:06 -0500 Subject: 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. --- serial.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'serial.c') diff --git a/serial.c b/serial.c index 75effe1b..d2bb3665 100644 --- a/serial.c +++ b/serial.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -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 -- cgit v1.2.1