guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 02/02: shepherd: Check for client EOF.


From: Ludovic Courtès
Subject: [shepherd] 02/02: shepherd: Check for client EOF.
Date: Sat, 23 Jan 2016 11:12:09 +0000

civodul pushed a commit to branch master
in repository shepherd.

commit ce52d0c321b45d123a6ae8fa77fc2b4b696073b5
Author: Ludovic Courtès <address@hidden>
Date:   Sat Jan 23 12:09:54 2016 +0100

    shepherd: Check for client EOF.
    
    * modules/shepherd/comm.scm (read-command): Check for 'eof-object?' and
    return it as is when it occurs.
    * modules/shepherd.scm (process-connection): Likewise.
    * tests/misbehaved-client.sh: Add test.
---
 modules/shepherd.scm       |    7 ++++++-
 modules/shepherd/comm.scm  |    6 ++++--
 tests/misbehaved-client.sh |    8 ++++++++
 3 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 3650e0e..e6a7a55 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -212,7 +212,12 @@
   "Process client connection SOCK, reading and processing commands."
   (catch 'system-error
     (lambda ()
-      (process-command (read-command sock) sock)
+      (match (read-command sock)
+        ((? shepherd-command? command)
+         (process-command command sock))
+        ((? eof-object?)
+         #f))
+
       ;; Currently we assume one command per connection.
       (false-if-exception (close sock)))
     (lambda args
diff --git a/modules/shepherd/comm.scm b/modules/shepherd/comm.scm
index f6f53c2..957e5b1 100644
--- a/modules/shepherd/comm.scm
+++ b/modules/shepherd/comm.scm
@@ -88,7 +88,7 @@ return the socket."
       sock)))
 
 (define (read-command port)
-  "Receive a command from PORT."
+  "Receive a command from PORT; return the command the EOF object."
   (match (read port)
     (('shepherd-command ('version 0 _ ...)
                         ('action action)
@@ -97,7 +97,9 @@ return the socket."
                         ('directory directory))
      (shepherd-command action service
                        #:arguments args
-                       #:directory directory))))
+                       #:directory directory))
+    ((? eof-object? eof)
+     eof)))
 
 (define (write-command command port)
   "Write COMMAND to PORT."
diff --git a/tests/misbehaved-client.sh b/tests/misbehaved-client.sh
index bbf6b03..cb06677 100644
--- a/tests/misbehaved-client.sh
+++ b/tests/misbehaved-client.sh
@@ -40,6 +40,14 @@ dmd_pid="`cat $pid`"
 "$GUILE" -c "
 (use-modules (shepherd comm))
 
+;; Close without even talking.
+(close-port (open-connection \"$socket\"))"
+
+$herd status                   # still here?
+
+"$GUILE" -c "
+(use-modules (shepherd comm))
+
 (let ((sock (open-connection \"$socket\")))
   (setvbuf sock _IOFBF 5000)
   (write-command (shepherd-command 'status 'dmd) sock)



reply via email to

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