built-sources-fork-bomb.sh 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #! /bin/sh
  2. # Copyright (C) 2012-2017 Free Software Foundation, Inc.
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. # Due to how the handling of $(BUILT_SOURCES) is implemented in Automake-NG,
  17. # a recursive make call in the recipe of any $(BUILT_SOURCES) (or of any of
  18. # its prerequisites) might cause an infinite recursion (complete with fork
  19. # bomb, yuck) if not handled correctly. Verify that this doesn't happen.
  20. # For more background, see:
  21. # <http://lists.gnu.org/archive/html/help-smalltalk/2012-08/msg00027.html>
  22. # <http://lists.gnu.org/archive/html/automake-patches/2012-08/msg00052.html>
  23. # Backported to improve coverage of mainline Automake.
  24. required=GNUmake
  25. . test-init.sh
  26. echo AC_OUTPUT >> configure.ac
  27. cat > Makefile.am << 'END'
  28. BUILT_SOURCES = foo
  29. .PHONY: build-foo
  30. build-foo:
  31. echo OK > foo
  32. foo:
  33. $(MAKE) build-foo
  34. # If the bug is still present, we want this test to fail, not to actually
  35. # go fork bomb and potentially crash the user machine. Take care of that.
  36. is_too_deep := $(shell test $(MAKELEVEL) -lt 10 && echo no)
  37. ## Extra indentation here required to avoid confusing Automake.
  38. ifeq ($(is_too_deep),no)
  39. # All is ok.
  40. else
  41. $(error ::OOPS:: Recursion too deep, $(MAKELEVEL) levels)
  42. endif
  43. END
  44. $ACLOCAL
  45. $AUTOMAKE -Wno-portability
  46. $AUTOCONF
  47. ./configure
  48. run_make -M -- -n foo
  49. test ! -f foo
  50. # Guard against possible infinite recursion.
  51. $FGREP '::OOPS::' output && exit 1
  52. run_make -M -- foo
  53. # Guard against possible infinite recursion.
  54. $FGREP '::OOPS::' output && exit 1
  55. :