[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 01/01: herd: Exit with non-zero when a custom action returns
From: |
Ludovic Courtès |
Subject: |
[shepherd] 01/01: herd: Exit with non-zero when a custom action returns false. |
Date: |
Tue, 13 Nov 2018 05:12:17 -0500 (EST) |
civodul pushed a commit to branch master
in repository shepherd.
commit 9e5715741e511ad55d2b6046688970d5e4ea95d6
Author: Ludovic Courtès <address@hidden>
Date: Tue Nov 13 11:10:59 2018 +0100
herd: Exit with non-zero when a custom action returns false.
* modules/shepherd/scripts/herd.scm (run-command): Call (exit 1) unless
all the values of RESULT are true.
* tests/basic.sh: Test it.
---
modules/shepherd/scripts/herd.scm | 6 ++++--
tests/basic.sh | 6 +++++-
2 files changed, 9 insertions(+), 3 deletions(-)
diff --git a/modules/shepherd/scripts/herd.scm
b/modules/shepherd/scripts/herd.scm
index 36219b8..3264a21 100644
--- a/modules/shepherd/scripts/herd.scm
+++ b/modules/shepherd/scripts/herd.scm
@@ -150,8 +150,10 @@ the daemon via SOCKET-FILE."
service)
(exit 1)))
(_
- ;; For other commands, we don't do any interpretation.
- #t)))
+ ;; For other commands, exit successfully if and only if all the
+ ;; values of RESULT are true.
+ (unless (every ->bool result)
+ (exit 1)))))
(('reply ('version 0 _ ...) ;an error
('result _) ('error error)
('messages messages))
diff --git a/tests/basic.sh b/tests/basic.sh
index cd4ade9..79caa32 100644
--- a/tests/basic.sh
+++ b/tests/basic.sh
@@ -57,7 +57,8 @@ cat > "$conf"<<EOF
#:actions (make-actions (hi "Say hi."
(lambda _
(display "start\n\nend\n")
- #t)))
+ #t))
+ (fail "Fail." (const #f)))
#:respawn? #f)
(make <service>
#:provides '(broken)
@@ -111,6 +112,9 @@ $herd hi test-2 | grep '^start$'
$herd hi test-2 | grep '^end$'
test `$herd hi test-2 | wc -l` -eq 3
+# An action that returns false must lead to a non-zero exit code.
+if $herd fail test-2; then false; else true; fi
+
# This used to crash shepherd: <http://bugs.gnu.org/24684>.
if $herd enable test-2 with extra arguments
then false; else true; fi