Friday, January 27, 2023

update lang/guile3 to 3.0.9

guile received a minor update, the changelog is available here:

https://git.savannah.gnu.org/gitweb/?p=guile.git;a=blob;f=NEWS;h=4313880c73b09bc3398f0b4b08eb362a4ad7a29e;hb=HEAD

The new function `spawn' and existing functions like `system*',
`open-pipe' and `pipeline' are now written in terms of posix_spawn,
and this brought pain and suffering because of the introduced
regression.

Turns out they're using posix_spawn wrong (i presume) by scheduling
the closing of 3...1023 via posix_spawn_file_actions_addclose. Yep,
all 1020 fds. I've filed a bug upstream[0], but the TL;DR is that
close(2) fails, posix_spawn cares about its return value and quits.
I'm using an ugly hack to fix it, but it's the best I could think of
without rewriting guile to use CLOEXEC extensively, or leaking fd to
child processes.

While here I've also tweaked a few regress so they pass correctly,
I'll take care of upstreaming these patches if I don't forget.

Almost all tests are passing, and the few (4) that don't are bogus or
for stuff we don't have or don't do on OpenBSD anyway.

I intend to commit this update in a week or so, depending on the
feedback I get (testing on !amd64 is greatly appreciated!) and
upstream response on the bug.

[0]: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=61095

Index: Makefile
===================================================================
RCS file: /home/cvs/ports/lang/guile3/Makefile,v
retrieving revision 1.3
diff -u -p -r1.3 Makefile
--- Makefile 19 Aug 2022 07:24:09 -0000 1.3
+++ Makefile 27 Jan 2023 12:30:46 -0000
@@ -3,10 +3,9 @@ BROKEN-powerpc = stage0 abort trap, bad

COMMENT= GNU's Ubiquitous Intelligent Language for Extension

-VERSION= 3.0.8
+VERSION= 3.0.9
DISTNAME= guile-${VERSION}
PKGNAME= guile3-${VERSION}
-REVISION= 0
V= ${VERSION:R}
SUBST_VARS= V

Index: distinfo
===================================================================
RCS file: /home/cvs/ports/lang/guile3/distinfo,v
retrieving revision 1.1.1.1
diff -u -p -r1.1.1.1 distinfo
--- distinfo 31 Jul 2022 08:50:20 -0000 1.1.1.1
+++ distinfo 26 Jan 2023 17:31:31 -0000
@@ -1,2 +1,2 @@
-SHA256 (guile-3.0.8.tar.gz) = 8lrgwm6RGvG1AFKS1PVmIYefdNaVizB0HPZ9i2/rIBY=
-SIZE (guile-3.0.8.tar.gz) = 10438342
+SHA256 (guile-3.0.9.tar.gz) = GFJQea0poNRtFcdlgbXZHIcCMBv9ghZm0uHRNyYWKBE=
+SIZE (guile-3.0.9.tar.gz) = 9734735
Index: patches/patch-libguile_posix_c
===================================================================
RCS file: patches/patch-libguile_posix_c
diff -N patches/patch-libguile_posix_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-libguile_posix_c 27 Jan 2023 12:10:40 -0000
@@ -0,0 +1,27 @@
+fix close_inherited_fds_slow
+
+The intent of close_inherited_fds_slow is to mimick closefrom(2) in the
+posix_spawn API, i.e. schedule the closing of all fds > 2 after fork().
+
+However, the way this is implemented in non-linux OSes is to schedule
+the closing of 3..1023. This fails due to EBADF in posix_spawn after
+the fork() and makes it exit(127).
+
+Index: libguile/posix.c
+--- libguile/posix.c.orig
++++ libguile/posix.c
+@@ -1325,8 +1325,12 @@ SCM_DEFINE (scm_fork, "primitive-fork", 0, 0, 0,
+ static void
+ close_inherited_fds_slow (posix_spawn_file_actions_t *actions, int max_fd)
+ {
+- while (--max_fd > 2)
+- posix_spawn_file_actions_addclose (actions, max_fd);
++ struct stat sb;
++ max_fd = getdtablecount();
++ while (--max_fd > 2) {
++ if (fstat(max_fd, &sb) != -1)
++ posix_spawn_file_actions_addclose (actions, max_fd);
++ }
+ }
+
+ static void
Index: patches/patch-test-suite_standalone_test-system-cmds
===================================================================
RCS file: patches/patch-test-suite_standalone_test-system-cmds
diff -N patches/patch-test-suite_standalone_test-system-cmds
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-test-suite_standalone_test-system-cmds 27 Jan 2023 16:42:11 -0000
@@ -0,0 +1,24 @@
+use 'sh -c' instead of "guile -c" which can't work; we're only
+interested in the exit code.
+
+Index: test-suite/standalone/test-system-cmds
+--- test-suite/standalone/test-system-cmds.orig
++++ test-suite/standalone/test-system-cmds
+@@ -12,7 +12,7 @@ exec guile -q -s "$0" "$@"
+
+ ;; Note: Use double quotes since simple quotes are not supported by
+ ;; `cmd.exe' on Windows.
+- (let ((rs (status:exit-val (system "guile -c \"(exit 42)\""))))
++ (let ((rs (status:exit-val (system "sh -c \"exit 42\""))))
+ (if (not (= 42 rs))
+ (begin
+ (simple-format
+@@ -22,7 +22,7 @@ exec guile -q -s "$0" "$@"
+ (exit 1)))))
+
+ (define (test-system*-cmd)
+- (let ((rs (status:exit-val (system* "guile" "-c" "(exit 42)"))))
++ (let ((rs (status:exit-val (system* "sh" "-c" "exit 42"))))
+ (if (not (= 42 rs))
+ (begin
+ (simple-format
Index: patches/patch-test-suite_tests_posix_test
===================================================================
RCS file: patches/patch-test-suite_tests_posix_test
diff -N patches/patch-test-suite_tests_posix_test
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-test-suite_tests_posix_test 27 Jan 2023 18:47:40 -0000
@@ -0,0 +1,55 @@
+ - wc pads the result with blanks, trim its output
+ - use "seq 3" rather than assuming /proc is available
+ - fix nonsensical crypt invocation, use examples from manpage
+
+Index: test-suite/tests/posix.test
+--- test-suite/tests/posix.test.orig
++++ test-suite/tests/posix.test
+@@ -411,7 +411,7 @@
+ (display "Hello world.\n" (cdr a+b))
+ (close-port (cdr a+b))
+
+- (let ((str (get-string-all (car c+d))))
++ (let ((str (string-trim (get-string-all (car c+d)))))
+ (close-port (car c+d))
+ (waitpid pid)
+ str)))
+@@ -428,18 +428,16 @@
+ (waitpid pid)
+ str)))
+
+- (pass-if-equal "ls /proc/self/fd"
+- "0\n1\n2\n3\n" ;fourth FD is for /proc/self/fd
+- (if (file-exists? "/proc/self/fd") ;Linux
+- (let* ((input+output (pipe))
+- (pid (spawn "ls" '("ls" "/proc/self/fd")
+- #:output (cdr input+output))))
+- (close-port (cdr input+output))
+- (let ((str (get-string-all (car input+output))))
+- (close-port (car input+output))
+- (waitpid pid)
+- str))
+- (throw 'unresolved)))
++ (pass-if-equal "seq 3"
++ "1\n2\n3\n"
++ (let* ((input+output (pipe))
++ (pid (spawn "seq" '("seq" "3")
++ #:output (cdr input+output))))
++ (close-port (cdr input+output))
++ (let ((str (get-string-all (car input+output))))
++ (close-port (car input+output))
++ (waitpid pid)
++ str)))
+
+ (pass-if-equal "file not found"
+ ENOENT
+@@ -459,7 +457,8 @@
+ (pass-if "basic usage"
+ (if (not (defined? 'crypt))
+ (throw 'unsupported)
+- (string? (crypt "pass" "abcdefg"))))
++ (string? (crypt "OrpheanBeholderScryDoubt"
++ "$2b$12$FPWWO2RJ3CK4FINTw0Hi8OiPKJcX653gzSS.jqltHFMxyDmmQ0Hqq"))))
+
+ (pass-if "crypt invalid salt on glibc"
+ (begin
Index: pkg/PLIST
===================================================================
RCS file: /home/cvs/ports/lang/guile3/pkg/PLIST,v
retrieving revision 1.2
diff -u -p -r1.2 PLIST
--- pkg/PLIST 31 Jul 2022 09:14:31 -0000 1.2
+++ pkg/PLIST 26 Jan 2023 23:36:21 -0000
@@ -328,7 +328,9 @@ lib/guile/${V}/ccache/rnrs/arithmetic/bi
lib/guile/${V}/ccache/rnrs/arithmetic/fixnums.go
lib/guile/${V}/ccache/rnrs/arithmetic/flonums.go
lib/guile/${V}/ccache/rnrs/base.go
+lib/guile/${V}/ccache/rnrs/bytevectors/
lib/guile/${V}/ccache/rnrs/bytevectors.go
+lib/guile/${V}/ccache/rnrs/bytevectors/gnu.go
lib/guile/${V}/ccache/rnrs/conditions.go
lib/guile/${V}/ccache/rnrs/control.go
lib/guile/${V}/ccache/rnrs/enums.go
@@ -714,7 +716,9 @@ share/guile/${V}/rnrs/arithmetic/bitwise
share/guile/${V}/rnrs/arithmetic/fixnums.scm
share/guile/${V}/rnrs/arithmetic/flonums.scm
share/guile/${V}/rnrs/base.scm
+share/guile/${V}/rnrs/bytevectors/
share/guile/${V}/rnrs/bytevectors.scm
+share/guile/${V}/rnrs/bytevectors/gnu.scm
share/guile/${V}/rnrs/conditions.scm
share/guile/${V}/rnrs/control.scm
share/guile/${V}/rnrs/enums.scm

No comments:

Post a Comment