--- old/tools/ioemu/vl.c Tue Jul 1 08:15:47 2008 +++ new/tools/ioemu/vl.c Tue Jul 1 08:15:46 2008 @@ -54,6 +54,7 @@ #include #include #include +#include #else #include #include @@ -1822,26 +1823,96 @@ return 0; } -#if defined(__linux__) +#ifdef __sun__ +static int openpty(int *amaster, int *aslave, char *name, + struct termios *termp, struct winsize *winp) +{ + const char *slave; + int mfd = -1, sfd = -1; + + *amaster = *aslave = -1; + + mfd = open("/dev/ptmx", O_RDWR | O_NOCTTY); + if (mfd < 0) + goto err; + + if (grantpt(mfd) == -1 || unlockpt(mfd) == -1) + goto err; + + if ((slave = ptsname(mfd)) == NULL) + goto err; + + if ((sfd = open(slave, O_RDONLY | O_NOCTTY)) == -1) + goto err; + + if (ioctl(sfd, I_PUSH, "ptem") == -1 || + ioctl(sfd, I_PUSH, "ldterm") == -1) + goto err; + + if (amaster) + *amaster = mfd; + if (aslave) + *aslave = sfd; + if (winp) + ioctl(sfd, TIOCSWINSZ, winp); + + if (termp) + tcsetattr(sfd, TCSANOW, termp); + + assert(name == NULL); + + return 0; + +err: + if (sfd != -1) + close(sfd); + close(mfd); + return -1; +} + +void cfmakeraw (struct termios *termios_p) +{ + termios_p->c_iflag &= + ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); + termios_p->c_oflag &= ~OPOST; + termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); + termios_p->c_cflag &= ~(CSIZE|PARENB); + termios_p->c_cflag |= CS8; + + termios_p->c_cc[VMIN] = 0; + termios_p->c_cc[VTIME] = 0; +} + +#endif /* __sun__ */ + +#if defined(__linux__) || defined(__sun__) static CharDriverState *qemu_chr_open_pty(void) { struct termios tty; int master_fd, slave_fd; - /* Not satisfying */ if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) < 0) { return NULL; } /* Set raw attributes on the pty. */ + tcgetattr(slave_fd, &tty); cfmakeraw(&tty); - tcsetattr(slave_fd, TCSAFLUSH, &tty); + tcsetattr(slave_fd, TCSANOW, &tty); fprintf(stderr, "char device redirected to %s\n", ptsname(master_fd)); return qemu_chr_open_fd(master_fd, master_fd); } +#else /* defined(__linux__) || defined(__sun__) */ +static CharDriverState *qemu_chr_open_pty(void) +{ + return NULL; +} +#endif /* defined(__linux__) || defined(__sun__) */ +#ifdef __linux__ + static void tty_serial_init(int fd, int speed, int parity, int data_bits, int stop_bits) { @@ -2042,12 +2113,7 @@ return chr; } -#else -static CharDriverState *qemu_chr_open_pty(void) -{ - return NULL; -} -#endif +#endif /* __linux__ */ #endif /* !defined(_WIN32) */