[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/01: services: 'read-pid-file' always exits its busy loop.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 01/01: services: 'read-pid-file' always exits its busy loop. |
Date: |
Mon, 6 May 2019 05:46:27 -0400 (EDT) |
civodul pushed a commit to branch master
in repository shepherd.
commit 83a83697c870a6ccb195662d7ad54e67f14f9443
Author: Ludovic Courtès <address@hidden>
Date: Mon May 6 11:45:07 2019 +0200
services: 'read-pid-file' always exits its busy loop.
* modules/shepherd/service.scm (read-pid-file): Factorize retrial in
'try-again'. This avoids the direct and unconditional call to 'loop'
introduced in 72631752149d000c8c98ae0cc66e0b0c2eda94ef.
---
modules/shepherd/service.scm | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm
index 3aea7b8..b937609 100644
--- a/modules/shepherd/service.scm
+++ b/modules/shepherd/service.scm
@@ -714,7 +714,17 @@ set when starting a service."
number. Return #f if FILE was not created or does not contain a number;
otherwise return the number that was read (a PID)."
(define start (current-time))
+
(let loop ()
+ (define (try-again)
+ (and (< (current-time) (+ start max-delay))
+ (begin
+ ;; FILE does not exist yet, so wait and try again.
+ ;; XXX: Ideally we would yield to the main event loop
+ ;; and/or use inotify.
+ (sleep 1)
+ (loop))))
+
(catch 'system-error
(lambda ()
(match (string->number
@@ -723,7 +733,7 @@ otherwise return the number that was read (a PID)."
(#f
;; If we didn't get an integer, it may be because the daemon didn't
;; create FILE atomically and isn't done writing to it. Try again.
- (loop))
+ (try-again))
((? integer? pid)
;; It's possible, though unlikely, that PID is not a valid PID, for
;; instance because writes to FILE did not complete. However, we
@@ -734,13 +744,7 @@ otherwise return the number that was read (a PID)."
(lambda args
(let ((errno (system-error-errno args)))
(if (= ENOENT errno)
- (and (< (current-time) (+ start max-delay))
- (begin
- ;; FILE does not exist yet, so wait and try again.
- ;; XXX: Ideally we would yield to the main event loop
- ;; and/or use inotify.
- (sleep 1)
- (loop)))
+ (try-again)
(apply throw args)))))))
(define* (exec-command command