no-home.sh 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # GNU Shepherd --- Make sure shepherd doesn't fail when $HOME is not writable.
  2. # Copyright © 2014, 2016 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. HOME=/nowhere
  20. export HOME
  21. if test -w "$HOME"
  22. then
  23. # We cannot run this test.
  24. exit 77
  25. fi
  26. socket="t-socket-$$"
  27. pid="t-pid-$$"
  28. herd="herd -s $socket"
  29. trap "rm -f $socket;
  30. test -f $pid && kill \`cat $pid\` || true; rm -f $pid" EXIT
  31. # Make sure 'shepherd' starts even though $HOME is not writable.
  32. shepherd -I -s "$socket" -c /dev/null -l /dev/null --pid="$pid" &
  33. shepherd_pid="$!"
  34. # Wait until it's ready, or until it terminates.
  35. while ! test -f "$pid" ; do kill -0 "$shepherd_pid" ; sleep 0.3 ; done
  36. kill -0 `cat "$pid"`
  37. $herd status root
  38. $herd stop root
  39. if kill `cat "$pid"`
  40. then
  41. exit 1
  42. fi