zsh-workers
 help / color / mirror / code / Atom feed
From: Matthew Martin <phy1729@gmail.com>
To: zsh-workers@zsh.org
Subject: Hang in E01 due to zpty on OpenBSD
Date: Sun, 3 Apr 2022 16:42:24 -0500	[thread overview]
Message-ID: <YkoUwETgsrrqDeZN@CptOrmolo.darkstar> (raw)

E01 hangs on OpenBSD-current when run as the _pbuild user. The line that
hangs is L1435
	zpty subshell $ZTST_testdir/../Src/zsh -f +Z
which is because the read call in Modules/zpty.c L472
	ret = read(master, &syncch, 1);
never returns. I believe this is because the forked child fails to open
the corresponding tty when get_pty is called on 362 and the child exits.
I assume the EPERM on open is an OpenBSD bug, but zsh should probably
not hang either.

I'd appreciate if anyone could confirm the below is an accurate minimal
reproducer to report to OpenBSD.


#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>

static int
get_pty(char *path) {
	const char char1[] = "pqrstuvwxyzPQRST";
	const char char2[] = "0123456789"
	    "abcdefghijklmnopqrstuvwxyz"
	    "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

	const char *p1, *p2;
	int fd;

	strcpy(path, "/dev/ptyxx");

	for (p1 = char1; *p1; p1++) {
		path[8] = *p1;
		for (p2 = char2; *p2; p2++) {
			path[9] = *p2;
			if ((fd = open(path, O_RDWR|O_NOCTTY)) >= 0) {
				return fd;
			}
		}
	}

	return -1;
}

int
main() {
	char path[11];
	int ptyfd, ttyfd;

	if ((ptyfd = get_pty(path)) == -1) {
		err(1, "get_pty");
	}

	printf("%d: %s\n", ptyfd, path);

	path[5] = 't';
	if ((ttyfd = open(path, O_RDWR|O_NOCTTY)) == -1) {
		err(1, "open");
	}

	printf("%d: %s\n", ttyfd, path);
}


             reply	other threads:[~2022-04-03 21:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-03 21:42 Matthew Martin [this message]
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
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=YkoUwETgsrrqDeZN@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).