Blame qemu-0.9.1-pty-rawmode.patch

Daniel P. Berrange a1020f
diff -rup qemu-0.9.1.orig/vl.c qemu-0.9.1.new/vl.c
Daniel P. Berrange a1020f
--- qemu-0.9.1.orig/vl.c	2008-05-05 13:32:55.000000000 -0400
Daniel P. Berrange a1020f
+++ qemu-0.9.1.new/vl.c	2008-05-05 13:33:17.000000000 -0400
Daniel P. Berrange a1020f
@@ -2200,28 +2200,78 @@ static CharDriverState *qemu_chr_open_st
Daniel P. Berrange a1020f
     return chr;
Daniel P. Berrange a1020f
 }
Daniel P. Berrange a1020f
 
Daniel P. Berrange a1020f
+#ifdef __sun__
Daniel P. Berrange a1020f
+/* Once Solaris has openpty(), this is going to be removed. */
Daniel P. Berrange a1020f
+int openpty(int *amaster, int *aslave, char *name,
Daniel P. Berrange a1020f
+            struct termios *termp, struct winsize *winp)
Daniel P. Berrange a1020f
+{
Daniel P. Berrange a1020f
+        const char *slave;
Daniel P. Berrange a1020f
+        int mfd = -1, sfd = -1;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        *amaster = *aslave = -1;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        mfd = open("/dev/ptmx", O_RDWR | O_NOCTTY);
Daniel P. Berrange a1020f
+        if (mfd < 0)
Daniel P. Berrange a1020f
+                goto err;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        if (grantpt(mfd) == -1 || unlockpt(mfd) == -1)
Daniel P. Berrange a1020f
+                goto err;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        if ((slave = ptsname(mfd)) == NULL)
Daniel P. Berrange a1020f
+                goto err;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        if ((sfd = open(slave, O_RDONLY | O_NOCTTY)) == -1)
Daniel P. Berrange a1020f
+                goto err;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        if (ioctl(sfd, I_PUSH, "ptem") == -1 ||
Daniel P. Berrange a1020f
+            (termp != NULL && tcgetattr(sfd, termp) < 0))
Daniel P. Berrange a1020f
+                goto err;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        if (amaster)
Daniel P. Berrange a1020f
+                *amaster = mfd;
Daniel P. Berrange a1020f
+        if (aslave)
Daniel P. Berrange a1020f
+                *aslave = sfd;
Daniel P. Berrange a1020f
+        if (winp)
Daniel P. Berrange a1020f
+                ioctl(sfd, TIOCSWINSZ, winp);
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        return 0;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+err:
Daniel P. Berrange a1020f
+        if (sfd != -1)
Daniel P. Berrange a1020f
+                close(sfd);
Daniel P. Berrange a1020f
+        close(mfd);
Daniel P. Berrange a1020f
+        return -1;
Daniel P. Berrange a1020f
+}
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+void cfmakeraw (struct termios *termios_p)
Daniel P. Berrange a1020f
+{
Daniel P. Berrange a1020f
+        termios_p->c_iflag &=
Daniel P. Berrange a1020f
+                ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
Daniel P. Berrange a1020f
+        termios_p->c_oflag &= ~OPOST;
Daniel P. Berrange a1020f
+        termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
Daniel P. Berrange a1020f
+        termios_p->c_cflag &= ~(CSIZE|PARENB);
Daniel P. Berrange a1020f
+        termios_p->c_cflag |= CS8;
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
+        termios_p->c_cc[VMIN] = 0;
Daniel P. Berrange a1020f
+        termios_p->c_cc[VTIME] = 0;
Daniel P. Berrange a1020f
+}
Daniel P. Berrange a1020f
+#endif
Daniel P. Berrange a1020f
+
Daniel P. Berrange a1020f
 #if defined(__linux__) || defined(__sun__)
Daniel P. Berrange a1020f
 static CharDriverState *qemu_chr_open_pty(void)
Daniel P. Berrange a1020f
 {
Daniel P. Berrange a1020f
     struct termios tty;
Daniel P. Berrange a1020f
-    char slave_name[1024];
Daniel P. Berrange a1020f
     int master_fd, slave_fd;
Daniel P. Berrange a1020f
 
Daniel P. Berrange a1020f
-#if defined(__linux__)
Daniel P. Berrange a1020f
-    /* Not satisfying */
Daniel P. Berrange a1020f
-    if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) {
Daniel P. Berrange a1020f
+    if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) < 0) {
Daniel P. Berrange a1020f
         return NULL;
Daniel P. Berrange a1020f
     }
Daniel P. Berrange a1020f
-#endif
Daniel P. Berrange a1020f
 
Daniel P. Berrange a1020f
-    /* Disabling local echo and line-buffered output */
Daniel P. Berrange a1020f
-    tcgetattr (master_fd, &tty);
Daniel P. Berrange a1020f
-    tty.c_lflag &= ~(ECHO|ICANON|ISIG);
Daniel P. Berrange a1020f
-    tty.c_cc[VMIN] = 1;
Daniel P. Berrange a1020f
-    tty.c_cc[VTIME] = 0;
Daniel P. Berrange a1020f
-    tcsetattr (master_fd, TCSAFLUSH, &tty);
Daniel P. Berrange a1020f
+    /* Set raw attributes on the pty. */
Daniel P. Berrange a1020f
+    cfmakeraw(&tty);
Daniel P. Berrange a1020f
+    tcsetattr(slave_fd, TCSAFLUSH, &tty);
Daniel P. Berrange a1020f
 
Daniel P. Berrange a1020f
-    fprintf(stderr, "char device redirected to %s\n", slave_name);
Daniel P. Berrange a1020f
+    fprintf(stderr, "char device redirected to %s\n", ptsname(master_fd));
Daniel P. Berrange a1020f
     return qemu_chr_open_fd(master_fd, master_fd);
Daniel P. Berrange a1020f
 }
Daniel P. Berrange a1020f