guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 09/13: comm: Capture the client command protocol version.


From: Ludovic Courtès
Subject: [shepherd] 09/13: comm: Capture the client command protocol version.
Date: Sun, 16 Apr 2023 17:38:37 -0400 (EDT)

civodul pushed a commit to branch master
in repository shepherd.

commit 933df1f3248b41388a67f39dd291b11dfefb3e58
Author: Ludovic Courtès <ludo@gnu.org>
AuthorDate: Fri Apr 14 19:28:11 2023 +0200

    comm: Capture the client command protocol version.
    
    * modules/shepherd/comm.scm (<shepherd-command>)[version]: New field.
    (%protocol-version): New variable.
    (shepherd-command): Add #:version.
    (read-command): Pass #:version.
    (write-command): Honor 'version' field.
    * modules/shepherd.scm (process-command): Update <shepherd-command>
    match pattern.
---
 modules/shepherd.scm      |  2 +-
 modules/shepherd/comm.scm | 32 +++++++++++++++++++++++---------
 2 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 17a3d1e..5b7318f 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -507,7 +507,7 @@ while evaluating @var{command}."
   "Interpret COMMAND, a command sent by the user, represented as a
 <shepherd-command> object.  Send the reply to PORT."
   (match command
-    (($ <shepherd-command> the-action service-symbol (args ...)
+    (($ <shepherd-command> version the-action service-symbol (args ...)
                            directory)             ;ignored
 
      ;; We have to catch `quit' so that we can send the terminator
diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm
index c864aaa..d6f259d 100644
--- a/modules/shepherd/comm.scm
+++ b/modules/shepherd/comm.scm
@@ -29,6 +29,7 @@
             <shepherd-command>
             shepherd-command?
             shepherd-command
+            shepherd-command-version
             shepherd-command-directory
             shepherd-command-action
             shepherd-command-service
@@ -61,17 +62,24 @@
 
 ;; Command for shepherd.
 (define-record-type <shepherd-command>
-  (%shepherd-command action service args directory)
+  (%shepherd-command version action service args directory)
   shepherd-command?
+  (version   shepherd-command-version)            ; list of integers
   (action    shepherd-command-action)             ; symbol
   (service   shepherd-command-service)            ; symbol
   (args      shepherd-command-arguments)          ; list of strings
   (directory shepherd-command-directory))         ; directory name
 
+(define %protocol-version
+  ;; Current client protocol version.
+  '(0))
+
 (define* (shepherd-command action service
-                           #:key (arguments '()) (directory (getcwd)))
+                           #:key
+                           (version %protocol-version)
+                           (arguments '()) (directory (getcwd)))
   "Return a new command for ACTION on SERVICE."
-  (%shepherd-command action service arguments directory))
+  (%shepherd-command version action service arguments directory))
 
 (define* (open-connection #:optional (file default-socket-file))
   "Open a connection to the daemon, using the Unix-domain socket at FILE, and
@@ -110,14 +118,19 @@ wrong---premature end-of-file, invalid sexp, etc."
   (catch 'read-error
     (lambda ()
       (match (read port)
-        (('shepherd-command ('version 0 _ ...)
+        (('shepherd-command ('version version ...)
                             ('action action)
                             ('service service)
                             ('arguments (args ...))
                             ('directory directory))
-         (shepherd-command action service
-                           #:arguments args
-                           #:directory directory))
+         (match version
+           ((0 _ ...)
+            (shepherd-command action service
+                              #:version version
+                              #:arguments args
+                              #:directory directory))
+           (_
+            #f)))
         (_                                        ;EOF or unmatched sexp
          #f)))
     (lambda _
@@ -127,8 +140,9 @@ wrong---premature end-of-file, invalid sexp, etc."
 (define (write-command command port)
   "Write COMMAND to PORT."
   (match command
-    (($ <shepherd-command> action service (arguments ...) directory)
-     (write `(shepherd-command (version 0)        ; protocol version
+    (($ <shepherd-command> version
+        action service (arguments ...) directory)
+     (write `(shepherd-command (version ,@version) ;protocol version
                                (action ,action)
                                (service ,service)
                                (arguments ,arguments)



reply via email to

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