carlwgeorge / rpms / qemu

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