ia64/xen-unstable

changeset 19324:efc854626354

xenconsole: Solaris ptys have different semantics.

Make sure that tty semantics are active for Solaris ptys, or if they
aren't (and not needed) to not do tcget/setattr on the filedescriptor
in Python code.

Also work around a bug in the Solaris ptm streams driver, which will
cause a write error on the master side of a pty (because of e.g. a
missing slave) to persist forever.

Signed-off-by: Frank van der Linden <frank.vanderlinden@sun.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Mar 12 10:56:55 2009 +0000 (2009-03-12)
parents a762162e2fc9
children fc24bd05571e
files tools/console/client/main.c
line diff
     1.1 --- a/tools/console/client/main.c	Thu Mar 12 10:56:08 2009 +0000
     1.2 +++ b/tools/console/client/main.c	Thu Mar 12 10:56:55 2009 +0000
     1.3 @@ -35,6 +35,9 @@
     1.4  #include <err.h>
     1.5  #include <errno.h>
     1.6  #include <string.h>
     1.7 +#ifdef __sun__
     1.8 +#include <sys/stropts.h>
     1.9 +#endif
    1.10  
    1.11  #include "xs.h"
    1.12  
    1.13 @@ -72,7 +75,7 @@ static void usage(const char *program) {
    1.14  }
    1.15  
    1.16  #ifdef	__sun__
    1.17 -void cfmakeraw (struct termios *termios_p)
    1.18 +void cfmakeraw(struct termios *termios_p)
    1.19  {
    1.20  	termios_p->c_iflag &=
    1.21  	    ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
    1.22 @@ -95,7 +98,7 @@ static int get_pty_fd(struct xs_handle *
    1.23  	int xs_fd = xs_fileno(xs), pty_fd = -1;
    1.24  	int start, now;
    1.25  	unsigned int len = 0;
    1.26 -	char *pty_path, **watch_paths;;
    1.27 +	char *pty_path, **watch_paths;
    1.28  
    1.29  	start = now = time(NULL);
    1.30  	do {
    1.31 @@ -119,6 +122,29 @@ static int get_pty_fd(struct xs_handle *
    1.32  			}
    1.33  		}
    1.34  	} while (pty_fd == -1 && (now = time(NULL)) < start + seconds);
    1.35 +
    1.36 +#ifdef __sun__
    1.37 +	if (pty_fd != -1) {
    1.38 +		struct termios term;
    1.39 +
    1.40 +		/*
    1.41 +		 * The pty may come from either xend (with pygrub) or
    1.42 +		 * xenconsoled.  It may have tty semantics set up, or not.
    1.43 +		 * While it isn't strictly necessary to have those
    1.44 +		 * semantics here, it is good to have a consistent
    1.45 +		 * state that is the same as under Linux.
    1.46 +		 *
    1.47 +		 * If tcgetattr fails, they have not been set up,
    1.48 +		 * so go ahead and set them up now, by pushing the
    1.49 +		 * ptem and ldterm streams modules.
    1.50 +		 */
    1.51 +		if (tcgetattr(pty_fd, &term) < 0) {
    1.52 +			ioctl(pty_fd, I_PUSH, "ptem");
    1.53 +			ioctl(pty_fd, I_PUSH, "ldterm");
    1.54 +		}
    1.55 +	}
    1.56 +#endif
    1.57 +
    1.58  	return pty_fd;
    1.59  }
    1.60  
    1.61 @@ -134,12 +160,12 @@ static void init_term(int fd, struct ter
    1.62  	new_term = *old;
    1.63  	cfmakeraw(&new_term);
    1.64  
    1.65 -	tcsetattr(fd, TCSAFLUSH, &new_term);
    1.66 +	tcsetattr(fd, TCSANOW, &new_term);
    1.67  }
    1.68  
    1.69  static void restore_term(int fd, struct termios *old)
    1.70  {
    1.71 -	tcsetattr(fd, TCSAFLUSH, old);
    1.72 +	tcsetattr(fd, TCSANOW, old);
    1.73  }
    1.74  
    1.75  static int console_loop(int fd, struct xs_handle *xs, char *pty_path)
    1.76 @@ -167,7 +193,8 @@ static int console_loop(int fd, struct x
    1.77  
    1.78  		if (FD_ISSET(xs_fileno(xs), &fds)) {
    1.79  			int newfd = get_pty_fd(xs, pty_path, 0);
    1.80 -			close(fd);
    1.81 +			if (fd != -1)
    1.82 +				close(fd);
    1.83                          if (newfd == -1) 
    1.84  				/* Console PTY has become invalid */
    1.85  				return 0;