0001-set-viriable-_drv-not-local.patch 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. From 6e0da103effe64832eea52fad5c44a328f7141b7 Mon Sep 17 00:00:00 2001
  2. From: Hongxu Jia <hongxu.jia@windriver.com>
  3. Date: Thu, 20 Jun 2019 17:31:11 +0800
  4. Subject: [PATCH] set viriable _drv not local
  5. If shebang is set to /bin/sh and /bin/sh is a symlink to /bin/bash,
  6. bash turn on posix mode.
  7. Since bash is upgraded to 5.0, it follows 'IEEE 1003.2 POSIX Shell
  8. Standard', to implement 'functions do not have local traps or options,
  9. and it is not possible to define local variables'
  10. For more detail, see variables.c:push_posix_temp_var in the following commit
  11. http://git.savannah.gnu.org/cgit/bash.git/commit/?id=d233b485e83c3a784b803fb894280773f16f2deb
  12. The IEEE 1003.2 POSIX Shell Standard:
  13. https://www.cs.ait.ac.th/~on/O/oreilly/unix/ksh/appa_02.htm
  14. While /bin/sh points to bash 5.0, it caused the following issue:
  15. $ cat <<ENDOF>case.sh
  16. fsck_drv_com(){
  17. echo "issuing \$_drv"
  18. }
  19. fsck_able() {
  20. _drv="_drv=e2fsck fsck_drv_com"
  21. }
  22. fsck_single() {
  23. local _drv
  24. fsck_able
  25. eval "\$_drv"
  26. }
  27. fsck_single
  28. ENDOF
  29. $ chmod a+x case.sh
  30. Unexpected:
  31. $ ./cash.sh
  32. issuing _drv=e2fsck fsck_drv_com
  33. Set viriable _drv not local, get expected result:
  34. $ ./case.sh
  35. issuing e2fsck
  36. Upstream-Status: Submitted [https://github.com/dracutdevs/dracut/pull/587]
  37. Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
  38. ---
  39. modules.d/99fs-lib/fs-lib.sh | 2 +-
  40. 1 file changed, 1 insertion(+), 1 deletion(-)
  41. diff --git a/modules.d/99fs-lib/fs-lib.sh b/modules.d/99fs-lib/fs-lib.sh
  42. index d39ca1b..60877ee 100755
  43. --- a/modules.d/99fs-lib/fs-lib.sh
  44. +++ b/modules.d/99fs-lib/fs-lib.sh
  45. @@ -142,7 +142,7 @@ fsck_single() {
  46. local _fs="${2:-auto}"
  47. local _fsopts="$3"
  48. local _fop="$4"
  49. - local _drv
  50. + _drv=""
  51. [ $# -lt 2 ] && return 255
  52. # if UUID= marks more than one device, take only the first one
  53. --
  54. 2.7.4