$OpenBSD: patch-Tty_xs,v 1.1 2004/08/28 22:54:50 millert Exp $ --- Tty.xs.orig Wed Mar 6 06:47:32 2002 +++ Tty.xs Sat Aug 28 13:02:55 2004 @@ -271,6 +271,7 @@ make_safe_fd(int * fd) } } +#if !defined(HAVE_OPENPTY) /* * After having acquired a master pty, try to find out the slave name, * initialize and open the slave. @@ -433,6 +434,7 @@ open_slave(int *ptyfd, int *ttyfd, char return 1; } +#endif /* * Allocates and opens a pty. Returns 0 if no pty could be allocated, or @@ -488,7 +490,7 @@ allocate_pty(int *ptyfd, int *ttyfd, cha } #endif -#if defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R) +#if defined(HAVE_PTSNAME) || defined(HAVE_PTSNAME_R) || defined(HAVE_OPENPTY) /* we don't need to try these if we don't have a way to get the pty names */ #if defined(HAVE_GETPT) @@ -505,29 +507,21 @@ allocate_pty(int *ptyfd, int *ttyfd, cha #endif /* defined(HAVE_GETPT) */ #if defined(HAVE_OPENPTY) - /* openpty(3) exists in a variety of OS'es, but due to it's - * broken interface (no maxlen to slavename) we'll only use it - * to create the tty/pty pair and rely on ptsname to get the - * name. */ - { - mysig_t old_signal; - int ret; - + /* openpty(3) is documented to require 16 bytes for the + * slave name. We always allocate 64 so it is safe... + */ #if PTY_DEBUG - if (print_debug) - fprintf(stderr, "trying openpty()...\n"); + if (print_debug) + fprintf(stderr, "trying openpty()...\n"); #endif - old_signal = mysignal(SIGCHLD, SIG_DFL); - ret = openpty(ptyfd, ttyfd, NULL, NULL, NULL); - mysignal(SIGCHLD, old_signal); - if (ret >= 0 && *ptyfd >= 0) { - if (open_slave(ptyfd, ttyfd, namebuf, namebuflen)) - break; - } - *ptyfd = -1; - *ttyfd = -1; - if (PL_dowarn) - warn("pty_allocate(nonfatal): openpty(): %.100s", strerror(errno)); + if (openpty(ptyfd, ttyfd, namebuf, NULL, NULL) == 0) { + make_safe_fd(ptyfd); + make_safe_fd(ttyfd); + return 1; + } else { + if (PL_dowarn) + warn("pty_allocate: openpty(): %.100s", strerror(errno)); + return 0; } #endif /* defined(HAVE_OPENPTY) */