From unknown Wed Aug 20 05:15:44 2025 X-Loop: help-debbugs@gnu.org Subject: bug#64216: Proc open-input-pipe returns #eof when reading on macOS, works as expected on Linux Resent-From: Jose Ortiz Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Thu, 22 Jun 2023 05:48:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 64216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 64216@debbugs.gnu.org X-Debbugs-Original-To: bug-guile@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.168741285015430 (code B ref -1); Thu, 22 Jun 2023 05:48:02 +0000 Received: (at submit) by debbugs.gnu.org; 22 Jun 2023 05:47:30 +0000 Received: from localhost ([127.0.0.1]:34614 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qCDAH-00040h-Iw for submit@debbugs.gnu.org; Thu, 22 Jun 2023 01:47:30 -0400 Received: from lists.gnu.org ([209.51.188.17]:57972) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qC8ER-0000Mx-BY for submit@debbugs.gnu.org; Wed, 21 Jun 2023 20:31:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qC8EN-0005c9-HW for bug-guile@gnu.org; Wed, 21 Jun 2023 20:31:23 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qC8EL-0000SW-V8 for bug-guile@gnu.org; Wed, 21 Jun 2023 20:31:23 -0400 Received: by mail-pg1-x535.google.com with SMTP id 41be03b00d2f7-543d32eed7cso2677077a12.2 for ; Wed, 21 Jun 2023 17:31:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687393880; x=1689985880; h=subject:from:content-language:to:user-agent:mime-version:date :message-id:from:to:cc:subject:date:message-id:reply-to; bh=St+BzN2CgNBNcniyc59wgLI24AKIrwXZt7FiXoHxHd0=; b=k6DY14QX3zIDiRfOwrG4GMjbpbPb5NDZgKN27Zxftxp18DS/lIf3Z0CmlIAFyKtJ4P 40+dNs1MLYIDEMKPP5uHXapkd6E4ZfZDdSe1qqz8AMMgVFonJ+JRfOOBS6XcsqKF/GGn 8AXV1n/hOIeaILC4j5+g4JaFxHRvpgpSsNKzA9FDF0JRP+ZoILLgh46iArMFNXLC0UMp IFNeCjzpNGPfTqJA/nEMPYlKAZ7W92glkhaFwDkcqH9x95/QOM9Iyuq3ekpn4k8M322d RJQ05hkHAHNwb1hCAIIV40fTuRtBSnF+h6GFWMQHelc4wMNaM7erU6YK2rvcrO6PFnHa L8yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687393880; x=1689985880; h=subject:from:content-language:to:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=St+BzN2CgNBNcniyc59wgLI24AKIrwXZt7FiXoHxHd0=; b=AB8x2e7FAmHJGFGf7+TFERrPGIGbQ4YXK4+TVDcnnSr7iUwW699Gl9SjrB7cwE0UxH V98eG8stz4j0aCfdWRGzVUi0VIiL2i4ULuMaPILvy0AD5Me4OPa0MLiYvSuTlfmd7Nxq zcKDWWgA67HYibPGIxmnxlGB5ikd8sSuKUNlYuKa1lZcdYi8FupolyuY54MB78Ke8Kce k0mhYWXyyP04L0wyXbv8IO1VETXtcIcitkZxaampTInQ5yrPh0jp8Yx19KdI/FW7Rpq3 ibkIkIJqhuvGAPw9SJMn3+05fOgj/hHKjJ/CoF1XWfgPBPa9wyF/0qF/HUDfErzKiaK/ KTPw== X-Gm-Message-State: AC+VfDzJpqR8YRqxR+zICDz+rjMzBkDNgVUKVsNUyuhosSuMwrhKjhva vSMu6jlGC8fn5+RZvXAuscN3tC0CmPrSZg== X-Google-Smtp-Source: ACHHUZ7ZBI/ZCDMSa/fdLQCFnuQyD9XHwdoogpH4fT4hQRuu+5PVB7E2nvpdWHpbkEWelD88r7BhDA== X-Received: by 2002:a17:902:eac2:b0:1b1:ae33:30de with SMTP id p2-20020a170902eac200b001b1ae3330demr13927092pld.13.1687393880025; Wed, 21 Jun 2023 17:31:20 -0700 (PDT) Received: from [192.168.6.249] ([68.72.208.140]) by smtp.gmail.com with ESMTPSA id io20-20020a17090312d400b001ac38343438sm4041459plb.176.2023.06.21.17.31.19 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 21 Jun 2023 17:31:19 -0700 (PDT) Content-Type: multipart/alternative; boundary="------------VlzCJCkTxZGvDLUk29OL0HOp" Message-ID: <343e5a96-4bd0-4fe4-2959-c12f1fa0409b@gmail.com> Date: Wed, 21 Jun 2023 17:31:18 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 Content-Language: en-US From: Jose Ortiz Received-SPF: pass client-ip=2607:f8b0:4864:20::535; envelope-from=kotshie@gmail.com; helo=mail-pg1-x535.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Spam-Score: -1.3 (-) X-Mailman-Approved-At: Thu, 22 Jun 2023 01:47:26 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.3 (--) This is a multi-part message in MIME format. --------------VlzCJCkTxZGvDLUk29OL0HOp Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit When reading from open-input-pipe, it returns #eof on macOS devices, while it works properly in Linux. ``` (use-modules (ice-9 popen) (ice-9 rdelim)) (let* ((port (open-input-pipe "date --utc")) (str (read-line port))) (close-pipe port) str) ``` macOS> # linux> "Thu Jun 22 12:30:26 AM UTC 2023" Building latest and running popen.test also fails with: m1 :: Projects/guile/test-suite ? guile -L . -e main -s guile-test tests/popen.test Running tests/popen.test FAIL: tests/popen.test: open-input-pipe: echo hello FAIL: tests/popen.test: open-input-pipe: open-input-pipe process gets (current-input-port) as stdin ERROR: tests/popen.test: open-output-pipe: no duplicate - arguments: ((wrong-type-arg "string-append" "Wro ng type (expecting ~A): ~S" ("string" #f) (#f))) - Jose --------------VlzCJCkTxZGvDLUk29OL0HOp Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 7bit
When reading from open-input-pipe, it returns #eof on macOS devices, while it works properly in Linux.

```
(use-modules (ice-9 popen)
             (ice-9 rdelim))
(let* ((port (open-input-pipe "date --utc"))
       (str  (read-line port)))
  (close-pipe port)
  str)
```
macOS> #<eof>
linux> "Thu Jun 22 12:30:26 AM UTC 2023"


Building latest and running popen.test also fails with: 

m1 :: Projects/guile/test-suite ? guile -L . -e main -s guile-test tests/popen.test                                                                                                                                   
Running tests/popen.test                                                                                                                                                                                              
                                                                                                                                                                  
FAIL: tests/popen.test: open-input-pipe: echo hello                                                                                                                                                                   
FAIL: tests/popen.test: open-input-pipe: open-input-pipe process gets (current-input-port) as stdin                                                                                                                   
ERROR: tests/popen.test: open-output-pipe: no duplicate - arguments: ((wrong-type-arg "string-append" "Wro                                                                                                            
ng type (expecting ~A): ~S" ("string" #f) (#f)))  



- Jose 

--------------VlzCJCkTxZGvDLUk29OL0HOp-- From unknown Wed Aug 20 05:15:44 2025 X-Loop: help-debbugs@gnu.org Subject: bug#64216: "ice-9 popen" cannot open process on Darwin References: <343e5a96-4bd0-4fe4-2959-c12f1fa0409b@gmail.com> In-Reply-To: <343e5a96-4bd0-4fe4-2959-c12f1fa0409b@gmail.com> Resent-From: Torrekie Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 08 Aug 2023 11:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 64216@debbugs.gnu.org Received: via spool by 64216-submit@debbugs.gnu.org id=B64216.16914942599749 (code B ref 64216); Tue, 08 Aug 2023 11:31:01 +0000 Received: (at 64216) by debbugs.gnu.org; 8 Aug 2023 11:30:59 +0000 Received: from localhost ([127.0.0.1]:35371 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTKvS-0002W0-Qd for submit@debbugs.gnu.org; Tue, 08 Aug 2023 07:30:59 -0400 Received: from mta-06-4.privateemail.com ([198.54.122.146]:31172) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qTKvQ-0002FD-Ro for 64216@debbugs.gnu.org; Tue, 08 Aug 2023 07:30:57 -0400 Received: from mta-06.privateemail.com (localhost [127.0.0.1]) by mta-06.privateemail.com (Postfix) with ESMTP id 76E931800064 for <64216@debbugs.gnu.org>; Tue, 8 Aug 2023 07:30:50 -0400 (EDT) Received: from [127.0.0.1] (65.49.150.102.16clouds.com [65.49.150.102]) by mta-06.privateemail.com (Postfix) with ESMTPA for <64216@debbugs.gnu.org>; Tue, 8 Aug 2023 07:30:49 -0400 (EDT) From: Torrekie Content-Type: multipart/alternative; boundary="Apple-Mail=_2DEA9B85-134B-4A53-ADEE-F13532BB0CA3" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Message-Id: <06F0890F-B208-4AE6-96FD-B4EC11E2F3E1@torrekie.dev> Date: Tue, 8 Aug 2023 19:30:46 +0800 X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --Apple-Mail=_2DEA9B85-134B-4A53-ADEE-F13532BB0CA3 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Can confirm and reproduce this bug on macOS / iOS with Guile 3.0.9, it = seems guile-config also affected by this bug which causing "pkg-config" = calls always fail. ``` TorrekiedeMacBook-Pro:pv4 torrekie$ guile-config link error: ("/opt/homebrew/opt/pkg-config/bin/pkg-config" "--libs" = "guile-3.0") exited with non-zero error code 127 ``` In guile-config, pkg-config was called through "open-pipe*" ``` (define (pkg-config . args) (let* ((real-args (cons %pkg-config-program args)) (pipe (apply open-pipe* OPEN_READ real-args)) (output (read-delimited "" pipe)) (ret (close-pipe pipe))) (case (status:exit-val ret) ((0) (if (eof-object? output) "" output)) (else (display-line-error (format #f "error: ~s exited with non-zero error code ~A" (cons %pkg-config-program args) (status:exit-val = ret))) ;; assume pkg-config sent diagnostics to stdout (exit (status:exit-val ret)))))) ``` By attaching to LLDB I didn't see any exec/posix_spawn/popen been = called, by inspecting the source code I see Guile's popen was = implemented through `posix_spawn` ``` // libguile/posix.c static SCM scm_piped_process (SCM prog, SCM args, SCM from, SCM to) #define FUNC_NAME "piped-process" { pid_t pid; (void) piped_process (&pid, prog, args, from, to); if (pid =3D=3D -1) { /* Create a dummy process that exits with value 127 to mimic the previous fork + exec implementation. TODO: This is a compatibility shim to remove in the next stable series. */ pid =3D fork (); if (pid =3D=3D -1) SCM_SYSERROR; if (pid =3D=3D 0) _exit (127); } return scm_from_int (pid); } #undef FUNC_NAME ``` The function "piped_process" is a wrapper for "do_spawn", the "do_spawn" = retuns -1 while `posix_spawn` or `posix_spawnp` fails which finally = regarding to the `_exit(127)` in above code. But obviously posix_spawn = calls was working as expected in other programs, by doing `nm` we can = see libguile was not actually referenced posix_spawn, instead, it = defined an internal implementation of it. ``` TorrekiedeMacBook-Pro:pv4 torrekie$ nm = /opt/homebrew/opt/guile/lib/libguile-3.0.dylib | grep posix_spawn 00000000000bfdb4 t _gl_posix_spawn_internal 00000000000bfc90 t _rpl_posix_spawn_file_actions_addclose 00000000000bfd18 t _rpl_posix_spawn_file_actions_adddup2 ``` In m4/posix_spawn.m4 logics, Guile does not trust Darwin posix_spawn* = for some reason which causing REPLACE_POSIX_SPAWN has been defined, I am = trying to rebuild one without replacing posix_spawn and see what = happens. --Apple-Mail=_2DEA9B85-134B-4A53-ADEE-F13532BB0CA3 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Can confirm and = reproduce this bug on macOS / iOS with Guile 3.0.9, it seems = guile-config also affected by this bug which causing "pkg-config" calls = always fail.

```
TorrekiedeMacBook-Pro:pv4 torrekie$ guile-config = link
error: = ("/opt/homebrew/opt/pkg-config/bin/pkg-config" "--libs" "guile-3.0") = exited with non-zero error code 127
```

In guile-config, pkg-config was called through = "open-pipe*"
```
(define (pkg-config . args)
  (let* = ((real-args (cons %pkg-config-program args))
  =        (pipe (apply open-pipe* OPEN_READ = real-args))
        =  (output (read-delimited "" pipe))
  =        (ret (close-pipe pipe)))
    (case (status:exit-val ret)
      ((0) (if (eof-object? output) "" = output))
      (else = (display-line-error
        =      (format #f "error: ~s exited with non-zero error = code ~A"
            =          (cons %pkg-config-program args) = (status:exit-val ret)))
        =     ;; assume pkg-config sent diagnostics to stdout
            (exit = (status:exit-val ret))))))
```

By attaching to LLDB I = didn't see any exec/posix_spawn/popen been called, by inspecting the = source code I see Guile's popen was implemented through = `posix_spawn`

```
// libguile/posix.c
static SCM
scm_piped_process (SCM prog, SCM args, SCM from, SCM = to)
#define FUNC_NAME "piped-process"
{
  pid_t pid;

  (void) = piped_process (&pid, prog, args, from, to);
  if (pid =3D=3D -1)
    = {
      /* Create a dummy process = that exits with value 127 to mimic the
  =        previous fork + exec implementation. =  TODO: This is a
        =  compatibility shim to remove in the next stable series. =  */
      pid =3D fork = ();
      if (pid =3D=3D = -1)
        = SCM_SYSERROR;
      if (pid =3D=3D = 0)
        _exit = (127);
    }

  return scm_from_int = (pid);
}
#undef = FUNC_NAME
```

The function "piped_process" is a = wrapper for "do_spawn", the = "do_spawn" retuns -1 while `posix_spawn` or `posix_spawnp` fails which = finally regarding to the `_exit(127)` in above code. But obviously = posix_spawn calls was working as expected in other programs, by doing = `nm` we can see libguile was not actually referenced posix_spawn, = instead, it defined an internal implementation of = it.
```
TorrekiedeMacBook-Pro:pv4 torrekie$ nm = /opt/homebrew/opt/guile/lib/libguile-3.0.dylib | grep = posix_spawn
00000000000bfdb4 t = _gl_posix_spawn_internal
00000000000bfc90 t = _rpl_posix_spawn_file_actions_addclose
00000000000bfd18 t = _rpl_posix_spawn_file_actions_adddup2
```

In m4/posix_spawn.m4 = logics, Guile does not trust Darwin posix_spawn* for some reason which = causing REPLACE_POSIX_SPAWN has been defined, I am trying to = rebuild one without replacing posix_spawn and see what = happens.


= --Apple-Mail=_2DEA9B85-134B-4A53-ADEE-F13532BB0CA3-- From unknown Wed Aug 20 05:15:44 2025 X-Loop: help-debbugs@gnu.org Subject: bug#64216: libgnu __spawni fail on Darwin References: <343e5a96-4bd0-4fe4-2959-c12f1fa0409b@gmail.com> In-Reply-To: <343e5a96-4bd0-4fe4-2959-c12f1fa0409b@gmail.com> Resent-From: Torrekie Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Fri, 11 Aug 2023 10:31:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 64216@debbugs.gnu.org Received: via spool by 64216-submit@debbugs.gnu.org id=B64216.169174981332011 (code B ref 64216); Fri, 11 Aug 2023 10:31:01 +0000 Received: (at 64216) by debbugs.gnu.org; 11 Aug 2023 10:30:13 +0000 Received: from localhost ([127.0.0.1]:44985 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUPPI-0008KE-JR for submit@debbugs.gnu.org; Fri, 11 Aug 2023 06:30:13 -0400 Received: from mta-13-4.privateemail.com ([198.54.127.109]:15118) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUPPF-0008Is-AB for 64216@debbugs.gnu.org; Fri, 11 Aug 2023 06:30:10 -0400 Received: from mta-13.privateemail.com (localhost [127.0.0.1]) by mta-13.privateemail.com (Postfix) with ESMTP id 43C23180004E for <64216@debbugs.gnu.org>; Fri, 11 Aug 2023 06:30:03 -0400 (EDT) Received: from [127.0.0.1] (65.49.150.102.16clouds.com [65.49.150.102]) by mta-13.privateemail.com (Postfix) with ESMTPA for <64216@debbugs.gnu.org>; Fri, 11 Aug 2023 06:30:01 -0400 (EDT) From: Torrekie Content-Type: multipart/alternative; boundary="Apple-Mail=_7935A177-D0A9-4369-AE11-A95B9862E8DB" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Message-Id: Date: Fri, 11 Aug 2023 18:29:57 +0800 X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Score: -1.0 (-) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -2.0 (--) --Apple-Mail=_7935A177-D0A9-4369-AE11-A95B9862E8DB Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Due to the lack of attaching child process feature in LLDB, I cannot see = what was happening after a fork() call, but one thing is clear that the = alternative `posix_spawn` provided by lib/spawni.c was not quite working = as expected on Darwin systems (might only happens under arm64).=20 https://github.com/NanoComp/meep/issues/2495 = Same bug mentioned in this GitHub issue, and I have actually attempted = to undef REPLACE_POSIX_SPAWN to use system one, but it was still = corrupted by malformed file actions which returning 22 (EINVAL) and set = errno to ENOENT that may complaining about dup2-ed non-standard stdio = fds. One thing is for sure, when REPLACE_POSIX_SPAWN is defined, posix_spawn = calls will point to __spawni function as implementation. This function = fails before actually calling `execve` (Or I didn't successfully caught = that in lldb) This was my test result on macOS 11.2 arm64 /Applications/Xcode.app/Contents/Developer/usr/bin/make check-TESTS test-system-cmds: system* exit status was 127 rather than 42 FAIL: test-system-cmds PASS: test-bad-identifiers PASS: test-require-extension PASS: test-guile-snarf PASS: test-import-order PASS: test-command-line-encoding PASS: test-command-line-encoding2 PASS: test-language error: interrupted by the user PASS: test-guild-compile wrote = `/Users/torrekie/proj/guile-3.0.9/cache/guile/ccache/3.0-LE-8-4.6/Users/to= rrekie/proj/guile-3.0.9/test-suite/standalone/test-signal-fork.go' parent: 53087 ....child: ..53133 ............................................. completed PASS: test-signal-fork PASS: test-num2integral PASS: test-round PASS: test-asmobs PASS: test-ffi PASS: test-foreign-object-scm PASS: test-foreign-object-c PASS: test-list PASS: test-unwind PASS: test-conversion PASS: test-loose-ends PASS: test-fast-slot-ref PASS: test-mb-regexp PASS: test-use-srfi PASS: test-scm-c-read PASS: test-scm-take-locale-symbol PASS: test-scm-take-u8vector PASS: test-scm-to-latin1-string PASS: test-scm-values PASS: test-scm-c-bind-keyword-arguments PASS: test-srfi-4 PASS: test-extensions PASS: test-with-guile-module PASS: test-scm-with-guile PASS: test-scm-spawn-thread PASS: test-pthread-create SKIP: test-pthread-create-secondary PASS: test-smob-mark PASS: test-smob-mark-race wrote = `/Users/torrekie/proj/guile-3.0.9/cache/guile/ccache/3.0-LE-8-4.6/Users/to= rrekie/proj/guile-3.0.9/test-suite/standalone/test-stack-overflow.go' SKIP: test-stack-overflow wrote = `/Users/torrekie/proj/guile-3.0.9/cache/guile/ccache/3.0-LE-8-4.6/Users/to= rrekie/proj/guile-3.0.9/test-suite/standalone/test-out-of-memory.go' SKIP: test-out-of-memory ;;; (child-exception ("scm_fdes_to_port" "~A" ("Bad file descriptor") = (9))) ;;; (child-status 256) PASS: test-close-on-exec =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D 1 of 38 tests failed (3 tests were not run) Please report to bug-guile@gnu.org =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D make[5]: *** [check-TESTS] Error 1 make[4]: *** [check-am] Error 2 make[3]: *** [check] Error 2 make[2]: *** [check-recursive] Error 1 make[1]: *** [check-recursive] Error 1 make: *** [check] Error 2= --Apple-Mail=_7935A177-D0A9-4369-AE11-A95B9862E8DB Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii Due = to the lack of attaching child process feature in LLDB, I cannot see = what was happening after a fork() call, but one thing is clear that the = alternative `posix_spawn` provided by lib/spawni.c was not quite working = as expected on Darwin systems (might only happens under = arm64). 


Same bug mentioned in = this GitHub issue, and I have actually attempted to undef = REPLACE_POSIX_SPAWN to use system one, but it was still corrupted by = malformed file actions which returning 22 (EINVAL) and set errno to = ENOENT that may complaining about dup2-ed non-standard stdio = fds.

One thing = is for sure, when REPLACE_POSIX_SPAWN is defined, posix_spawn calls will point = to __spawni function as implementation. This function fails before = actually calling `execve` (Or I didn't successfully caught = that in lldb)

This was my test result on macOS 11.2 = arm64

/Applications/Xcode.app/Contents/Developer/usr/bin/make =  check-TESTS
test-system-cmds: system* exit status was 127 rather than = 42
FAIL: = test-system-cmds
PASS: test-bad-identifiers
PASS: = test-require-extension
PASS: test-guile-snarf
PASS: test-import-order
PASS: = test-command-line-encoding
PASS: test-command-line-encoding2
PASS: test-language
error: interrupted by the = user
PASS: = test-guild-compile
wrote = `/Users/torrekie/proj/guile-3.0.9/cache/guile/ccache/3.0-LE-8-4.6/Users/to= rrekie/proj/guile-3.0.9/test-suite/standalone/test-signal-fork.go'<= /font>
parent: = 53087
....child: ..53133
.............................................
completed
PASS: test-signal-fork
PASS: test-num2integral
PASS: test-round
PASS: test-asmobs
PASS: test-ffi
PASS: = test-foreign-object-scm
PASS: test-foreign-object-c
PASS: test-list
PASS: test-unwind
PASS: test-conversion
PASS: test-loose-ends
PASS: = test-fast-slot-ref
PASS: test-mb-regexp
PASS: test-use-srfi
PASS: test-scm-c-read
PASS: test-scm-take-locale-symbol
PASS: = test-scm-take-u8vector
PASS: test-scm-to-latin1-string
PASS: test-scm-values
PASS: = test-scm-c-bind-keyword-arguments
PASS: test-srfi-4
PASS: test-extensions
PASS: test-with-guile-module
PASS: = test-scm-with-guile
PASS: test-scm-spawn-thread
PASS: = test-pthread-create
SKIP: test-pthread-create-secondary
PASS: test-smob-mark
PASS: = test-smob-mark-race
wrote = `/Users/torrekie/proj/guile-3.0.9/cache/guile/ccache/3.0-LE-8-4.6/Users/to= rrekie/proj/guile-3.0.9/test-suite/standalone/test-stack-overflow.go'
SKIP: = test-stack-overflow
wrote = `/Users/torrekie/proj/guile-3.0.9/cache/guile/ccache/3.0-LE-8-4.6/Users/to= rrekie/proj/guile-3.0.9/test-suite/standalone/test-out-of-memory.go'
SKIP: = test-out-of-memory

;;; (child-exception ("scm_fdes_to_port" "~A" ("Bad file = descriptor") (9)))

;;; (child-status 256)
PASS: test-close-on-exec
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
1 of 38 tests failed
(3 tests were not run)
Please report to bug-guile@gnu.org
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
make[5]: *** [check-TESTS] Error = 1
make[4]: = *** [check-am] Error 2
make[3]: *** [check] Error 2
make[2]: *** [check-recursive] Error = 1
make[1]: = *** [check-recursive] Error 1
make: *** [check] Error = 2
= --Apple-Mail=_7935A177-D0A9-4369-AE11-A95B9862E8DB-- From unknown Wed Aug 20 05:15:44 2025 X-Loop: help-debbugs@gnu.org Subject: bug#64216: *spawn calls fixed in latest commit References: <343e5a96-4bd0-4fe4-2959-c12f1fa0409b@gmail.com> In-Reply-To: <343e5a96-4bd0-4fe4-2959-c12f1fa0409b@gmail.com> Resent-From: Torrekie Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sat, 12 Aug 2023 21:36:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64216 X-GNU-PR-Package: guile X-GNU-PR-Keywords: To: 64216@debbugs.gnu.org Received: via spool by 64216-submit@debbugs.gnu.org id=B64216.169187610616087 (code B ref 64216); Sat, 12 Aug 2023 21:36:02 +0000 Received: (at 64216) by debbugs.gnu.org; 12 Aug 2023 21:35:06 +0000 Received: from localhost ([127.0.0.1]:57707 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUwGH-0004BN-LL for submit@debbugs.gnu.org; Sat, 12 Aug 2023 17:35:06 -0400 Received: from mta-12-4.privateemail.com ([198.54.127.107]:20025) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1qUwGE-0004Ag-84 for 64216@debbugs.gnu.org; Sat, 12 Aug 2023 17:35:04 -0400 Received: from mta-12.privateemail.com (localhost [127.0.0.1]) by mta-12.privateemail.com (Postfix) with ESMTP id 19BCB18000B0 for <64216@debbugs.gnu.org>; Sat, 12 Aug 2023 17:34:56 -0400 (EDT) Received: from [127.0.0.1] (65.49.150.102.16clouds.com [65.49.150.102]) by mta-12.privateemail.com (Postfix) with ESMTPA for <64216@debbugs.gnu.org>; Sat, 12 Aug 2023 17:34:54 -0400 (EDT) From: Torrekie Content-Type: multipart/alternative; boundary="Apple-Mail=_7A464FE5-D3E7-4C31-A63F-9A33CF134FB8" Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Message-Id: <502B5303-E752-43AB-A187-E1DAE4A10AE7@torrekie.dev> Date: Sun, 13 Aug 2023 05:34:51 +0800 X-Mailer: Apple Mail (2.3654.60.0.2.21) X-Virus-Scanned: ClamAV using ClamSMTP X-Spam-Score: -0.0 (/) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: debbugs-submit-bounces@debbugs.gnu.org Sender: "Debbugs-submit" X-Spam-Score: -1.0 (-) --Apple-Mail=_7A464FE5-D3E7-4C31-A63F-9A33CF134FB8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii By inspecting commit ccd7400fdbebca73fc4340ad4ca0248655009f04, I see = this issue has been fixed for BSD posix_spawn and internal `__spawni`. diff --git a/libguile/posix.c b/libguile/posix.c index 3adc743c4..6776a7744 100644 --- a/libguile/posix.c +++ b/libguile/posix.c @@ -1390,12 +1390,19 @@ do_spawn (char *exec_file, char **exec_argv, = char **exec_env, /* Move the fds out of the way, so that duplicate fds or fds equal to 0, 1, 2 don't trample each other */ =20 - posix_spawn_file_actions_adddup2 (&actions, in, fd_slot[0]); - posix_spawn_file_actions_adddup2 (&actions, out, fd_slot[1]); - posix_spawn_file_actions_adddup2 (&actions, err, fd_slot[2]); - posix_spawn_file_actions_adddup2 (&actions, fd_slot[0], 0); - posix_spawn_file_actions_adddup2 (&actions, fd_slot[1], 1); - posix_spawn_file_actions_adddup2 (&actions, fd_slot[2], 2); + int dup2_action_from[] =3D {in, out, err, + fd_slot[0], fd_slot[1], fd_slot[2]}; + int dup2_action_to [] =3D {fd_slot[0], fd_slot[1], fd_slot[2], + 0, 1, 2}; + + errno =3D 0; + for (int i =3D 0; i < sizeof (dup2_action_from) / sizeof (int); i++) + { + errno =3D posix_spawn_file_actions_adddup2 (&actions, = dup2_action_from[i], + dup2_action_to[i]); + if (errno !=3D 0) + return -1; + } =20 #ifdef HAVE_ADDCLOSEFROM /* This function appears in glibc 2.34. It's both free from race Can confirm FreeBSD's patch = (https://github.com/freebsd/freebsd-ports/raw/6e9b9fd9dd69cbbfabd780e2cec9= e2b98d5aef1e/lang/guile3/files/extra-patch-upstream-fixes.patch = ) that = based on latest commits fixed the problem on Darwin iPad:/buildroot/guile-3.0.9 root# guile-config link -lguile-3.0 -lgc -lpthread iPad:/buildroot/guile-3.0.9 root# guile-config compile -D_THREAD_SAFE -I/usr/include/guile/3.0 -I/usr iPad:/buildroot/guile-3.0.9 root# /usr/bin/uname -a Darwin iPad 20.4.0 Darwin Kernel Version 20.4.0: Sun Feb 28 21:05:09 PST = 2021; root:xnu-7195.100.367~3/RELEASE_ARM64_T8101 arm64 iPad:/buildroot/guile-3.0.9 root# sw_vers ProductName: iPhone OS ProductVersion: 14.5.1 BuildVersion: 18E212= --Apple-Mail=_7A464FE5-D3E7-4C31-A63F-9A33CF134FB8 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii By = inspecting commit ccd7400fdbebca73fc4340ad4ca0248655009f04, I see = this issue has been fixed for BSD posix_spawn and internal = `__spawni`.

diff --git a/libguile/posix.c b/libguile/posix.c
index 3adc743c4..6776a7744 100644
--- = a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1390,12 +1390,19 @@ do_spawn (char *exec_file, char = **exec_argv, char **exec_env,
   /* Move = the fds out of the way, so that duplicate fds or fds equal
      to 0, 1, 2 don't trample each other = */
 
- =  posix_spawn_file_actions_adddup2 (&actions, in, = fd_slot[0]);
- =  posix_spawn_file_actions_adddup2 (&actions, out, = fd_slot[1]);
- =  posix_spawn_file_actions_adddup2 (&actions, err, = fd_slot[2]);
- =  posix_spawn_file_actions_adddup2 (&actions, fd_slot[0], = 0);
-  posix_spawn_file_actions_adddup2 = (&actions, fd_slot[1], 1);
- =  posix_spawn_file_actions_adddup2 (&actions, fd_slot[2], = 2);
+  int dup2_action_from[] =3D {in, out, = err,
+             =                fd_slot[0], = fd_slot[1], fd_slot[2]};
+  int dup2_action_to =  [] =3D {fd_slot[0], fd_slot[1], fd_slot[2],
+ =                     =        0, 1, 2};
+
+  errno =3D 0;
+  for (int i = =3D 0; i < sizeof (dup2_action_from) / sizeof (int); i++)
+    {
+     =  errno =3D posix_spawn_file_actions_adddup2 (&actions, = dup2_action_from[i],
+         =                     =                   =  dup2_action_to[i]);
+      if = (errno !=3D 0)
+        return = -1;
+    }
 
 #ifdef = HAVE_ADDCLOSEFROM
   /* This function = appears in glibc 2.34.  It's both free from race


= --Apple-Mail=_7A464FE5-D3E7-4C31-A63F-9A33CF134FB8--