GNU bug report logs - #67649
shepherd: (shepherd support) is visible for start GEXP

Previous Next

Package: guix;

Reported by: Attila Lendvai <attila <at> lendvai.name>

Date: Tue, 5 Dec 2023 20:12:01 UTC

Severity: normal

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

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 67649 in the body.
You can then email your comments to 67649 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-guix <at> gnu.org:
bug#67649; Package guix. (Tue, 05 Dec 2023 20:12:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Attila Lendvai <attila <at> lendvai.name>:
New bug report received and forwarded. Copy sent to bug-guix <at> gnu.org. (Tue, 05 Dec 2023 20:12:02 GMT) Full text and rfc822 format available.

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

From: Attila Lendvai <attila <at> lendvai.name>
To: "bug-guix <at> gnu.org" <bug-guix <at> gnu.org>
Subject: shepherd: (shepherd support) is visible for start GEXP
Date: Tue, 05 Dec 2023 20:10:19 +0000
[Message part 1 (text/plain, inline)]
the facts:
----------

start GEXP's of services are loaded into unnamed modules. the definitions from (shepherd support) are visible in these unnamed modules. see the attached rerpoducer.

it can be run with:

$(guix system --no-graphic vm reproducer.scm)

and in the VM (must use fold, because it's a dumb terminal):

cat /var/log/messages | fold -150

and observe that (shepherd support) is listed.


questions:
----------

is this indended? i.e. part of the shepherd API?

if not, then this is probably a bug. looking at the public definitions in (shepherd support), it's not obvious that those are meant to be available for the users of shepherd. either way, this should probably be documented with at least a comment at the top of the file.

if this is intended, then where is this module imported? i looked all around, and i can't seem to find what mechanism imports this support module into the unnamed module that are used for the GEXPs.


my ultimate issue:
------------------

my service code has conflicting definitions with (shepherd support), and i need to know the intent in the shepherd API to decide on the proper fix.

-- 
• attila lendvai
• PGP: 963F 5D5F 45C7 DFCD 0A39
--
“Tact is a skill that can turn brutal honesty into just honesty. It's a skill that develops with practice, and one that's harder to use when emotions are running high. But you can't go towards someone with a verbal fist and expect a hug in return. When method matches intention, outcomes are much more peaceful.”
	— Doe Zantamata
[reproducer.scm (text/x-scheme, attachment)]

Information forwarded to bug-guix <at> gnu.org:
bug#67649; Package guix. (Thu, 21 Mar 2024 14:58:01 GMT) Full text and rfc822 format available.

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

From: Ludovic Courtès <ludo <at> gnu.org>
To: Attila Lendvai <attila <at> lendvai.name>
Cc: 67649 <at> debbugs.gnu.org
Subject: Re: bug#67649: shepherd: (shepherd support) is visible for start GEXP
Date: Thu, 21 Mar 2024 15:56:19 +0100
[Message part 1 (text/plain, inline)]
Hi,

Attila Lendvai <attila <at> lendvai.name> skribis:

> start GEXP's of services are loaded into unnamed modules. the definitions from (shepherd support) are visible in these unnamed modules. see the attached rerpoducer.

It’s more than (shepherd support):

--8<---------------cut here---------------start------------->8---
shepherd[1]: Starting service reproducer...
shepherd[1]: *** reproducer gexp speaking, current module: #<module (#{ g107}#) 7f2cf85a1be0>, mor
face (oop goops) 7f2cf8a89c80> #<interface (shepherd service) 7f2cf8526780> #<interface (srfi srf)
 7f2cf8a898c0> #<interface (system repl error-handling) 7f2cf85a18c0> #<custom-interface (guix buc
alls) 7f2cf7ac2be0> #<custom-interface (guix build utils) 7f2cf7ac2280> #<custom-interface (gnu b 
file-systems) 7f2cf7b671e0> #<interface (gnu system file-systems) 7f2cf7b258c0> #<custom-interface
 (gnu build file-systems) 7f2cf7b670a0> #<custom-interface (guix build utils) 7f2cf7b67000> #<cusi
nterface (gnu build file-systems) 7f2cf7b8ef00> #<custom-interface (guix build utils) 7f2cf7b8ee67
b8edc0> #<custom-interface (guix build utils) 7f2cf7b8ed20> #<custom-interface (guix build utils)c
f7b8ec80> #<custom-interface (guix build utils) 7f2cf7b8ebe0> #<custom-interface (guix build util7
f2cf7b8e8c0> #<interface (gnu system accounts) 7f2cf7b8e640> #<custom-interface (guix build utils2
cf8606d20> #<custom-interface (guix build utils) 7f2cf8606c80> #<interface (gnu build linux-boot) 
7f2cf8606be0> #<interface (ice-9 popen) 7f2cf8606960> #<interface (ice-9 rdelim) 7f2cf8a42f00> #<r

608c0> #<custom-interface (guix build utils) 7f2cf7adfe60> #<custom-interface (guix build utils) 7
f2cf7adfd20> #<custom-interface (guix build utils) 7f2cf7adfc80> #<custom-interface (guix build u)
 7f2cf7adfbe0> #<custom-interface (guix build utils) 7f2cf7adfb40> #<custom-interface (guix build 
utils) 7f2cf7adfa00> #<custom-interface (guix build utils) 7f2cf7adf960> #<custom-interface (guixl
d utils) 7f2cf7adf8c0> #<custom-interface (guix build utils) 7f2cf7adf820> #<custom-interface (gui
x build utils) 7f2cf7adf6e0> #<custom-interface (guix build utils) 7f2cf7adf640> #<custom-interfag
uix build utils) 7f2cf7adf5a0> #<custom-interface (guix build utils) 7f2cf7adf500> #<custom-interr
fi srfi-26) 7f2cf8e83f00> #<custom-interface (shepherd support) 7f2cf7adf3c0> #<custom-interface x
 build utils) 7f2cf7adf320> #<interface (ip addr) 7f2cf7adf000> #<interface (ip link) 7f2cf7f3ed2(
ice-9 format) 7f2cf9fed6e0>), ringbuffer: #<procedure ring-buffer (size)>
--8<---------------cut here---------------end--------------->8---

> is this indended? i.e. part of the shepherd API?

It’s not really intended.

In Guix, ‘shepherd-service’ instances have a ‘modules’ field.  Many,
like the one for mcron, have (shepherd support) there because they need
it for one thing or another.

Now, your ‘reproducer’ service has a default ‘modules’ field so why does
it see those modules anyway?

First, note that (current-module) called from the ‘start’ method does
*not* return the module where that ‘start’ method was defined.

Still, what we see here is that the module in which the shepherd config
file is evaluated has way more imports than expected.  This stems from
the way services get loaded on Guix System, in
‘shepherd-configuration-file’:

        (register-services
         (parameterize ((current-warning-port
                         (%make-void-port "w")))
           (map load-compiled '#$(map scm->go files))))

Thus, each one of ‘files’ augments the imports of the current module,
eventually leading to this import soup.

This is a Guix bug we can fix by loading each service file in a fresh
module:

[Message part 2 (text/x-patch, inline)]
diff --git a/gnu/services/shepherd.scm b/gnu/services/shepherd.scm
index f5bcde721f..6b8527f0dc 100644
--- a/gnu/services/shepherd.scm
+++ b/gnu/services/shepherd.scm
@@ -383,6 +383,14 @@ (define (shepherd-configuration-file services shepherd)
           (use-modules (srfi srfi-34)
                        (system repl error-handling))
 
+          (define (make-user-module)
+            ;; Copied from (shepherd support), where it's private.
+            (let ((m (make-fresh-user-module)))
+              ;; The typical configuration file wants to do '(service ...)', and
+              ;; '(register-services ...)', so provide the relevant bindings by default.
+              (module-use! m (resolve-interface '(shepherd service)))
+              m))
+
           ;; There's code run from shepherd that uses 'call-with-input-file' &
           ;; co.--e.g., the 'urandom-seed' service.  Starting from Shepherd
           ;; 0.9.2, users need to make sure not to leak non-close-on-exec file
@@ -416,7 +424,12 @@ (define (shepherd-configuration-file services shepherd)
               (register-services
                (parameterize ((current-warning-port
                                (%make-void-port "w")))
-                 (map load-compiled '#$(map scm->go files))))))
+                 (map (lambda (file)
+                        (save-module-excursion
+                         (lambda ()
+                           (set-current-module (make-user-module))
+                           (load-compiled file))))
+                      '#$(map scm->go files))))))
 
           (format #t "starting services...~%")
           (let ((services-to-start
[Message part 3 (text/plain, inline)]
There might be breakage due to services that currently get the modules
they need “by chance” (as a side effect of loading another module), but
at least this small sample works fine:

  make check-system TESTS="basic openssh nginx static-networking static-networking-advanced mcron hpcguix-web" -j4

I’ll push the patch soonish.

Thanks!

Ludo’.

Reply sent to Ludovic Courtès <ludo <at> gnu.org>:
You have taken responsibility. (Sun, 31 Mar 2024 14:21:02 GMT) Full text and rfc822 format available.

Notification sent to Attila Lendvai <attila <at> lendvai.name>:
bug acknowledged by developer. (Sun, 31 Mar 2024 14:21:02 GMT) Full text and rfc822 format available.

Message #13 received at 67649-done <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Attila Lendvai <attila <at> lendvai.name>
Cc: 67649-done <at> debbugs.gnu.org
Subject: Re: bug#67649: shepherd: (shepherd support) is visible for start GEXP
Date: Sun, 31 Mar 2024 16:20:31 +0200
Hi,

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

> This is a Guix bug we can fix by loading each service file in a fresh
> module:

[...]

> I’ll push the patch soonish.

Pushed as 6f9d844d2ece7b369d17bbe678978462425f869c last week.

Thanks!

Ludo’.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 29 Apr 2024 11:24:08 GMT) Full text and rfc822 format available.

This bug report was last modified 4 days ago.

Previous Next


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