summaryrefslogtreecommitdiff
path: root/policy-rc.d
blob: 9e0b9e7f310cade65867b8f15c839d4fb393a54a (plain)
  1. #!/bin/sh
  2. $Id: policy-rc.d,v 1.5 2007-01-16 09:59:43 jonas Exp $
  3. #
  4. # Copyright © 2006 Jonas Smedegaard <dr@jones.dk>
  5. # Description: Suppress system V scripts if invoked within a chroot.
  6. #
  7. # This program is free software; you can redistribute it and/or
  8. # modify it under the terms of the GNU General Public License as
  9. # published by the Free Software Foundation; either version 2, or (at
  10. # your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. # General Public License for more details.
  16. # Policy-rc.d is mentioned in manpage invoke-rc.d(8) and documented at
  17. # http://people.debian.org/~hmh/invokerc.d-policyrc.d-specification.txt
  18. set -e
  19. PRG=`basename $0`
  20. TEMP=`getopt -s sh --long list,quiet -n "$PRG" -- "$@"`
  21. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  22. eval set -- "$TEMP"
  23. # Stolen from udev postinst
  24. chrooted() {
  25. if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ];
  26. then
  27. # the devicenumber/inode pair of / is the same as that of /sbin/init's
  28. # root, so we're *not* in a chroot and hence return false.
  29. return 1
  30. fi
  31. return 0
  32. }
  33. quiet=""
  34. list=""
  35. while true ; do
  36. case "$1" in
  37. --quiet) quiet="1" ; shift ;;
  38. --list) list="1" ; shift ;;
  39. --) shift ; break ;;
  40. *) echo "Internal error!" ; exit 1 ;;
  41. esac
  42. done
  43. initscript="$1"
  44. actions="$2"
  45. runlevel="$3"
  46. if [ "$list" ]; then
  47. cat <<EOF
  48. The following policies are known to this policy daemon:
  49. default: All actions are allowed.
  50. chroot: If invoked from within a chroot environment,
  51. no actions are allowed, else all are allowed.
  52. This policy daemon care not about actions, so all standard actions
  53. (start, [force-]stop, restart, [force-]reload and status), and any
  54. additionally implemented ones, are supported.
  55. EOF
  56. exit 0
  57. fi
  58. if chrooted; then
  59. if ! [ "$quiet" ]; then
  60. echo >&2 "Chroot environment detected, suppressing sysV script."
  61. fi
  62. exit 101
  63. fi
  64. exit 0