unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: attila.lendvai@gmail.com
To: guix-devel@gnu.org
Cc: Attila Lendvai <attila@lendvai.name>
Subject: [PATCH shepherd] service: Factor out SEND-TO-PROCESS-MONITOR.
Date: Sun, 30 Jun 2024 18:13:03 +0200	[thread overview]
Message-ID: <20240630161303.22507-6-attila@lendvai.name> (raw)
In-Reply-To: <20240630161303.22507-2-attila@lendvai.name>

From: Attila Lendvai <attila@lendvai.name>

Assert that (CURRENT-PROCESS-MONITOR) is valid.

* modules/shepherd/service.scm (send-to-process-monitor): New function.
(handle-SIGCHLD), (process-monitor), (monitor-service-process),
(terminate-process): Use it.
---
 modules/shepherd/service.scm | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index d9dc0d5..e1c602c 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -2351,8 +2351,7 @@ otherwise by updating its state."
        #t)
       ((pid . status)
        ;; Let the process monitor handle it.
-       (put-message (current-process-monitor)
-                    `(handle-process-termination ,pid ,status))
+       (send-to-process-monitor `(handle-process-termination ,pid ,status))
 
        ;; As noted in libc's manual (info "(libc) Process Completion"),
        ;; loop so we don't miss any terminated child process.
@@ -2488,10 +2487,13 @@ which its completion status will be sent."
     (values (unboxed-errors (get-message reply))
             reply)))
 
+(define (send-to-process-monitor message)
+  (assert (current-process-monitor))
+  (put-message (current-process-monitor) message))
+
 (define (spawn-via-monitor arguments)
   (let ((reply (make-channel)))
-    (put-message (current-process-monitor)
-                 `(spawn ,arguments ,(current-service) ,reply))
+    (send-to-process-monitor `(spawn ,arguments ,(current-service) ,reply))
     (unboxed-errors (get-message reply))
     (get-message reply)))
 
@@ -2539,8 +2541,7 @@ while waiting for @var{program} to terminate."
   "Monitor process @var{pid} and notify @var{service} when it terminates."
   (assert (current-process-monitor))
   (let ((reply (make-channel)))
-    (put-message (current-process-monitor)
-                 `(await ,pid ,reply))
+    (send-to-process-monitor `(await ,pid ,reply))
     (spawn-fiber
      (lambda ()
        (let ((status (get-message reply)))
@@ -2583,7 +2584,7 @@ group; wait for @var{pid} to terminate and return its exit status.  If
 @var{pid} is still running @var{grace-period} seconds after @var{signal} has
 been sent, send it @code{SIGKILL}."
   (let ((reply (make-channel)))
-    (put-message (current-process-monitor) `(await ,(abs pid) ,reply))
+    (send-to-process-monitor `(await ,(abs pid) ,reply))
     (catch-system-error (kill pid signal))
 
     (match (get-message* reply grace-period #f)
@@ -2904,4 +2905,3 @@ we want to receive these signals."
       "This does not work for the 'root' service."
       (lambda (running)
 	(local-output (l10n "You must be kidding.")))))))
-
-- 
2.45.2



  parent reply	other threads:[~2024-06-30 17:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-30 16:12 [PATCH shepherd] service: Add custom printer for <service> attila.lendvai
2024-06-30 16:13 ` [PATCH shepherd] service: Rename to QUERY-SERVICE-CONTROLLER and use CUT attila.lendvai
2024-06-30 16:13 ` attila.lendvai [this message]
2024-06-30 16:13 ` [PATCH shepherd] service: Factor out SEND-TO-REGISTRY attila.lendvai
2024-06-30 16:13 ` [PATCH shepherd] service: Factor out SEND-TO-SERVICE-CONTROLLER attila.lendvai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240630161303.22507-6-attila@lendvai.name \
    --to=attila.lendvai@gmail.com \
    --cc=attila@lendvai.name \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).