From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 3856 invoked from network); 4 Apr 2022 02:34:32 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 4 Apr 2022 02:34:32 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1649039672; b=YzN5OeGjswbV6Z/u37QIVnpbS5VkEY99vsMYFNRjmKSyDrGTL8B/Bi9qK1p5X7WskBrNon/xjD kM82btrR314KVG2wq2FTpndRnw8b3vDxhLM3YlWl410XH2S/RfakUEkjtDmTCI/uUAeZjHMYkV 5NWanDDf6X8jC+JfZz1pez7bSBZ1z10YcIBZD8Gv+NnLWBeYAFfJswhOaSlJ6mB9OK9rhBhoSH rjgbM9Es+H9gGZBmoYS0K1rjm8Fq/KZkj2RPgKh5gTmEe0BhRTRA08geGb6Chv1N4NQMx/J8Zj /SzpJ/jy6a3ZktSjXAR9bY1u3eiV6RZlZIYjzHSDPlc/cQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ot1-f46.google.com) smtp.remote-ip=209.85.210.46; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1649039672; bh=eqBHx8WOa7KXig6KgIRjBCpSOOMBSHbw9vEAKvYWbdw=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:To:From:Date:DKIM-Signature:DKIM-Signature; b=bY+nl/VrvjVXKG2LSG8JIiHiFyytHxcYwfJrvI56OxjuWxaGr21xgqC5ZLdLPk6JGT1JDZJMgr VnV9EgE7m1zGKc+vQGLVgJ8Hf1Gns6ypiXJnL5w1VxZH8QU7GN6UaTjV0Lfkn8yl3lmL1xezsA FKJdLjAut8mrGPPO+B8cczb7ipAFKYTkGeNki2rodC+Qu5zauJAmgPYURNBO5Q+cNs7XHQZn1y jyC0Ox+kmSkcKAGZv9+ERIq3JAw4gDQJLy7KtHeNH5gR0V517L8KW/nzXl4rEsAzcUjB+RQO0R SSaXsNgJEX9lvVCF2SmLjRusXTbKdCHiD2/zLVQyWPYAhA==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:To:From:Date:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=ig6jISVH9YFC60WaYZ7XaUwo97XRbx6TfKhasAcQQNg=; b=iE1W6jFLjzbBwY2/iX31W3GWr5 yNz0w4J+r/7og8UMHmpQjzmIS/c6wQaHA9fgAsjLZ3A9Svft6PIWOkdoO2ImB6F/Q9iW4pinwrd0k xQlpVV20xZR43TsGvZnd6DRLnhB+nFFGbtoB+HBVTWvWx1qorlnn/u1pYhX3Q7LxWnXK3jIk4ulAO WQyeto7GPQENVW0lW2tfn8z4nX+KJS+AqSY+M7iW8GFVkJtzKl10AdppKyR6OI3uFS/jMhD2IaZ0e tLoTx+fOUPqY8mm82z4ym5xg9fzOkwVWRvaAqvhvSegLUWWVTiQ0njx/0yZvkK3emZe740RFDMOVB vYWDxGPg==; Received: from authenticated user by zero.zsh.org with local id 1nbCY3-0009Xp-IO; Mon, 04 Apr 2022 02:34:31 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f46.google.com) smtp.remote-ip=209.85.210.46; dkim=pass header.d=gmail.com header.s=20210112 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-ot1-f46.google.com ([209.85.210.46]:43665) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1nbCXk-0009CE-O0; Mon, 04 Apr 2022 02:34:14 +0000 Received: by mail-ot1-f46.google.com with SMTP id i23-20020a9d6117000000b005cb58c354e6so6355550otj.10 for ; Sun, 03 Apr 2022 19:34:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=ig6jISVH9YFC60WaYZ7XaUwo97XRbx6TfKhasAcQQNg=; b=YGMWnhJP4usG70mrHQOaZh/IZAHvE+EWfU9Qfbcxeg+kLanZhgEPU+x/HRUSYXrejY SOIzy+YXO7bBGtJqnFit+TjeakXGOB+Fgic6T1hFGqPFFXYKLI8UfkqkqkWO/yfns7hO Uw7P1NawamNM8L+wDs/2z7Fsdd4LOmeFLILTYq5bTk+aORHXMFlVLRwK/qdHVrUkH3De jYzquNWofDvpVizQfEfxGTmNNUX+a9me3V4FFT90+kjtamcka0cM1M7HIyEh/yfS+1QM Yt/qOh2Uk+xnAg8TvbRnkBOhNZ5h9Ln6c0bNN5SVCMPJxRkEA69WOJR95kABmwxZbO2Z 4UqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:subject:message-id:mail-followup-to :references:mime-version:content-disposition:in-reply-to; bh=ig6jISVH9YFC60WaYZ7XaUwo97XRbx6TfKhasAcQQNg=; b=thkq5Lf3/INOuozNB9CT6yd6oZgU2rL8BYRgIdjVwELhCOGkIgCNQO5slZnNnZNfjT 9717aHxEh01nFKijQR4UZxuCKUdrV9QqfvvRgHoMc4s3pglKoWD6bZPGB96uV+dUGh5d hc/WtalZ0IQouAdGZk6BtSIsUANmh887SfFeSehkt4Y1LChr1dNrH+hwHOmrNIALj+Ka Cr6FnKf0q0udkMQ21tNPHcq027tg4uNHV7Alw+QIsDActbNV+AfzfRQOWj09yWLOxVIq EUp12fTgTwC2vUYCCRxuzjnO/0NcR0zYhK06lQfe3Y32i1SciIq0K/iaV4W4QNr5TDU5 WdaA== X-Gm-Message-State: AOAM532nZwzoQpTaVevRnwZ1qx+QRXbhE8m3BOLcXGOuH4LsrqqSIQcx K5pCUlnm17qCzC4d+XSmwNEFi6klwNM= X-Google-Smtp-Source: ABdhPJzeo1snLYWK5qAL8kinGyYmZwGIGfFOEKgz/NePWhVexnBPieoEqqdpTvrC2LyPSpbUuAoXsw== X-Received: by 2002:a05:6830:1c3d:b0:5cd:97c1:2590 with SMTP id f29-20020a0568301c3d00b005cd97c12590mr11084921ote.90.1649039651124; Sun, 03 Apr 2022 19:34:11 -0700 (PDT) Received: from CptOrmolo.darkstar (cpe-76-184-110-212.tx.res.rr.com. [76.184.110.212]) by smtp.gmail.com with ESMTPSA id f79-20020a4a5852000000b003291b52dc7csm3057065oob.15.2022.04.03.19.34.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Apr 2022 19:34:10 -0700 (PDT) Date: Sun, 3 Apr 2022 21:34:07 -0500 From: Matthew Martin To: zsh-workers@zsh.org Subject: Re: Hang in E01 due to zpty on OpenBSD Message-ID: Mail-Followup-To: zsh-workers@zsh.org References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Seq: 49980 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: On Sun, Apr 03, 2022 at 06:04:30PM -0700, Bart Schaefer wrote: > On Sun, Apr 3, 2022 at 2:43 PM Matthew Martin 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 +#include +#include +#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 @@ -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