misbehaved-client.sh 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # GNU Shepherd --- Make sure shepherd tolerates misbehaved clients.
  2. # Copyright © 2016, 2018 Ludovic Courtès <ludo@gnu.org>
  3. #
  4. # This file is part of the GNU Shepherd.
  5. #
  6. # The GNU Shepherd is free software; you can redistribute it and/or modify it
  7. # under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 3 of the License, or (at
  9. # your option) any later version.
  10. #
  11. # The GNU Shepherd is distributed in the hope that it will be useful, but
  12. # WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with the GNU Shepherd. If not, see <http://www.gnu.org/licenses/>.
  18. shepherd --version
  19. herd --version
  20. socket="t-socket-$$"
  21. conf="t-conf-$$"
  22. log="t-log-$$"
  23. pid="t-pid-$$"
  24. herd="herd -s $socket"
  25. trap "rm -f $socket $conf $stamp $log;
  26. test -f $pid && kill \`cat $pid\` || true; rm -f $pid" EXIT
  27. rm -f "$pid"
  28. shepherd -I -s "$socket" -c /dev/null -l "$log" --pid="$pid" &
  29. # Wait till it's ready.
  30. while ! test -f "$pid" ; do sleep 0.3 ; done
  31. shepherd_pid="`cat $pid`"
  32. "$GUILE" -c "
  33. (use-modules (shepherd comm))
  34. ;; Close without even talking.
  35. (close-port (open-connection \"$socket\"))"
  36. $herd status # still here?
  37. "$GUILE" -c "
  38. (use-modules (shepherd comm))
  39. ;; Send an unbalanced sexp, then quit.
  40. (let ((sock (open-connection \"$socket\")))
  41. (display \"(ah ha!\" sock)
  42. (close-port sock))"
  43. $herd status # still here?
  44. "$GUILE" -c "
  45. (use-modules (shepherd comm))
  46. ;; Send an unrecognized sexp.
  47. (let ((sock (open-connection \"$socket\")))
  48. (display \"(hi there)\" sock))"
  49. $herd status # still here?
  50. "$GUILE" -c "
  51. (use-modules (shepherd comm) (shepherd support))
  52. (let ((sock (open-connection \"$socket\")))
  53. (setvbuf sock (buffering-mode block) 5000)
  54. (write-command (shepherd-command 'status 'root) sock)
  55. ;; Close prematurely, right after sending the command.
  56. (close-port sock))"
  57. $herd status
  58. cat "$log"