Skip to contentSkip to conversation

do not allow multiple xenconsole connect to the same pty

PATCH New Li Dongyang 1 participant 1 message Feb 15, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 do not allow multiple xenconsole connect to the same pty

allowing multiple xenconsole connect to the same pty is just insane, prevent this by acquiring a write flock on the pty fd once we opened it.

tools/console/client/main.c +7 -0
diff -r c64dcc4d2eca -r 08ea56ee1b70 tools/console/client/main.c
@@ -96,6 +96,7 @@
  * Assumes there is already a watch set in the store for this path. */
 {
 	struct timeval tv;
+	struct flock lock;
 	fd_set watch_fdset;
 	int xs_fd = xs_fileno(xs), pty_fd = -1;
 	int start, now;
@@ -122,6 +123,12 @@
 				if (pty_fd == -1) 
 					err(errno, "Could not open tty `%s'", 
 					    pty_path);
+				memset(&lock, 0, sizeof(lock));
+				lock.l_type = F_WRLCK;
+				lock.l_whence = SEEK_SET;
+				if (fcntl(pty_fd, F_SETLK, &lock) != 0)
+					err(errno, "Could not lock tty '%s'",
+					    pty_path);
 				free(pty_path);
 			}
 		}