guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 04/06: service: Add ‘start-command’.


From: Ludovic Courtès
Subject: [shepherd] 04/06: service: Add ‘start-command’.
Date: Wed, 20 Mar 2024 18:10:42 -0400 (EDT)

civodul pushed a commit to branch wip-timers
in repository shepherd.

commit a801c2e087598985242108118cbb8109e7206c36
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Mon Mar 18 22:27:14 2024 +0100

    service: Add ‘start-command’.
    
    This allows for race-free fork + waitpid, similar to
    ‘spawn-via-monitor’, but split-phase.
    
    * modules/shepherd/service.scm (start-command): New procedure.
---
 modules/shepherd/service.scm | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index b02587b..7ef2ff0 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -94,6 +94,7 @@
             respawn-service
             handle-SIGCHLD
             with-process-monitor
+            start-command
             spawn-command
             spawn-shell-command
             %precious-signals
@@ -2716,6 +2717,17 @@ context.  The process monitoring fiber is responsible 
for handling
 @code{SIGCHLD} and generally dealing with process creation and termination."
   (call-with-process-monitor (lambda () exp ...)))
 
+(define (start-command command . arguments)
+  "Start a process executing @var{command}, as per @code{fork+exec-command}, 
but
+immediately monitor its PID.  Return two values: its PID and a channel on
+which its completion status will be sent."
+  (let ((reply (make-channel)))
+    (put-message (current-process-monitor)
+                 `(spawn ,(cons command arguments) ,(current-service)
+                         ,reply))
+    (values (unboxed-errors (get-message reply))
+            reply)))
+
 (define (spawn-via-monitor arguments)
   (let ((reply (make-channel)))
     (put-message (current-process-monitor)



reply via email to

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