Tue May 30 23:04:53 2023 UTC ()
vte3: improve patch to work around NetBSD posix_openpt(3) defect

Now that as of roughly 9.99.101 we have a posix_openpt(3) that applies
O_NONBLOCK and O_CLOEXEC, we don't need the fallback code. Now we
dynamically detect whether we need the fallback using the best
approximation we can (an assumption backed by a test case I recently
added). Tested on 9.3_STABLE, 10.0_BETA, and 10.99.4.


(gutteridge)
diff -r1.62 -r1.63 pkgsrc/x11/vte3/Makefile
diff -r1.22 -r1.23 pkgsrc/x11/vte3/distinfo
diff -r1.9 -r1.10 pkgsrc/x11/vte3/patches/patch-src_pty.cc

cvs diff -r1.62 -r1.63 pkgsrc/x11/vte3/Makefile (expand / switch to unified diff)

--- pkgsrc/x11/vte3/Makefile 2023/04/19 08:11:59 1.62
+++ pkgsrc/x11/vte3/Makefile 2023/05/30 23:04:53 1.63
@@ -1,18 +1,18 @@ @@ -1,18 +1,18 @@
1# $NetBSD: Makefile,v 1.62 2023/04/19 08:11:59 adam Exp $ 1# $NetBSD: Makefile,v 1.63 2023/05/30 23:04:53 gutteridge Exp $
2 2
3DISTNAME= vte-0.68.0 3DISTNAME= vte-0.68.0
4PKGNAME= ${DISTNAME:S/vte/vte3/} 4PKGNAME= ${DISTNAME:S/vte/vte3/}
5PKGREVISION= 12 5PKGREVISION= 13
6CATEGORIES= x11 6CATEGORIES= x11
7MASTER_SITES= ${MASTER_SITE_GITHUB:=GNOME/} 7MASTER_SITES= ${MASTER_SITE_GITHUB:=GNOME/}
8GITHUB_PROJECT= vte 8GITHUB_PROJECT= vte
9GITHUB_TAG= ${PKGVERSION_NOREV} 9GITHUB_TAG= ${PKGVERSION_NOREV}
10 10
11MAINTAINER= pkgsrc-users@NetBSD.org 11MAINTAINER= pkgsrc-users@NetBSD.org
12HOMEPAGE= https://www.gnome.org/ 12HOMEPAGE= https://www.gnome.org/
13COMMENT= Terminal widget with improved accessibility and I18N support 13COMMENT= Terminal widget with improved accessibility and I18N support
14LICENSE= gnu-lgpl-v2 14LICENSE= gnu-lgpl-v2
15 15
16PKGCONFIG_OVERRIDE_STAGE= post-configure 16PKGCONFIG_OVERRIDE_STAGE= post-configure
17PKGCONFIG_OVERRIDE+= output/meson-private/vte-2.91.pc 17PKGCONFIG_OVERRIDE+= output/meson-private/vte-2.91.pc
18 18

cvs diff -r1.22 -r1.23 pkgsrc/x11/vte3/distinfo (expand / switch to unified diff)

--- pkgsrc/x11/vte3/distinfo 2022/09/04 19:26:10 1.22
+++ pkgsrc/x11/vte3/distinfo 2023/05/30 23:04:53 1.23
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1$NetBSD: distinfo,v 1.22 2022/09/04 19:26:10 gutteridge Exp $ 1$NetBSD: distinfo,v 1.23 2023/05/30 23:04:53 gutteridge Exp $
2 2
3BLAKE2s (vte-0.68.0.tar.gz) = 1583ddbed30f848687a1ce02df9d03ce89a5b905a72a9cd1d866195931acbcb1 3BLAKE2s (vte-0.68.0.tar.gz) = 1583ddbed30f848687a1ce02df9d03ce89a5b905a72a9cd1d866195931acbcb1
4SHA512 (vte-0.68.0.tar.gz) = fb2260ae1363203cdccd0e0c6cafe29e5fb25947d2830a7ce1051f672fdc11c067791a8b74cb3017548e366976763fec2022e0c196ed501f46abb08876ad24d6 4SHA512 (vte-0.68.0.tar.gz) = fb2260ae1363203cdccd0e0c6cafe29e5fb25947d2830a7ce1051f672fdc11c067791a8b74cb3017548e366976763fec2022e0c196ed501f46abb08876ad24d6
5Size (vte-0.68.0.tar.gz) = 641981 bytes 5Size (vte-0.68.0.tar.gz) = 641981 bytes
6SHA1 (patch-bindings_vala_app.vala) = 09444285f642ab48849bbbc1ae663bee3567b8d4 6SHA1 (patch-bindings_vala_app.vala) = 09444285f642ab48849bbbc1ae663bee3567b8d4
7SHA1 (patch-meson.build) = 82125d3c18d848afffcb7a063c9e53ad8fd4ac62 7SHA1 (patch-meson.build) = 82125d3c18d848afffcb7a063c9e53ad8fd4ac62
8SHA1 (patch-src_app_app.cc) = 2548e01629aa563595387328638a52a5616ff0bd 8SHA1 (patch-src_app_app.cc) = 2548e01629aa563595387328638a52a5616ff0bd
9SHA1 (patch-src_dumpkeys.c) = 102f24d7404d46b13194f3431d0a864d480e5da7 9SHA1 (patch-src_dumpkeys.c) = 102f24d7404d46b13194f3431d0a864d480e5da7
10SHA1 (patch-src_meson.build) = a8e159688fb36e4cfac40249e279a670c9c6cda8 10SHA1 (patch-src_meson.build) = a8e159688fb36e4cfac40249e279a670c9c6cda8
11SHA1 (patch-src_mev.c) = b38dc42e02a8d5fa1e579349319f0b8c8b31dbce 11SHA1 (patch-src_mev.c) = b38dc42e02a8d5fa1e579349319f0b8c8b31dbce
12SHA1 (patch-src_missing.cc) = 807a3f6134d8dd6fd602326ce02ca6e2ed1d189d 12SHA1 (patch-src_missing.cc) = 807a3f6134d8dd6fd602326ce02ca6e2ed1d189d
13SHA1 (patch-src_pty.cc) = abd037769075f8ad9a7258f3bb970f3ed7e317cf 13SHA1 (patch-src_pty.cc) = a46b10e9921e6d6ea8fbf0939a73a7b4b83d3455
14SHA1 (patch-src_widget.cc) = cbc8b715b21248996bfb7c6abe355c5f4e510539 14SHA1 (patch-src_widget.cc) = cbc8b715b21248996bfb7c6abe355c5f4e510539

cvs diff -r1.9 -r1.10 pkgsrc/x11/vte3/patches/patch-src_pty.cc (expand / switch to unified diff)

--- pkgsrc/x11/vte3/patches/patch-src_pty.cc 2022/09/04 19:26:10 1.9
+++ pkgsrc/x11/vte3/patches/patch-src_pty.cc 2023/05/30 23:04:53 1.10
@@ -1,40 +1,61 @@ @@ -1,40 +1,61 @@
1$NetBSD: patch-src_pty.cc,v 1.9 2022/09/04 19:26:10 gutteridge Exp $ 1$NetBSD: patch-src_pty.cc,v 1.10 2023/05/30 23:04:53 gutteridge Exp $
2 2
3Use correct includes on SunOS. 3Use correct includes on SunOS.
4Functional fix of posix_openpt() on NetBSD. 4Functional fix of posix_openpt() on NetBSD.
5https://gitlab.gnome.org/GNOME/vte/-/issues/2575 5https://gitlab.gnome.org/GNOME/vte/-/issues/2575
6 6
7--- src/pty.cc.orig 2022-03-27 17:52:19.000000000 +0000 7--- src/pty.cc.orig 2022-03-27 17:52:19.000000000 +0000
8+++ src/pty.cc 8+++ src/pty.cc
9@@ -62,7 +62,9 @@ 9@@ -62,9 +62,15 @@
10 #ifdef HAVE_PTY_H 10 #ifdef HAVE_PTY_H
11 #include <pty.h> 11 #include <pty.h>
12 #endif 12 #endif
13-#if defined(__sun) && defined(HAVE_STROPTS_H) 13-#if defined(__sun) && defined(HAVE_STROPTS_H)
14+#if defined(__sun) 14+#if defined(__sun)
15+#include <sys/ioccom.h> 15+#include <sys/ioccom.h>
16+#include <sys/ptyvar.h> 16+#include <sys/ptyvar.h>
17 #include <stropts.h> 17 #include <stropts.h>
18 #endif 18 #endif
 19+#ifdef __NetBSD__
 20+#include <sys/param.h>
 21+#include <sys/sysctl.h>
 22+#endif
19 #include <glib.h> 23 #include <glib.h>
20@@ -426,7 +428,19 @@ _vte_pty_open_posix(void) 24 #include <gio/gio.h>
21 auto fd = vte::libc::FD{posix_openpt(O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC)}; 25 #include "debug.h"
 26@@ -427,6 +433,27 @@ _vte_pty_open_posix(void)
22 #ifndef __linux__ 27 #ifndef __linux__
23 /* Other kernels may not support CLOEXEC or NONBLOCK above, so try to fall back */ 28 /* Other kernels may not support CLOEXEC or NONBLOCK above, so try to fall back */
24- bool need_cloexec = false, need_nonblocking = false; 29 bool need_cloexec = false, need_nonblocking = false;
 30+
25+#ifdef __NetBSD__ 31+#ifdef __NetBSD__
26+ /* 32+ // NetBSD is a special case: prior to 9.99.101, posix_openpt() will not return
27+ * NetBSD's posix_openpt() will accept flags that don't actually get applied, so it 33+ // EINVAL for unknown/unsupported flags but instead silently ignore these flags
28+ * will return an FD with only O_RDWR actually set. Unlike other BSDs, it doesn't 34+ // and just return a valid PTY but without the NONBLOCK | CLOEXEC flags set.
29+ * return EINVAL when given inapplicable flags. We need to force the fallbacks below. 35+ // So we need to manually apply these flags there. See issue #2575.
30+ */ 36+ int mib[2], osrev;
31+ bool need_cloexec = true; 37+ size_t len;
32+ bool need_nonblocking = true; 38+
 39+ mib[0] = CTL_KERN;
 40+ mib[1] = KERN_OSREV;
 41+ len = sizeof(osrev);
 42+ sysctl(mib, 2, &osrev, &len, NULL, 0);
 43+ if (osrev < 999010100) {
 44+ need_cloexec = need_nonblocking = true;
 45+ _vte_debug_print(VTE_DEBUG_PTY,
 46+ "NetBSD < 9.99.101, forcing fallback "
 47+ "for NONBLOCK and CLOEXEC.\n");
 48+ }
33+#else 49+#else
34+ bool need_cloexec = false; 
35+ bool need_nonblocking = false; 
36+#endif /* __NetBSD__ */ 
37+ 50+
38 if (!fd && errno == EINVAL) { 51 if (!fd && errno == EINVAL) {
39 /* Try without NONBLOCK and apply the flag afterward */ 52 /* Try without NONBLOCK and apply the flag afterward */
40 need_nonblocking = true; 53 need_nonblocking = true;
 54@@ -437,6 +464,7 @@ _vte_pty_open_posix(void)
 55 fd = posix_openpt(O_RDWR | O_NOCTTY);
 56 }
 57 }
 58+#endif /* __NetBSD__ */
 59 #endif /* !linux */
 60
 61 if (!fd) {