rewrite getpty to make use openpty when its found, save the slave fd
so that cleanopen can use it if its available git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14848 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -358,6 +358,8 @@ getnpty()
|
|||||||
* Returns the file descriptor of the opened pty.
|
* Returns the file descriptor of the opened pty.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static int ptyslavefd = -1;
|
||||||
|
|
||||||
static char Xline[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
static char Xline[] = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0";
|
||||||
char *line = Xline;
|
char *line = Xline;
|
||||||
|
|
||||||
@@ -378,40 +380,30 @@ static char *ptsname(int fd)
|
|||||||
|
|
||||||
int getpty(int *ptynum)
|
int getpty(int *ptynum)
|
||||||
{
|
{
|
||||||
#ifdef __osf__ /* XXX */
|
#if defined(HAVE_OPENPTY) || defined(__linux) || defined(__osf__) /* XXX */
|
||||||
|
{
|
||||||
int master;
|
int master;
|
||||||
int slave;
|
int slave;
|
||||||
if(openpty(&master, &slave, line, 0, 0) == 0){
|
if(openpty(&master, &slave, line, 0, 0) == 0){
|
||||||
close(slave);
|
ptyslavefd = slave;
|
||||||
return master;
|
return master;
|
||||||
}
|
}
|
||||||
return -1;
|
}
|
||||||
#else
|
#endif /* HAVE_OPENPTY .... */
|
||||||
#ifdef HAVE__GETPTY
|
#ifdef HAVE__GETPTY
|
||||||
int master, slave;
|
{
|
||||||
|
int master;
|
||||||
char *p;
|
char *p;
|
||||||
p = _getpty(&master, O_RDWR, 0600, 1);
|
p = _getpty(&master, O_RDWR, 0600, 1);
|
||||||
if(p == NULL)
|
if(p == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
strlcpy(line, p, sizeof(Xline));
|
strlcpy(line, p, sizeof(Xline));
|
||||||
return master;
|
return master;
|
||||||
#else
|
|
||||||
|
|
||||||
int p;
|
|
||||||
char *cp, *p1, *p2;
|
|
||||||
int i;
|
|
||||||
#if SunOS == 40
|
|
||||||
int dummy;
|
|
||||||
#endif
|
|
||||||
#if __linux
|
|
||||||
int master;
|
|
||||||
int slave;
|
|
||||||
if(openpty(&master, &slave, line, 0, 0) == 0){
|
|
||||||
close(slave);
|
|
||||||
return master;
|
|
||||||
}
|
}
|
||||||
#else
|
#endif
|
||||||
|
|
||||||
#ifdef STREAMSPTY
|
#ifdef STREAMSPTY
|
||||||
|
{
|
||||||
char *clone[] = { "/dev/ptc", "/dev/ptmx", "/dev/ptm",
|
char *clone[] = { "/dev/ptc", "/dev/ptmx", "/dev/ptm",
|
||||||
"/dev/ptym/clone", 0 };
|
"/dev/ptym/clone", 0 };
|
||||||
|
|
||||||
@@ -430,8 +422,13 @@ int getpty(int *ptynum)
|
|||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif /* STREAMSPTY */
|
#endif /* STREAMSPTY */
|
||||||
#ifndef _CRAY
|
#ifndef _CRAY
|
||||||
|
{
|
||||||
|
int p;
|
||||||
|
char *cp, *p1, *p2;
|
||||||
|
int i;
|
||||||
|
|
||||||
#ifndef __hpux
|
#ifndef __hpux
|
||||||
snprintf(line, sizeof(Xline), "/dev/ptyXX");
|
snprintf(line, sizeof(Xline), "/dev/ptyXX");
|
||||||
@@ -460,6 +457,10 @@ int getpty(int *ptynum)
|
|||||||
*p2 = "0123456789abcdef"[i];
|
*p2 = "0123456789abcdef"[i];
|
||||||
p = open(line, O_RDWR);
|
p = open(line, O_RDWR);
|
||||||
if (p > 0) {
|
if (p > 0) {
|
||||||
|
#if SunOS == 40
|
||||||
|
int dummy;
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef __hpux
|
#ifndef __hpux
|
||||||
line[5] = 't';
|
line[5] = 't';
|
||||||
#else
|
#else
|
||||||
@@ -481,9 +482,12 @@ int getpty(int *ptynum)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#else /* CRAY */
|
#else /* CRAY */
|
||||||
|
{
|
||||||
extern lowpty, highpty;
|
extern lowpty, highpty;
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
int p;
|
||||||
|
|
||||||
for (*ptynum = lowpty; *ptynum <= highpty; (*ptynum)++) {
|
for (*ptynum = lowpty; *ptynum <= highpty; (*ptynum)++) {
|
||||||
snprintf(myline, sizeof(myline), "/dev/pty/%03d", *ptynum);
|
snprintf(myline, sizeof(myline), "/dev/pty/%03d", *ptynum);
|
||||||
@@ -517,11 +521,9 @@ int getpty(int *ptynum)
|
|||||||
close(p);
|
close(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif /* CRAY */
|
#endif /* CRAY */
|
||||||
#endif /* STREAMSPTY */
|
|
||||||
#endif /* OPENPTY */
|
|
||||||
return(-1);
|
return(-1);
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -966,6 +968,9 @@ int cleanopen(char *line)
|
|||||||
{
|
{
|
||||||
int t;
|
int t;
|
||||||
|
|
||||||
|
if (ptyslavefd != -1)
|
||||||
|
return ptyslavefd;
|
||||||
|
|
||||||
#ifdef STREAMSPTY
|
#ifdef STREAMSPTY
|
||||||
if (!really_stream)
|
if (!really_stream)
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user