Print this page
Enable pty-based serial console emulation in ioemu.
Signed-off-by: John Levon <john.levon@sun.com>
@@ -52,10 +52,11 @@
#ifdef __sun__
#include <libdlpi.h>
#include <sys/ethernet.h>
#include <stropts.h>
#include <sys/bufmod.h>
+#include <assert.h>
#else
#include <linux/if.h>
#include <linux/if_tun.h>
#include <pty.h>
#include <malloc.h>
@@ -1820,30 +1821,100 @@
close(xc_handle);
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)
{
struct termios tty;
speed_t spd;
@@ -2040,16 +2111,11 @@
qemu_chr_reset(chr);
return chr;
}
-#else
-static CharDriverState *qemu_chr_open_pty(void)
-{
- return NULL;
-}
-#endif
+#endif /* __linux__ */
#endif /* !defined(_WIN32) */
#ifdef _WIN32
typedef struct {