/init.d/binfmt-support

http://github.com/brinkman83/bashrc · Shell · 78 lines · 57 code · 10 blank · 11 comment · 15 complexity · 4ab2f0197ef37462353f8808e22b58ff MD5 · raw file

  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: binfmt-support
  4. # Required-Start: $local_fs $remote_fs
  5. # Required-Stop: $local_fs $remote_fs
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop:
  8. # Short-Description: Support for extra binary formats
  9. # Description: Enable support for extra binary formats using the Linux
  10. # kernel's binfmt_misc facility.
  11. ### END INIT INFO
  12. PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
  13. NAME=binfmt-support
  14. DESC="additional executable binary formats"
  15. if [ "$(uname)" != Linux ]; then
  16. exit 0
  17. fi
  18. which update-binfmts >/dev/null 2>&1 || exit 0
  19. . /lib/lsb/init-functions
  20. [ -r /etc/default/rcS ] && . /etc/default/rcS
  21. set -e
  22. CODE=0
  23. case "$1" in
  24. start)
  25. ADMINDIR=/var/lib/binfmts
  26. CACHEDIR=/var/cache/binfmts
  27. fmts="$(cd "$ADMINDIR"; ls)" || exit 0
  28. [ -z "$fmts" ] && exit 0
  29. log_daemon_msg "Enabling $DESC" "$NAME"
  30. PROCDIR=/proc/sys/fs/binfmt_misc
  31. if [ ! -e "$PROCDIR/register" ]; then
  32. if which modprobe >/dev/null 2>&1; then
  33. modprobe -q binfmt_misc || true
  34. fi
  35. mount -t binfmt_misc -o nodev,noexec,nosuid binfmt_misc "$PROCDIR"
  36. fi
  37. cachefail=0
  38. for fmt in $fmts; do
  39. [ -e "$PROCDIR/$fmt" ] && continue
  40. if [ ! -e "$CACHEDIR/$fmt" ] ||
  41. ! cat "$CACHEDIR/$fmt" > $PROCDIR/register; then
  42. cachefail=1
  43. fi
  44. CODE=$?
  45. done
  46. if [ "$cachefail" = 1 ]; then
  47. update-binfmts --enable || CODE=$?
  48. fi
  49. log_end_msg $CODE
  50. exit $CODE
  51. ;;
  52. stop)
  53. log_daemon_msg "Disabling $DESC" "$NAME"
  54. update-binfmts --disable || CODE=$?
  55. log_end_msg $CODE
  56. exit $CODE
  57. ;;
  58. restart|force-reload)
  59. $0 stop
  60. $0 start
  61. ;;
  62. *)
  63. N=/etc/init.d/$NAME
  64. echo "Usage: $N {start|stop|restart|force-reload}" >&2
  65. exit 1
  66. ;;
  67. esac
  68. exit 0