Li Dongyang
2011-Feb-15 04:07 UTC
[Xen-devel] [PATCH]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. Signed-off-by: Li Dongyang <lidongyang@novell.com> 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@lists.xensource.com http://lists.xensource.com/xen-devel
Li Dongyang
2011-Feb-15 07:11 UTC
[Xen-devel] [PATCH]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. Signed-off-by: Li Dongyang <lidongyang@novell.com> 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@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2011-Feb-15 19:40 UTC
Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty
Li Dongyang writes ("[Xen-devel] [PATCH]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.I don''t think that flocking a pty is likely to be very portable. I guess what happens at the moment if you do this is that input is interleaved (fine) but output is distributed randomly amongst the available clients ? Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Alan Cox
2011-Feb-15 19:49 UTC
Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty
On Tue, 15 Feb 2011 19:40:04 +0000 Ian Jackson <Ian.Jackson@eu.citrix.com> wrote:> Li Dongyang writes ("[Xen-devel] [PATCH]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. > > I don''t think that flocking a pty is likely to be very portable. > > I guess what happens at the moment if you do this is that input is > interleaved (fine) but output is distributed randomly amongst the > available clients ?Use POSIX pty interfaces and you don''t get these problems. See grantpt/unlockpt/posix_openpt. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2011-Feb-15 20:04 UTC
Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty
Alan Cox writes ("Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty"):> Use POSIX pty interfaces and you don''t get these problems. See > grantpt/unlockpt/posix_openpt.Thanks for your helpful comment. Unfortunately it''s not really relevant in this situation. What our code is doing is using ptys as an internal IPC mechanism. I think this is very wrong and I hope we can fix it in the Xen 4.2 release cycle. But for now it''s what we have. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Li Dongyang
2011-Feb-17 03:32 UTC
Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty
On Wednesday, February 16, 2011 03:40:04 AM Ian Jackson wrote:> Li Dongyang writes ("[Xen-devel] [PATCH]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. > > I don''t think that flocking a pty is likely to be very portable.Thanks for reviewing, and what do you mean by ''not likely to be very portable''? flock(2) is not POSIX, but fcntl(3p) is POSIX, maybe I missed somthing? Li Dongyang> > I guess what happens at the moment if you do this is that input is > interleaved (fine) but output is distributed randomly amongst the > available clients ? > > Ian. > > _______________________________________________ > Xen-devel mailing list > Xen-devel@lists.xensource.com > http://lists.xensource.com/xen-devel_______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel
Ian Jackson
2011-Feb-17 19:01 UTC
Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty
Li Dongyang writes ("Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty"):> Thanks for reviewing, and what do you mean by ''not likely to be very > portable''? flock(2) is not POSIX, but fcntl(3p) is POSIX, maybe I > missed somthing?I mean that I wouldn''t be surprised if a platform we try to target for dom0 (or at least, not break) doesn''t support flock (or fcntl F_SETLK for that matter) on ptys. Ian. _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel