File: misbehaved-client.sh

package info (click to toggle)
shepherd 1.0.9-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,828 kB
  • sloc: lisp: 8,779; sh: 3,586; makefile: 290; ansic: 50
file content (111 lines) | stat: -rw-r--r-- 2,908 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# GNU Shepherd --- Make sure shepherd tolerates misbehaved clients.
# Copyright © 2016, 2018, 2022, 2025 Ludovic Courtès <ludo@gnu.org>
#
# 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 <https://www.gnu.org/licenses/>.

shepherd --version
herd --version

socket="t-socket-$$"
conf="t-conf-$$"
log="t-log-$$"
pid="t-pid-$$"
client="t-client-$$"

herd="herd -s $socket"

trap "cat $log || true; rm -f $socket $conf $stamp $log $client;
      test -f $pid && kill \`cat $pid\` || true; rm -f $pid" 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

shepherd_pid="`cat $pid`"

"$GUILE" -c "
(use-modules (shepherd comm))

;; Close without even talking.
(close-port (open-connection \"$socket\"))"

$herd status			# still here?

"$GUILE" -c "
(use-modules (shepherd comm))

;; Send an unbalanced sexp, then quit.
(let ((sock (open-connection \"$socket\")))
  (display \"(ah ha!\" sock)
  (close-port sock))"

$herd status			# still here?

"$GUILE" -c "
(use-modules (shepherd comm))

;; Send an unrecognized sexp.
(let ((sock (open-connection \"$socket\")))
  (display \"(hi there)\" sock))"

$herd status			# still here?

"$GUILE" -c "
(use-modules (shepherd comm) (shepherd support))

(let ((sock (open-connection \"$socket\")))
  (setvbuf sock 'block 5000)
  (write-command (shepherd-command 'status 'root) sock)

  ;; Close prematurely, right after sending the command.
  (close-port sock))"

$herd status

"$GUILE" -c "
(use-modules (shepherd comm) (shepherd support) (ice-9 match))

(let ((sock (open-connection \"$socket\")))
  (setvbuf sock 'none)
  (display \"(ah ha!\" sock)
  ;; Leave it hanging; shepherd must not block.
  (let ((sock (open-connection \"$socket\")))
    (write-command (shepherd-command 'status 'does-not-exist) sock)
    (match (read sock)
      (('reply _ ...) #t)
      (x
       (pk 'wrong x)
       (exit 1)))))"

$herd status

cat > "$client" <<EOF
;; -*- coding: utf-8 -*-
(use-modules (shepherd comm))

(let ((sock (open-connection "$socket")))
  (set-port-encoding! sock "ISO-8859-1")
  (set-port-conversion-strategy! sock 'error)
  (display "(Café, ça te dit ?)\n" sock)
  (close-port sock))
EOF

"$GUILE" --no-auto-compile "$client"
$herd status

cat "$log"