guix-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug#54205] [PATCH v2] Factor out a public FORK-AND-CALL.


From: Liliana Marie Prikler
Subject: [bug#54205] [PATCH v2] Factor out a public FORK-AND-CALL.
Date: Tue, 01 Mar 2022 13:01:52 +0100
User-agent: Evolution 3.42.1

Am Dienstag, dem 01.03.2022 um 08:29 +0100 schrieb Attila Lendvai:
> This enables service implementations to easily inject code that is
> run before their service is started.  One such example is calling
> setrlimit from a start action to set NOFILE (the open files limit),
> before the service is exec'ed and inherits this value from the parent
> process, i.e. from Shepherd.
In general, I think such capabilities should be added to exec-command,
rather than resorting to a lambda.  It takes a little while to realize
that call-in-fork, fork-and-call or whatever you want to name it is in
fact not pure evil; mainly because shepherd could in its stead already
invoke any lambda you throw at it.  That being said, one should always
be aware that this child process runs with the full permissions of
shepherd, which you normally don't want to do for a service.

> [...]
> +(define* (fork-and-call thunk)
> +  "Call THUNK in a fork."
>    ;; Install the SIGCHLD handler if this is the first fork+exec-
> command call.
This docstring, as well as the procedure name only describe what is
done with thunk in the crudest terms.  What's more, I don't think it
makes too much sense to restrict ourselves to thunks if we already run
arbitrary code anyway.

In my opinion, it ought to be 
> +(define* (fork+apply proc . args)
> +  "Spawn a process that calls PROC with ARGS and return its PID."
>    (unless %sigchld-handler-installed?
>      (sigaction SIGCHLD handle-SIGCHLD SA_NOCLDSTOP)
> @@ -916,17 +906,34 @@ its PID."
>              ;; process.
>              (unblock-signals %precious-signals)
>  
> -            (exec-command command
> -                          #:user user
> -                          #:group group
> -                          #:supplementary-groups supplementary-
> groups
> -                          #:log-file log-file
> -                          #:directory directory
> -                          #:file-creation-mask file-creation-mask
> -                          #:create-session? create-session?
> -                          #:environment-variables environment-
> variables))
> +            (apply proc args))
>            pid))))
WDYT?
 
> +(define* (fork+exec-command command
> +                            #:key
> +                            (user #f)
> +                            (group #f)
> +                            (supplementary-groups '())
> +                            (log-file #f)
> +                            (directory (default-service-directory))
> +                            (file-creation-mask #f)
> +                            (create-session? #t)
> +                            (environment-variables
> +                             (default-environment-variables)))
> +  "Spawn a process that executed COMMAND as per 'exec-command', and
> return
> +its PID."
This is just copypasta from a previous mistake, but
s/executed/executes/.

Cheers





reply via email to

[Prev in Thread] Current Thread [Next in Thread]