guix-commits
[Top][All Lists]
Advanced

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

[shepherd] 01/01: Revert "Remove EINTR-safe, and all references to it."


From: Carlo Zancanaro
Subject: [shepherd] 01/01: Revert "Remove EINTR-safe, and all references to it."
Date: Sun, 26 Aug 2018 09:30:51 -0400 (EDT)

czan pushed a commit to branch master
in repository shepherd.

commit 1e23e1b4dad8d4c0e2e6ff2e251b1d312337db5a
Author: Carlo Zancanaro <address@hidden>
Date:   Sun Aug 26 13:25:49 2018 +1000

    Revert "Remove EINTR-safe, and all references to it."
    
    This reverts commit 2756a929d96725d837738e396619072d50b366cc.
---
 modules/shepherd.scm         |  7 ++++++-
 modules/shepherd/service.scm | 35 ++++++++++++++++++++++-------------
 modules/shepherd/support.scm | 14 ++++++++++++++
 3 files changed, 42 insertions(+), 14 deletions(-)

diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index 1efe4ce..0e55088 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -241,7 +241,12 @@
           ;; Get commands from the standard input port.
           (process-textual-commands (current-input-port))
           ;; Process the data arriving at a socket.
-          (let ((sock   (open-server-socket socket-file)))
+          (let ((sock   (open-server-socket socket-file))
+
+                ;; With Guile <= 2.0.9, we can get a system-error exception for
+                ;; EINTR, which happens anytime we receive a signal, such as
+                ;; SIGCHLD.  Thus, wrap the 'accept' call.
+                (accept (EINTR-safe accept)))
 
             ;; Possibly write out our PID, which means we're ready to accept
             ;; connections.  XXX: What if we daemonized already?
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 006309c..24c9224 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -603,6 +603,13 @@ results."
                (apply action service the-action args))
              which-services))))
 
+;; EINTR-safe versions of 'system' and 'system*'.
+
+(define system*
+  (EINTR-safe (@ (guile) system*)))
+
+(define system
+  (EINTR-safe (@ (guile) system)))
 
 
 
@@ -987,19 +994,21 @@ returned in unspecified."
   (hashq-ref %services name '()))
 
 (define waitpid*
-  (lambda (what flags)
-    "Like 'waitpid', and return (0 . _) when there's no child left."
-    (catch 'system-error
-      (lambda ()
-        (waitpid what flags))
-      (lambda args
-        ;; Did we get ECHILD or something?  If we did, that's a problem,
-        ;; because this procedure is supposed to be called only upon
-        ;; SIGCHLD.
-        (let ((errno (system-error-errno args)))
-          (local-output "warning: 'waitpid' ~a failed unexpectedly: ~a"
-                        what (strerror errno))
-          '(0 . #f))))))
+  (let ((waitpid (EINTR-safe waitpid)))
+    (lambda (what flags)
+      "Like 'waitpid', but EINTR-safe, and return (0 . _) when there's no
+child left."
+      (catch 'system-error
+        (lambda ()
+          (waitpid what flags))
+        (lambda args
+          ;; Did we get ECHILD or something?  If we did, that's a problem,
+          ;; because this procedure is supposed to be called only upon
+          ;; SIGCHLD.
+          (let ((errno (system-error-errno args)))
+            (local-output "warning: 'waitpid' ~a failed unexpectedly: ~a"
+                          what (strerror errno))
+            '(0 . #f)))))))
 
 (define (handle-SIGCHLD signum)
   "Handle SIGCHLD, possibly by respawning the service that just died, or
diff --git a/modules/shepherd/support.scm b/modules/shepherd/support.scm
index 9f02719..380866e 100644
--- a/modules/shepherd/support.scm
+++ b/modules/shepherd/support.scm
@@ -30,6 +30,7 @@
 
             catch-system-error
             with-system-error-handling
+            EINTR-safe
             with-atomic-file-output
             mkdir-p
             with-directory-excursion
@@ -126,6 +127,19 @@ turned into user error messages."
    (lambda ()
      body ...)))
 
+(define (EINTR-safe proc)
+  "Wrap PROC so that if a 'system-error' exception with EINTR is raised (that
+was possible up to Guile 2.0.9 included) the call to PROC is restarted."
+  (lambda args
+    (let loop ()
+      (catch 'system-error
+        (lambda ()
+          (apply proc args))
+        (lambda args
+          (if (= EINTR (system-error-errno args))
+              (loop)
+              (apply throw args)))))))
+
 (define (with-atomic-file-output file proc)       ;copied from Guix
   "Call PROC with an output port for the file that is going to replace FILE.
 Upon success, FILE is atomically replaced by what has been written to the



reply via email to

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