summaryrefslogtreecommitdiff
path: root/policy-rc.d
blob: 8972383c4ce2bef2cfebfc806aa51be31eba2391 (plain)
  1. #!/bin/sh
  2. $Id: policy-rc.d,v 1.4 2007-01-03 14:38:03 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. echo "A chroot environment has been detected, udev not started."
  32. return 0
  33. }
  34. quiet=""
  35. list=""
  36. while true ; do
  37. case "$1" in
  38. --quiet) quiet="1" ; shift ;;
  39. --list) list="1" ; shift ;;
  40. --) shift ; break ;;
  41. *) echo "Internal error!" ; exit 1 ;;
  42. esac
  43. done
  44. initscript="$1"
  45. actions="$2"
  46. runlevel="$3"
  47. if [ "$list" ]; then
  48. cat <<EOF
  49. The following policies are known to this policy daemon:
  50. default: All actions are allowed.
  51. chroot: If invoked from within a chroot environment,
  52. no actions are allowed, else all are allowed.
  53. This policy daemon care not about actions, so all standard actions
  54. (start, [force-]stop, restart, [force-]reload and status), and any
  55. additionally implemented ones, are supported.
  56. EOF
  57. exit 0
  58. fi
  59. if ! chrooted; then
  60. if ! [ "$quiet" ]; then
  61. echo >&2 "Chroot environment detected, suppressing sysV script."
  62. fi
  63. exit 101
  64. fi
  65. exit 0