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:
Love Hörnquist Åstrand
2005-04-19 13:36:20 +00:00
parent 7adcb73bb8
commit 0ffd30a6e4

View File

@@ -358,6 +358,8 @@ getnpty()
* 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";
char *line = Xline;
@@ -378,40 +380,30 @@ static char *ptsname(int fd)
int getpty(int *ptynum)
{
#ifdef __osf__ /* XXX */
#if defined(HAVE_OPENPTY) || defined(__linux) || defined(__osf__) /* XXX */
{
int master;
int slave;
if(openpty(&master, &slave, line, 0, 0) == 0){
close(slave);
ptyslavefd = slave;
return master;
}
return -1;
#else
}
#endif /* HAVE_OPENPTY .... */
#ifdef HAVE__GETPTY
int master, slave;
{
int master;
char *p;
p = _getpty(&master, O_RDWR, 0600, 1);
if(p == NULL)
return -1;
strlcpy(line, p, sizeof(Xline));
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
{
char *clone[] = { "/dev/ptc", "/dev/ptmx", "/dev/ptm",
"/dev/ptym/clone", 0 };
@@ -430,8 +422,13 @@ int getpty(int *ptynum)
return p;
}
}
}
#endif /* STREAMSPTY */
#ifndef _CRAY
{
int p;
char *cp, *p1, *p2;
int i;
#ifndef __hpux
snprintf(line, sizeof(Xline), "/dev/ptyXX");
@@ -460,6 +457,10 @@ int getpty(int *ptynum)
*p2 = "0123456789abcdef"[i];
p = open(line, O_RDWR);
if (p > 0) {
#if SunOS == 40
int dummy;
#endif
#ifndef __hpux
line[5] = 't';
#else
@@ -481,9 +482,12 @@ int getpty(int *ptynum)
}
}
}
}
#else /* CRAY */
{
extern lowpty, highpty;
struct stat sb;
int p;
for (*ptynum = lowpty; *ptynum <= highpty; (*ptynum)++) {
snprintf(myline, sizeof(myline), "/dev/pty/%03d", *ptynum);
@@ -517,11 +521,9 @@ int getpty(int *ptynum)
close(p);
}
}
}
#endif /* CRAY */
#endif /* STREAMSPTY */
#endif /* OPENPTY */
return(-1);
#endif
}
@@ -966,6 +968,9 @@ int cleanopen(char *line)
{
int t;
if (ptyslavefd != -1)
return ptyslavefd;
#ifdef STREAMSPTY
if (!really_stream)
#endif