* 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.
This commit is contained in:
parent
5d46c490dd
commit
926014453f
@ -1,3 +1,12 @@
|
||||
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.
|
||||
|
@ -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
|
||||
|
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user