From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Newsgroups: gmane.lisp.guile.bugs Subject: bug#52835: [PATCH 0/2] Fix spawning a child not setting standard fds properly Date: Tue, 29 Nov 2022 16:05:05 +0100 Message-ID: <875yex4x9a.fsf_-_@gnu.org> References: <1d64d8e0e292fc3a89bcd491dd8f10171cb7c804.1662358976.git.dev@jpoiret.xyz> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="36146"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.2 (gnu/linux) Cc: 52835@debbugs.gnu.org, Timothy Sample To: Josselin Poiret Original-X-From: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Tue Nov 29 16:06:30 2022 Return-path: Envelope-to: guile-bugs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p02Bo-00095r-Mi for guile-bugs@m.gmane-mx.org; Tue, 29 Nov 2022 16:06:28 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1p02BW-0007MD-1F; Tue, 29 Nov 2022 10:06:10 -0500 Original-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 1p02BP-0007Ib-C0 for bug-guile@gnu.org; Tue, 29 Nov 2022 10:06:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1p02BP-0005d7-3b for bug-guile@gnu.org; Tue, 29 Nov 2022 10:06:03 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1p02BO-0003Qi-3t for bug-guile@gnu.org; Tue, 29 Nov 2022 10:06:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Tue, 29 Nov 2022 15:06:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52835 X-GNU-PR-Package: guile X-GNU-PR-Keywords: patch Original-Received: via spool by 52835-submit@debbugs.gnu.org id=B52835.166973435913165 (code B ref 52835); Tue, 29 Nov 2022 15:06:02 +0000 Original-Received: (at 52835) by debbugs.gnu.org; 29 Nov 2022 15:05:59 +0000 Original-Received: from localhost ([127.0.0.1]:54626 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p02BE-0003Q8-6w for submit@debbugs.gnu.org; Tue, 29 Nov 2022 10:05:59 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:54744) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1p02B9-0003Q1-VX for 52835@debbugs.gnu.org; Tue, 29 Nov 2022 10:05:51 -0500 Original-Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p02B3-0005W1-Q4; Tue, 29 Nov 2022 10:05:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:In-Reply-To:Date:References:Subject:To: From; bh=+whozZqY7Owv/m2bJZrjq7uG9LXyPSDhyrsypwHPcjg=; b=qVDInaV3q22su+Gnm47Z mZxXbSwZ/kIkQQDrvUO2pjX+PMvCLrIs7tlE9h6W099ILsP6EWwqClNi0VUvwBc30dbhgK/bVMSxr ozGbNDXIj/arFvPN17kZNVrx0Chea0TgAHO1pB2r8I26GYvFqhYOOLItz4l5zfnrWdzfpquovqLZ0 Uuqi87v3QEiKyK8a3abUY9MHrgMG++94d+1HroBaJth5UWvOEIDphTeONeuP2Gw1XUs23K2nz2AbJ CniVQ60rBf3UVDL2ajkfoD+ohSmvgojULW1ThD/gbxEH5jRWDkkOS0QK6e7PzvI1MhM/4OjAOF0qw CTBJjKwvGFKpdw==; Original-Received: from [193.50.110.137] (helo=ribbon) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1p02AZ-0006jJ-MW; Tue, 29 Nov 2022 10:05:39 -0500 In-Reply-To: <1d64d8e0e292fc3a89bcd491dd8f10171cb7c804.1662358976.git.dev@jpoiret.xyz> (Josselin Poiret's message of "Mon, 5 Sep 2022 08:48:15 +0200") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.bugs:10453 Archived-At: Hi Josselin, Sorry for taking so long to come back to you. I think this is great work! I pushed it as =E2=80=98wip-posix-spawn=E2=80=99 so others can give = it a try. Josselin Poiret skribis: > * libguile/posix.c (renumber_file_descriptor, start_child, > scm_piped_process): Remove functions. > (scm_port_to_fd_with_default): New helper function. > (scm_system_star): Rewrite using scm_spawn_process. > (scm_init_popen): Remove the definition of piped-process. > (scm_init_posix): Now make popen available unconditionally. > > * module/ice-9/popen.scm (port-with-defaults): New helper procedure. > (spawn): New procedure. > (open-process): Rewrite using spawn. > (pipeline): Rewrite using spawn*. > > * test-suite/tests/popen.test ("piped-process", "piped-process: > with-output"): Removed tests. > ("spawn", "spawn: with output"): Added tests. > * test-suite/tests/posix.test ("http://bugs.gnu.org/13166", "exit code > for nonexistent file", "https://bugs.gnu.org/55596"): Remove obsolete > tests. > ("exception for nonexistent file"): Add test. > --- > libguile/posix.c | 218 +++--------------------------------- > module/ice-9/popen.scm | 83 ++++++++++---- > test-suite/tests/popen.test | 14 +-- > test-suite/tests/posix.test | 36 +++--- > 4 files changed, 102 insertions(+), 249 deletions(-) More deletions than insertions. =F0=9F=91=8D That scary-looking Gnulib update seems to have worked well. I have mostly cosmetic/polishing comments and one issue with =E2=80=98syste= m*=E2=80=99. I can actually do that on your behalf if you=E2=80=99re unavailable these d= ays; let me know what you prefer. > static SCM > scm_spawn_process (SCM prog, SCM args, SCM scm_in, SCM scm_out, SCM scm_= err) > #define FUNC_NAME "spawn*" For top-level functions, please add a comment above explaining what it does. I would call this one =E2=80=98primitive-spawn=E2=80=99 rather than =E2=80= =98spawn*=E2=80=99 and keep it private to (ice-9 popen). > +(define* (spawn exec-file argv #:key > + (in (current-input-port)) > + (out (current-output-port)) > + (err (current-error-port))) Please add a docstring. It may also be worth documenting it in the manual given that it=E2=80=99s public. > + (let* ((in (port-with-defaults in "r")) > + (out (port-with-defaults out "w")) > + (err (port-with-defaults err "w")) I=E2=80=99d make it =E2=80=9Cr0=E2=80=9D and =E2=80=9Cw0=E2=80=9D since we= =E2=80=99re doing to throw the ports away right after. We could even avoid allocating a port when we=E2=80=99re going to use /dev/= null (and thus go with =E2=80=98open-fdes=E2=80=99 directly), but that=E2=80=99s= a micro-optimization we can keep for later. > +++ b/test-suite/tests/posix.test > @@ -236,24 +236,24 @@ >=20=20 > (with-test-prefix "system*" >=20=20 > - (pass-if "http://bugs.gnu.org/13166" > - ;; With Guile up to 2.0.7 included, the child process launched by > - ;; `system*' would remain alive after an `execvp' failure. > - (let ((me (getpid))) > - (and (not (zero? (system* "something-that-does-not-exist"))) > - (=3D me (getpid))))) I=E2=80=99d keep this one, I guess it doesn=E2=80=99t hurt? > - (pass-if-equal "exit code for nonexistent file" > - 127 ;aka. EX_NOTFOUND > - (status:exit-val (system* "something-that-does-not-exist"))) It=E2=80=99s good that we have better error reporting thanks to =E2=80=98po= six_spawn=E2=80=99. However, I don=E2=80=99t think we can change that in 3.0. What about, for = 3.0, adding a layer around =E2=80=98spawn=E2=80=99 so that =E2=80=98system*=E2= =80=99 still returns 127 when =E2=80=98spawn=E2=80=99 throws to =E2=80=98system-error=E2=80=99? > - (pass-if-equal "https://bugs.gnu.org/55596" > - 127 > - ;; The parameterization below used to cause 'start_child' to close > - ;; fd 2 in the child process, which in turn would cause it to > - ;; segfault, leading to a wrong exit code. > - (parameterize ((current-output-port (current-error-port))) > - (status:exit-val (system* "something-that-does-not-exist"))))) Likewise we should keep this one. > + (pass-if-equal "exception for nonexistent file" > + 2 ; ENOENT > + (call-with-prompt 'escape > + (lambda () > + (with-exception-handler > + (lambda (exn) > + (let* ((kind (exception-kind exn)) > + (errno (and (eq? kind 'system-error) > + (car (car > + (cdr (cdr (cdr (exception-args > + exn))))))))) > + (abort-to-prompt 'escape errno))) > + (lambda () > + (status:exit-val (system* > + "something-that-does-not-exist"))) > + #:unwind? #t)) > + (lambda (k arg) > + arg)))) We=E2=80=99ll have to leave this change for the next major series of Guile. Thanks! Ludo=E2=80=99.