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] Solaris ptys have different semantics

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] Solaris ptys have different semantics
From: John Levon <john.levon@xxxxxxx>
Date: Wed, 11 Mar 2009 18:38:21 -0700
Delivery-date: Wed, 11 Mar 2009 18:47:35 -0700
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
# HG changeset patch
# User John Levon <john.levon@xxxxxxx>
# Date 1236821884 25200
# Node ID 818e5fb60ee1377f1215dd43d9890f97eef72ea4
# Parent  3ff7bc124d4cd452e9b00aa60da82e9c6adaee5e
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@xxxxxxx>

diff --git a/tools/console/client/main.c b/tools/console/client/main.c
--- 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 *
        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 *
                        }
                }
        } 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 ter
        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 x
 
                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;

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

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] Solaris ptys have different semantics, John Levon <=