diff options
author | Christopher Faylor <me@cgf.cx> | 2011-11-08 10:26:15 +0400 |
---|---|---|
committer | Christopher Faylor <me@cgf.cx> | 2011-11-08 10:26:15 +0400 |
commit | 926014453f474ba583f485751600e851c4d5666a (patch) | |
tree | 43d5f55cfd8d95e980a5fa31014358fe69b5a82b /winsup/cygwin/libc | |
parent | 5d46c490dd1f5dc0b9a6c06e92e8773ba03acff2 (diff) |
* fhandler.h (__ptsname): New macro.
* dtable.cc (decode_tty): Use __ptsname to generate the slave pty name.
* fhandler_tty.cc (fhandler_pty_master::ptsname_r): Ditto.
* bsdlib.cc: Add needed includes for openpty() changes.
(openpty): Use __ptsname to generate the slave pty name. Close slave fd when
aslave == NULL.
Diffstat (limited to 'winsup/cygwin/libc')
-rw-r--r-- | winsup/cygwin/libc/bsdlib.cc | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/winsup/cygwin/libc/bsdlib.cc b/winsup/cygwin/libc/bsdlib.cc index 3b6e7e428..599df7107 100644 --- a/winsup/cygwin/libc/bsdlib.cc +++ b/winsup/cygwin/libc/bsdlib.cc @@ -35,6 +35,10 @@ #include <sys/ioctl.h> #include <fcntl.h> #include <err.h> +#include "path.h" +#include "fhandler.h" +#include "dtable.h" +#include "cygheap.h" #include "cygtls.h" extern "C" int @@ -108,20 +112,25 @@ openpty (int *amaster, int *aslave, char *name, const struct termios *termp, { grantpt (master); unlockpt (master); - strcpy (pts, ptsname (master)); + __ptsname (pts, cygheap->fdtab[master]->get_unit ()); revoke (pts); if ((slave = open (pts, O_RDWR | O_NOCTTY)) >= 0) { if (amaster) *amaster = master; - if (aslave) - *aslave = slave; if (name) strcpy (name, pts); if (termp) tcsetattr (slave, TCSAFLUSH, termp); if (winp) ioctl (slave, TIOCSWINSZ, (char *) winp); + /* The man page doesn't say that aslave can be NULL but we have + allowed it for years. As of 2011-11-08 we now avoid a handle + leak in this case. */ + if (aslave) + *aslave = slave; + else + close (slave); return 0; } close (master); |