[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[shepherd] 06/07: shepherd: Ignore SIGPIPE.
From: |
Ludovic Courtès |
Subject: |
[shepherd] 06/07: shepherd: Ignore SIGPIPE. |
Date: |
Fri, 22 Jan 2016 23:37:00 +0000 |
civodul pushed a commit to branch master
in repository shepherd.
commit 9f902c716537be551eadecd4c30118fc9ad12b60
Author: Ludovic Courtès <address@hidden>
Date: Sat Jan 23 00:18:44 2016 +0100
shepherd: Ignore SIGPIPE.
* modules/shepherd.scm (main): Call 'sigaction' to ignore SIGPIPE.
* tests/misbehaved-client.sh: New file.
* Makefile.am (TESTS): Add it.
---
Makefile.am | 1 +
modules/shepherd.scm | 5 ++++
tests/misbehaved-client.sh | 52 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 58 insertions(+), 0 deletions(-)
diff --git a/Makefile.am b/Makefile.am
index 7eb2a27..df97916 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -140,6 +140,7 @@ SUFFIXES = .go
TESTS = \
tests/basic.sh \
tests/respawn.sh \
+ tests/misbehaved-client.sh \
tests/no-home.sh \
tests/status-sexp.sh \
tests/sigint.sh
diff --git a/modules/shepherd.scm b/modules/shepherd.scm
index b033872..6c0aade 100644
--- a/modules/shepherd.scm
+++ b/modules/shepherd.scm
@@ -177,6 +177,10 @@
(lambda _
(stop dmd-service)))
+ ;; Ignore SIGPIPE so that we don't die if a client closes the connection
+ ;; prematurely.
+ (sigaction SIGPIPE SIG_IGN)
+
(if (not socket-file)
;; Get commands from the standard input port.
(process-textual-commands (current-input-port))
@@ -212,6 +216,7 @@
;; Currently we assume one command per connection.
(false-if-exception (close sock)))
(lambda args
+ ;; Maybe we got EPIPE while writing to SOCK, or something like that.
(false-if-exception (close sock)))))
(define %not-newline
diff --git a/tests/misbehaved-client.sh b/tests/misbehaved-client.sh
new file mode 100644
index 0000000..f69f65e
--- /dev/null
+++ b/tests/misbehaved-client.sh
@@ -0,0 +1,52 @@
+# GNU Shepherd --- Make sure shepherd tolerates misbehaved clients.
+# Copyright © 2016 Ludovic Courtès <address@hidden>
+#
+# This file is part of the GNU Shepherd.
+#
+# The GNU Shepherd is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or (at
+# your option) any later version.
+#
+# The GNU Shepherd is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
+
+shepherd --version
+herd --version
+
+socket="t-socket-$$"
+conf="t-conf-$$"
+log="t-log-$$"
+pid="t-pid-$$"
+
+herd="herd -s $socket"
+
+trap "rm -f $socket $conf $stamp $log $pid;
+ test -f $pid && kill \`cat $pid\` || true" EXIT
+
+rm -f "$pid"
+shepherd -I -s "$socket" -c /dev/null -l "$log" --pid="$pid" &
+
+# Wait till it's ready.
+while ! test -f "$pid" ; do sleep 0.3 ; done
+
+dmd_pid="`cat $pid`"
+
+"$GUILE" -c "
+(use-modules (shepherd comm))
+
+(let ((sock (open-connection \"$socket\")))
+ (setvbuf sock _IOFBF 5000)
+ (write-command (dmd-command 'status 'dmd) sock)
+
+ ;; Close prematurely, right after sending the command.
+ (close-port sock))"
+
+$herd status
+
+cat "$log"
- [shepherd] branch master updated (852341e -> 28ed7e1), Ludovic Courtès, 2016/01/22
- [shepherd] 01/07: herd: Report errors according to the GNU standards., Ludovic Courtès, 2016/01/22
- [shepherd] 03/07: support: Add 'display-line'., Ludovic Courtès, 2016/01/22
- [shepherd] 04/07: comm: Add 'report-command-error'., Ludovic Courtès, 2016/01/22
- [shepherd] 05/07: reboot, halt: Adjust to sexp replies., Ludovic Courtès, 2016/01/22
- [shepherd] 07/07: Rename 'dmd-output-port' to 'shepherd-output-port'., Ludovic Courtès, 2016/01/22
- [shepherd] 02/07: Move 'report-error' to (shepherd support)., Ludovic Courtès, 2016/01/22
- [shepherd] 06/07: shepherd: Ignore SIGPIPE.,
Ludovic Courtès <=