WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty
From: Li Dongyang <lidongyang@xxxxxxxxxx>
Date: Tue, 15 Feb 2011 12:07:38 +0800
Delivery-date: Tue, 15 Feb 2011 04:15:56 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: KMail/1.13.6 (Linux/2.6.38-rc4-btrfs+; KDE/4.6.0; x86_64; ; )
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 <lidongyang@xxxxxxxxxx>

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);
                        }
                }

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel