X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;ds=sidebyside;f=contrib%2Fcygtermd%2Fpty.c;h=6080ecfb3acd3ab06f60099e44c173950395ca87;hb=24da181a01ecd851757549afd20978e0bfac445b;hp=e30f9e0eb81347456e6d90ac1b9ecb34a9881d9b;hpb=b642aa086a5994a2d205e906edd7d2e6b90943af;p=PuTTY.git diff --git a/contrib/cygtermd/pty.c b/contrib/cygtermd/pty.c index e30f9e0e..6080ecfb 100644 --- a/contrib/cygtermd/pty.c +++ b/contrib/cygtermd/pty.c @@ -2,7 +2,7 @@ * pty.c - pseudo-terminal handling */ -#define _XOPEN_SOURCE +#define _XOPEN_SOURCE 500 #include #include @@ -122,9 +122,23 @@ int run_program_in_pty(const struct shell_data *shdata, close(fd); } #endif + /* + * Make the new pty our controlling terminal. On some OSes + * this is done with TIOCSCTTY; Cygwin doesn't have that, so + * instead it's done by simply opening the pty without + * O_NOCTTY. This code is primarily intended for Cygwin, but + * it's useful to have it work in other contexts for testing + * purposes, so I leave the TIOCSCTTY here anyway. + */ + if ((fd = open(ptyname, O_RDWR)) >= 0) { #ifdef TIOCSCTTY - ioctl(0, TIOCSCTTY, &i); + ioctl(fd, TIOCSCTTY, &i); #endif + close(fd); + } else { + perror("slave pty: open"); + exit(127); + } tcsetpgrp(0, getpgrp()); for (i = 0; i < shdata->nenvvars; i++)