GNU bug report logs - #52835
[PATCH 0/2] Fix spawning a child not setting standard fds properly

Previous Next

Package: guile;

Reported by: Josselin Poiret <dev <at> jpoiret.xyz>

Date: Mon, 27 Dec 2021 21:27:01 UTC

Severity: normal

Tags: patch

Done: Ludovic Courtès <ludo <at> gnu.org>

Bug is archived. No further changes may be made.

Full log


Message #92 received at 52835 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Josselin Poiret <dev <at> jpoiret.xyz>
Cc: 52835 <at> debbugs.gnu.org
Subject: Re: bug#52835: [PATCH 0/2] Fix spawning a child not setting
 standard fds properly
Date: Sun, 25 Dec 2022 18:03:48 +0100
Josselin Poiret <dev <at> jpoiret.xyz> skribis:

> * libguile/posix.c: Include spawn.h from Gnulib.
> (do_spawn, scm_spawn_process): New functions.
> * module/ice-9/spawn.scm: New file
> (spawn): New procedure.
> ---
>  libguile/posix.c       | 82 ++++++++++++++++++++++++++++++++++++++++++
>  libguile/posix.h       |  2 ++
>  module/ice-9/spawn.scm | 54 ++++++++++++++++++++++++++++
>  3 files changed, 138 insertions(+)

The new module should be added to ‘am/bootstrap.am’.

> +SCM_API SCM scm_spawn_process (SCM prog, SCM args, SCM env,
> +                               SCM in, SCM out, SCM err);

Let’s keep it ‘SCM_INTERNAL’.

> +(define* (spawn exec-file
> +                #:optional (args (list exec-file))
> +                #:key      (env (environ))
> +                           (in (current-input-port))
> +                           (out (current-output-port))
> +                           (err (current-error-port)))

s/exec-file/program/
s/args/arguments/
s/env/environment/

s/in/standard-input/
s/out/standard-output/
s/err/standard-error/

Maybe we could allow these two be either ports or file descriptors?

> +  "Spawns a new process running the program @var{exec} with arguments
> +@var{args}, in the environment specified by the list of environment
> +variable strings @var{env}, and with standard input, output and error
> +set to the ports specified by @var{in}, @var{out}, @var{err}.  Note that
> +the last part only works with fd-backed ports."
> +  (let* ((in (port-with-defaults in "r"))
> +         (out (port-with-defaults out "w"))
> +         (err (port-with-defaults err "w"))
> +         ;; Increment port revealed counts while to prevent ports GC'ing and
> +         ;; closing the associated fds while we spawn the process.
> +         (result (spawn* exec-file
> +                         args
> +                         env
> +                         (port->fdes in)
> +                         (port->fdes out)
> +                         (port->fdes err))))

I believe ‘spawn*’ is unbound here because it’s defined by
‘scm_init_popen’, which is called within the (ice-9 popen) module.

Ludo’.




This bug report was last modified 2 years and 128 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.