diff --git a/modules/shepherd/service.scm b/modules/shepherd/service.scm index 53437b6..bef8f42 100644 --- a/modules/shepherd/service.scm +++ b/modules/shepherd/service.scm @@ -715,21 +715,28 @@ 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 (retry) + (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 () - (string->number - (string-trim-both - (call-with-input-file file get-string-all)))) + (define str + (call-with-input-file file get-string-all)) + + (local-output (l10n "read-pid-file ~s -> ~s") + file str) + (or (string->number (string-trim-both str)) + (retry))) (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))) + (retry) (apply throw args))))))) (define* (exec-command command