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: Sun, 3 Apr 2022 21:34:07 -0500	[thread overview]
Message-ID: <YkpZH28mfZHlsd2T@CptOrmolo.darkstar> (raw)
In-Reply-To: <CAH+w=7ba1fo9BdNurD9TH5MjuyYRk=-xJ0ioXo8aTt_ZCKEhLw@mail.gmail.com>

On Sun, Apr 03, 2022 at 06:04:30PM -0700, Bart Schaefer wrote:
> On Sun, Apr 3, 2022 at 2:43 PM Matthew Martin <phy1729@gmail.com> wrote:
> >
> > I assume the EPERM on open is an OpenBSD bug, but zsh should probably
> > not hang either.
> 
> I'm not sure what could be done about this from the zsh code.  The
> only reasonable assumption for the pty master-side reader is that the
> slave-slide will become closed upon an error and the read will fail.
> Using a non-blocking read would defeat the purpose.

The only reasonable thing I can come up with is open both pty and tty on
the first call to get_pty, so the second call can't fail. 

The tests pass when I use openpty; though since that's in libutil and
I didn't immedietly see a way to link that in, there's a terrible work
around with dlopen/dlsym. I have no intention to commit this.

I've sent a mail to OpenBSD. I don't think this should block the
release. Worst case there will be a patch in the port that can be
upstreamed by the next release.


diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index dfd2a2a7a..3f21c2b89 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -37,6 +37,12 @@
 #endif
 #endif
 
+#ifdef __OpenBSD__
+#include <dlfcn.h>
+#include <termios.h>
+#include <util.h>
+#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 +167,38 @@ getptycmd(char *name)
     return NULL;
 }
 
-/* posix_openpt() seems to have some problem on OpenBSD */
-#if defined(USE_DEV_PTMX) && !defined(__OpenBSD__)
+#if defined(__OpenBSD__)
+
+static int
+get_pty(int master, int *retfd)
+{
+    static int mfd, sfd;
+
+    if (master) {
+	void *handle;
+	int (*openpty)(int *, int *, char *, struct termios *, struct winsize *);
+
+	if ((handle = dlopen("libutil.so", 0)) == NULL) {
+	    return 1;
+	}
+	if ((openpty = dlsym(handle, "openpty")) == NULL) {
+	    dlclose(handle);
+	    return 1;
+	}
+	if (openpty(&mfd, &sfd, NULL, NULL, NULL) == -1) {
+	    dlclose(handle);
+	    return 1;
+	}
+	dlclose(handle);
+	*retfd = mfd;
+	return 0;
+    }
+
+    *retfd = sfd;
+    return 0;
+}
+
+#elif defined(USE_DEV_PTMX)
 
 #ifdef HAVE_SYS_STROPTS_H
 #include <sys/stropts.h>
@@ -261,12 +297,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


  reply	other threads:[~2022-04-04  2:34 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 [this message]
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
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=YkpZH28mfZHlsd2T@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).