Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Hang in E01 due to zpty on OpenBSD



On Wed, Apr 06, 2022 at 02:48:00PM +0900, Jun T wrote:
> 
> > 2022/04/04 22:16, Matthew Martin <phy1729@xxxxxxxxx> wrote:
> > 
> > On Mon, Apr 04, 2022 at 05:34:09PM +0900, Jun T wrote:
> > 
> >> Replace the pattern (in configure.ac)
> >> openbsd*)
> >> by
> >> openbsd7*)
> >> or such if openpty() should be used only on specific versions of OpenBSD.
> > 
> > I would only support OpenBSD-current unless anyone objects
> 
> We can't specify -current here.
> I've upgraded to OpenBSD-7.1 but still can't reproduce your problem.
> 
> But since openpty() works fine on OpenBSD7.0/7.1, I will push the patch
> with 'openbsd7*)' (with Mikael's fix of typo) if there is no objection.

I'd prefer something like the below where it's a feature test instead of
an OS test.

diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index dfd2a2a7a..f4c95537d 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -37,6 +37,15 @@
 #endif
 #endif
 
+#ifdef HAVE_OPENPTY
+#ifdef OPENPTY_REQUIRES_PTY
+#include <pty.h>
+#elif defined(OPENPTY_REQUIRES_UTIL)
+#include <termios.h>
+#include <util.h>
+#endif
+#endif
+
 /* The number of bytes we normally read when given no pattern and the
  * upper bound on the number of bytes we read (even if we are give a
  * pattern). */
@@ -161,8 +170,26 @@ getptycmd(char *name)
     return NULL;
 }
 
-/* posix_openpt() seems to have some problem on OpenBSD */
-#if defined(USE_DEV_PTMX) && !defined(__OpenBSD__)
+#ifdef HAVE_OPENPTY
+
+static int
+get_pty(int master, int *retfd)
+{
+    static int mfd, sfd;
+
+    if (master) {
+	if (openpty(&mfd, &sfd, NULL, NULL, NULL) == -1) {
+	    return 1;
+	}
+	*retfd = mfd;
+	return 0;
+    }
+
+    *retfd = sfd;
+    return 0;
+}
+
+#elifdef USE_DEV_PTMX
 
 #ifdef HAVE_SYS_STROPTS_H
 #include <sys/stropts.h>
@@ -261,12 +288,7 @@ get_pty(int master, int *retfd)
 #elif defined(__FreeBSD__) || defined(__DragonFly__)
     static char char1[] = "pqrsPQRS";
     static char char2[] = "0123456789abcdefghijklmnopqrstuv";
-#elif defined(__OpenBSD__)
-    static char char1[] = "pqrstuvwxyzPQRST";
-    static char char2[] = "0123456789"
-                          "abcdefghijklmnopqrstuvwxyz"
-                          "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-#else /* __FreeBSD__ || __DragonFly__  || __OpenBSD*/
+#else /* __FreeBSD__ || __DragonFly__ */
     static char char1[] = "pqrstuvwxyzPQRST";
     static char char2[] = "0123456789abcdef";
 #endif
diff --git a/configure.ac b/configure.ac
index 8bba78c56..e3ff0aca4 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2400,6 +2400,37 @@ dnl ---------------
 
 zsh_CHECK_SOCKLEN_T
 
+dnl ---------------
+dnl Check for openpty support
+dnl ---------------
+AH_TEMPLATE([HAVE_OPENPTY],
+  [Define to 1 if you have the `openpty' function.])
+AH_TEMPLATE([OPENPTY_REQUIRES_PTY],
+  [Define to 1 if the `openpty' function requires pty.h.])
+AH_TEMPLATE([OPENPTY_REQUIRES_UTIL],
+  [Define to 1 if the `openpty' function requires termios.h and util.h.])
+AC_MSG_CHECKING([for openpty])
+openpty=no
+AC_LINK_IFELSE([AC_LANG_SOURCE(
+[[#include<pty.h>
+int main () { int (*p)(int *, int *, char *, const struct termios *, const struct winsize *) = openpty; }]])],
+  [AC_DEFINE([HAVE_OPENPTY])
+   AC_DEFINE([OPENPTY_REQUIRES_PTY])
+   openpty=yes])
+if test $openpty = no; then
+AC_LINK_IFELSE([AC_LANG_SOURCE(
+[[#include<termios.h>
+#include <util.h>
+int main () { int (*p)(int *, int *, char *, const struct termios *, const struct winsize *) = openpty; }]])],
+  [AC_DEFINE([HAVE_OPENPTY])
+   AC_DEFINE([OPENPTY_REQUIRES_UTIL])
+   openpty=yes])
+fi
+AC_MSG_RESULT([$openpty])
+if test $openpty = yes; then
+AC_SEARCH_LIBS(openpty, util)
+fi
+
 dnl ---------------
 dnl Check for pty multiplexer for use in pty module.
 dnl We need to open it read/write, so make sure it is writeable.




Messages sorted by: Reverse Date, Date, Thread, Author