From: Li Dongyang Subject: [PATCH]do not allow multiple xenconsole connect to the same pty Date: Tue, 15 Feb 2011 12:07:38 +0800 Message-ID: <201102151207.38331.lidongyang@novell.com> Mime-Version: 1.0 Content-Type: Text/Plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xensource.com Errors-To: xen-devel-bounces@lists.xensource.com To: xen-devel@lists.xensource.com List-Id: xen-devel@lists.xenproject.org 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. Signed-off-by: Li Dongyang diff -r c64dcc4d2eca -r 08ea56ee1b70 tools/console/client/main.c --- a/tools/console/client/main.c Thu Feb 10 17:24:41 2011 +0000 +++ b/tools/console/client/main.c Tue Feb 15 12:00:21 2011 +0800 @@ -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); } }