summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Faylor <me@cgf.cx>2011-11-08 06:26:15 +0000
committerChristopher Faylor <me@cgf.cx>2011-11-08 06:26:15 +0000
commit926014453f474ba583f485751600e851c4d5666a (patch)
tree43d5f55cfd8d95e980a5fa31014358fe69b5a82b
parent5d46c490dd1f5dc0b9a6c06e92e8773ba03acff2 (diff)
downloadcygnal-926014453f474ba583f485751600e851c4d5666a.tar.gz
cygnal-926014453f474ba583f485751600e851c4d5666a.tar.bz2
cygnal-926014453f474ba583f485751600e851c4d5666a.zip
* 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.
-rw-r--r--winsup/cygwin/ChangeLog9
-rw-r--r--winsup/cygwin/dtable.cc2
-rw-r--r--winsup/cygwin/fhandler.h1
-rw-r--r--winsup/cygwin/fhandler_tty.cc2
-rw-r--r--winsup/cygwin/libc/bsdlib.cc15
5 files changed, 24 insertions, 5 deletions
diff --git a/winsup/cygwin/ChangeLog b/winsup/cygwin/ChangeLog
index 4381fc406..c979d76ca 100644
--- a/winsup/cygwin/ChangeLog
+++ b/winsup/cygwin/ChangeLog
@@ -1,5 +1,14 @@
2011-11-08 Christopher Faylor <me.cygwin2011@cgf.cx>
+ * 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.
+
+2011-11-08 Christopher Faylor <me.cygwin2011@cgf.cx>
+
* include/cygwin/stdlib.h: Update copyright.
2011-11-07 Christopher Faylor <me.cygwin2011@cgf.cx>
diff --git a/winsup/cygwin/dtable.cc b/winsup/cygwin/dtable.cc
index 982a671c2..f8fbbd25b 100644
--- a/winsup/cygwin/dtable.cc
+++ b/winsup/cygwin/dtable.cc
@@ -887,7 +887,7 @@ static void
decode_tty (char *buf, WCHAR *w32)
{
int ttyn = wcstol (w32, NULL, 10);
- __small_sprintf (buf, "/dev/pty%d", ttyn);
+ __ptsname (buf, ttyn);
}
/* Try to derive posix filename from given handle. Return true if
diff --git a/winsup/cygwin/fhandler.h b/winsup/cygwin/fhandler.h
index 189c0f3b5..4ceba4e5d 100644
--- a/winsup/cygwin/fhandler.h
+++ b/winsup/cygwin/fhandler.h
@@ -1456,6 +1456,7 @@ class fhandler_pty_slave: public fhandler_pty_common
}
};
+#define __ptsname(buf, unit) __small_sprintf ((buf), "/dev/pty%d", (unit))
class fhandler_pty_master: public fhandler_pty_common
{
int pktmode; // non-zero if pty in a packet mode.
diff --git a/winsup/cygwin/fhandler_tty.cc b/winsup/cygwin/fhandler_tty.cc
index c68211b66..9431cb067 100644
--- a/winsup/cygwin/fhandler_tty.cc
+++ b/winsup/cygwin/fhandler_tty.cc
@@ -1424,7 +1424,7 @@ fhandler_pty_master::ptsname_r (char *buf, size_t buflen)
{
char tmpbuf[TTY_NAME_MAX];
- __small_sprintf (tmpbuf, "/dev/pty%d", get_unit ());
+ __ptsname (tmpbuf, get_unit ());
if (buflen <= strlen (tmpbuf))
{
set_errno (ERANGE);
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);