we no longer need this custom code to deal with ptys

This commit is contained in:
brad 2004-01-05 02:00:54 +00:00
parent a2de45a8df
commit 78b95934a9

View File

@ -1,84 +1,11 @@
$OpenBSD: patch-pty_c,v 1.2 2003/10/14 23:05:28 jolan Exp $
--- pty.c.orig 2003-09-08 09:26:18.000000000 -0500
+++ pty.c 2003-10-14 14:31:29.000000000 -0500
@@ -25,10 +25,29 @@
$OpenBSD: patch-pty_c,v 1.3 2004/01/05 02:00:54 brad Exp $
--- pty.c.orig 2003-09-08 10:26:18.000000000 -0400
+++ pty.c 2004-01-04 21:00:15.000000000 -0500
@@ -25,6 +25,7 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <signal.h>
+#include <termios.h>
+#include <util.h>
#include "config.h"
#include "screen.h"
+#if HAVE_DIRENT_H
+# include <dirent.h>
+# define NAMLEN(dirent) strlen((dirent)->d_name)
+#else
+# define dirent direct
+# define NAMLEN(dirent) (dirent)->d_namlen
+# if SYSNDIR
+# include <sys/ndir.h>
+# endif
+# if SYSDIR
+# include <sys/dir.h>
+# endif
+# if NDIR
+# include <ndir.h>
+# endif
+#endif
+
#ifndef sun
# include <sys/ioctl.h>
#endif
@@ -337,25 +356,25 @@ int
OpenPTY(ttyn)
char **ttyn;
{
- register char *p, *q, *l, *d;
- register int f;
+ DIR *devdir;
+ struct dirent *candidate;
+ int f;
- debug("OpenPTY: Using BSD style ptys.\n");
- strcpy(PtyName, PtyProto);
- strcpy(TtyName, TtyProto);
- for (p = PtyName; *p != 'X'; p++)
- ;
- for (q = TtyName; *q != 'X'; q++)
- ;
- for (l = PTYRANGE0; (*p = *l) != '\0'; l++)
+ debug("OpenPTY: Using BSD style ptys, dynamic range.\n");
+
+ devdir = opendir("/dev");
+ if (!devdir)
+ return -1;
+ while (candidate = readdir(devdir))
{
- for (d = PTYRANGE1; (p[1] = *d) != '\0'; d++)
+ if (NAMLEN(candidate) == 5 && strncmp(candidate->d_name, "pty", 3) == 0)
{
+ sprintf(PtyName, "/dev/%s", candidate->d_name);
debug1("OpenPTY tries '%s'\n", PtyName);
if ((f = open(PtyName, O_RDWR | O_NOCTTY)) == -1)
continue;
- q[0] = *l;
- q[1] = *d;
+ strcpy(TtyName, PtyName);
+ TtyName[5] = 't';
if (eff_uid && access(TtyName, R_OK | W_OK))
{
close(f);
@@ -378,9 +397,11 @@ char **ttyn;
#endif
initmaster(f);
*ttyn = TtyName;
+ closedir(devdir);
return f;
}
}
+ closedir(devdir);
return -1;
}
#endif