do not allow multiple xenconsole connect to the same pty
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
@@ -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); } }
Li Dongyang writes ("[Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty"):
Quoted 2 lines
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.
Quoted 9 lines · On Tue, 15 Feb 2011 19:40:04 +0000 Ian Jackson <[email protected]>…
Li Dongyang writes ("[Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty"):
Quoted 2 lines
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.
Alan Cox writes ("Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty"):
Quoted 2 lines
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.
Quoted 5 lines · Ian Jackson
Li Dongyang writes ("[Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty"):
Quoted 2 lines
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
Quoted 11 lines
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
[email protected]
http://lists.xensource.com/xen-devel
Li Dongyang writes ("Re: [Xen-devel] [PATCH]do not allow multiple xenconsole connect to the same pty"):
Quoted 3 lines
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.