diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2009-03-12 10:56:55 +0000 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2009-03-12 10:56:55 +0000 |
commit | 275c6ccdc971ac824e45029428b480fcc7a8829a (patch) | |
tree | 675de0e881ed1d872c0805901b83e28d0b1f46f2 /tools/console | |
parent | 08dade96d99e5b978c727cc6bdb19661de1a4cca (diff) | |
download | xen-275c6ccdc971ac824e45029428b480fcc7a8829a.tar.gz xen-275c6ccdc971ac824e45029428b480fcc7a8829a.tar.bz2 xen-275c6ccdc971ac824e45029428b480fcc7a8829a.zip |
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>
Diffstat (limited to 'tools/console')
-rw-r--r-- | tools/console/client/main.c | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/tools/console/client/main.c b/tools/console/client/main.c index 6fb41114b6..39556da5a0 100644 --- a/tools/console/client/main.c +++ b/tools/console/client/main.c @@ -35,6 +35,9 @@ #include <err.h> #include <errno.h> #include <string.h> +#ifdef __sun__ +#include <sys/stropts.h> +#endif #include "xs.h" @@ -72,7 +75,7 @@ static void usage(const char *program) { } #ifdef __sun__ -void cfmakeraw (struct termios *termios_p) +void cfmakeraw(struct termios *termios_p) { termios_p->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); @@ -95,7 +98,7 @@ static int get_pty_fd(struct xs_handle *xs, char *path, int seconds) int xs_fd = xs_fileno(xs), pty_fd = -1; int start, now; unsigned int len = 0; - char *pty_path, **watch_paths;; + char *pty_path, **watch_paths; start = now = time(NULL); do { @@ -119,6 +122,29 @@ static int get_pty_fd(struct xs_handle *xs, char *path, int seconds) } } } while (pty_fd == -1 && (now = time(NULL)) < start + seconds); + +#ifdef __sun__ + if (pty_fd != -1) { + struct termios term; + + /* + * The pty may come from either xend (with pygrub) or + * xenconsoled. It may have tty semantics set up, or not. + * While it isn't strictly necessary to have those + * semantics here, it is good to have a consistent + * state that is the same as under Linux. + * + * If tcgetattr fails, they have not been set up, + * so go ahead and set them up now, by pushing the + * ptem and ldterm streams modules. + */ + if (tcgetattr(pty_fd, &term) < 0) { + ioctl(pty_fd, I_PUSH, "ptem"); + ioctl(pty_fd, I_PUSH, "ldterm"); + } + } +#endif + return pty_fd; } @@ -134,12 +160,12 @@ static void init_term(int fd, struct termios *old) new_term = *old; cfmakeraw(&new_term); - tcsetattr(fd, TCSAFLUSH, &new_term); + tcsetattr(fd, TCSANOW, &new_term); } static void restore_term(int fd, struct termios *old) { - tcsetattr(fd, TCSAFLUSH, old); + tcsetattr(fd, TCSANOW, old); } static int console_loop(int fd, struct xs_handle *xs, char *pty_path) @@ -167,7 +193,8 @@ static int console_loop(int fd, struct xs_handle *xs, char *pty_path) if (FD_ISSET(xs_fileno(xs), &fds)) { int newfd = get_pty_fd(xs, pty_path, 0); - close(fd); + if (fd != -1) + close(fd); if (newfd == -1) /* Console PTY has become invalid */ return 0; |