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

Re: Hang in E01 due to zpty on OpenBSD



> 2022/04/04 12:49, Matthew Martin <phy1729@xxxxxxxxx> wrote:
> 
> OpenBSD has gutted the pty route and strongly prefers openpty over
> posix_openpt. Is there a correct way link the zpty module against
> libutil?

Please try the following patch.
Replace the pattern (in configure.ac)
openbsd*)
by
openbsd7*)
or such if openpty() should be used only on specific versions of OpenBSD.



diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index dfd2a2a7a..cdab1d8e1 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -249,6 +249,28 @@ get_pty(int master, int *retfd)
     return 0;
 }
 
+/* openpty() is prefered on OpenBSD */
+#elif defined(__OpenBSD__) && defined(HAVE_OPENPTY)
+
+#include <util.h>
+
+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;
+}
+
 #else /* No /dev/ptmx or no pt functions */
 
 static int
diff --git a/configure.ac b/configure.ac
index 8bba78c56..6aae71300 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2441,6 +2441,18 @@ int ptsname();]], [[]])],[ac_cv_use_dev_ptmx=no],[ac_cv_use_dev_ptmx=yes])])
    fi
 fi
 
+dnl On (some) OpenBSD, it seems openpty() is the only reliable way to get pty.
+AH_TEMPLATE([HAVE_OPENPTY],
+[Define to 1 if openpt() is available on OpenBSD])
+case "$host_os" in
+  openbsd*)
+    AC_SEARCH_LIBS(openpty, util)
+    if test x$ac_cv_search_openpty != xno; then
+      AC_DEFINE(HAVE_OPENPTY)
+    fi
+    ;;
+esac
+
 dnl -----------------
 dnl multibyte support
 dnl -----------------







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