zsh-workers
 help / color / mirror / code / Atom feed
From: Matthew Martin <phy1729@gmail.com>
To: zsh-workers@zsh.org
Subject: Re: Hang in E01 due to zpty on OpenBSD
Date: Wed, 6 Apr 2022 07:53:39 -0500	[thread overview]
Message-ID: <Yk2NU2krjfBGnQBu@CptOrmolo.darkstar> (raw)
In-Reply-To: <E1767D7E-9DAC-4261-ACEF-5BF1F59A0927@kba.biglobe.ne.jp>

On Wed, Apr 06, 2022 at 02:48:00PM +0900, Jun T wrote:
> 
> > 2022/04/04 22:16, Matthew Martin <phy1729@gmail.com> 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.


  reply	other threads:[~2022-04-06 12:54 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-03 21:42 Matthew Martin
2022-04-04  1:04 ` Bart Schaefer
2022-04-04  2:34   ` Matthew Martin
2022-04-04  3:49     ` Matthew Martin
2022-04-04  8:34       ` Jun T
2022-04-04 11:21         ` Mikael Magnusson
2022-04-04 13:16         ` Matthew Martin
2022-04-06  5:48           ` Jun T
2022-04-06 12:53             ` Matthew Martin [this message]
2022-04-06 20:12               ` Bart Schaefer
2022-04-07  3:47               ` Jun T
2022-04-07  4:52                 ` Matthew Martin
2022-04-08  7:51                   ` Jun T
2022-04-04  2:39 ` Jun T
2022-04-04  2:51   ` Matthew Martin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Yk2NU2krjfBGnQBu@CptOrmolo.darkstar \
    --to=phy1729@gmail.com \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).