Commit 64b7b7334b92c1fdc1bb7d3d1afc342656c59539

Authored by aurel32
1 parent f2bf094e

Put Pseudo-TTY in rawmode for char devices

(Daniel P. Berrange)


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@4338 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 1 changed file with 62 additions and 12 deletions
@@ -2269,28 +2269,78 @@ static CharDriverState *qemu_chr_open_stdio(void) @@ -2269,28 +2269,78 @@ static CharDriverState *qemu_chr_open_stdio(void)
2269 return chr; 2269 return chr;
2270 } 2270 }
2271 2271
  2272 +#ifdef __sun__
  2273 +/* Once Solaris has openpty(), this is going to be removed. */
  2274 +int openpty(int *amaster, int *aslave, char *name,
  2275 + struct termios *termp, struct winsize *winp)
  2276 +{
  2277 + const char *slave;
  2278 + int mfd = -1, sfd = -1;
  2279 +
  2280 + *amaster = *aslave = -1;
  2281 +
  2282 + mfd = open("/dev/ptmx", O_RDWR | O_NOCTTY);
  2283 + if (mfd < 0)
  2284 + goto err;
  2285 +
  2286 + if (grantpt(mfd) == -1 || unlockpt(mfd) == -1)
  2287 + goto err;
  2288 +
  2289 + if ((slave = ptsname(mfd)) == NULL)
  2290 + goto err;
  2291 +
  2292 + if ((sfd = open(slave, O_RDONLY | O_NOCTTY)) == -1)
  2293 + goto err;
  2294 +
  2295 + if (ioctl(sfd, I_PUSH, "ptem") == -1 ||
  2296 + (termp != NULL && tcgetattr(sfd, termp) < 0))
  2297 + goto err;
  2298 +
  2299 + if (amaster)
  2300 + *amaster = mfd;
  2301 + if (aslave)
  2302 + *aslave = sfd;
  2303 + if (winp)
  2304 + ioctl(sfd, TIOCSWINSZ, winp);
  2305 +
  2306 + return 0;
  2307 +
  2308 +err:
  2309 + if (sfd != -1)
  2310 + close(sfd);
  2311 + close(mfd);
  2312 + return -1;
  2313 +}
  2314 +
  2315 +void cfmakeraw (struct termios *termios_p)
  2316 +{
  2317 + termios_p->c_iflag &=
  2318 + ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON);
  2319 + termios_p->c_oflag &= ~OPOST;
  2320 + termios_p->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
  2321 + termios_p->c_cflag &= ~(CSIZE|PARENB);
  2322 + termios_p->c_cflag |= CS8;
  2323 +
  2324 + termios_p->c_cc[VMIN] = 0;
  2325 + termios_p->c_cc[VTIME] = 0;
  2326 +}
  2327 +#endif
  2328 +
2272 #if defined(__linux__) || defined(__sun__) 2329 #if defined(__linux__) || defined(__sun__)
2273 static CharDriverState *qemu_chr_open_pty(void) 2330 static CharDriverState *qemu_chr_open_pty(void)
2274 { 2331 {
2275 struct termios tty; 2332 struct termios tty;
2276 - char slave_name[1024];  
2277 int master_fd, slave_fd; 2333 int master_fd, slave_fd;
2278 2334
2279 -#if defined(__linux__)  
2280 - /* Not satisfying */  
2281 - if (openpty(&master_fd, &slave_fd, slave_name, NULL, NULL) < 0) { 2335 + if (openpty(&master_fd, &slave_fd, NULL, NULL, NULL) < 0) {
2282 return NULL; 2336 return NULL;
2283 } 2337 }
2284 -#endif  
2285 2338
2286 - /* Disabling local echo and line-buffered output */  
2287 - tcgetattr (master_fd, &tty);  
2288 - tty.c_lflag &= ~(ECHO|ICANON|ISIG);  
2289 - tty.c_cc[VMIN] = 1;  
2290 - tty.c_cc[VTIME] = 0;  
2291 - tcsetattr (master_fd, TCSAFLUSH, &tty); 2339 + /* Set raw attributes on the pty. */
  2340 + cfmakeraw(&tty);
  2341 + tcsetattr(slave_fd, TCSAFLUSH, &tty);
2292 2342
2293 - fprintf(stderr, "char device redirected to %s\n", slave_name); 2343 + fprintf(stderr, "char device redirected to %s\n", ptsname(master_fd));
2294 return qemu_chr_open_fd(master_fd, master_fd); 2344 return qemu_chr_open_fd(master_fd, master_fd);
2295 } 2345 }
2296 2346