os-prober-factor-out-logger.patch 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. Index: os-prober/common.sh
  2. ===================================================================
  3. --- os-prober.orig/common.sh
  4. +++ os-prober/common.sh
  5. @@ -62,10 +62,14 @@ cache_progname() {
  6. esac
  7. }
  8. -log() {
  9. - cache_progname
  10. - logger -t "$progname" "$@"
  11. -}
  12. +# fd_logger: bind value now, possibly after assigning default.
  13. +eval '
  14. + log() {
  15. + cache_progname
  16. + echo "$progname: $@" 1>&'${fd_logger:=9}'
  17. + }
  18. +'
  19. +export fd_logger # so subshells inherit current value by default
  20. error() {
  21. log "error: $@"
  22. @@ -81,10 +85,14 @@ debug() {
  23. fi
  24. }
  25. -result () {
  26. - log "result:" "$@"
  27. - echo "$@"
  28. -}
  29. +# fd_result: bind value now, possibly after assigning default.
  30. +eval '
  31. + result() {
  32. + log "result:" "$@"
  33. + echo "$@" 1>&'${fd_result:=1}'
  34. + }
  35. +'
  36. +export fd_result # so subshells inherit current value by default
  37. # shim to make it easier to use os-prober outside d-i
  38. if ! type mapdevfs >/dev/null 2>&1; then
  39. Index: os-prober/linux-boot-prober
  40. ===================================================================
  41. --- os-prober.orig/linux-boot-prober
  42. +++ os-prober/linux-boot-prober
  43. @@ -1,4 +1,12 @@
  44. #!/bin/sh
  45. +
  46. +# dash shell does not have "{varname}>&1" feature that bash shell has
  47. +# for auto-assignment of new filedescriptors.
  48. +# It is cumbersome to write the 'eval' to use our own variables in redirections.
  49. +# Therefore use fixed numbers.
  50. +export fd_result=3 # file descriptor for external results
  51. +export fd_logger=9 # file descriptor for input to logger
  52. +
  53. . /usr/share/os-prober/common.sh
  54. set -e
  55. @@ -19,6 +27,7 @@ bootuuid=
  56. grep "^/dev/" /proc/mounts | parse_proc_mounts >"$OS_PROBER_TMP/mounted-map" || true
  57. +( (
  58. if [ -z "$1" ]; then
  59. ERR=y
  60. elif [ "$1" = btrfs -a -z "$2" ]; then
  61. @@ -186,3 +195,5 @@ else
  62. fi
  63. fi
  64. fi
  65. +) 9>&1 | logger 1>&- # fd_logger
  66. +) 3>&1 # fd_result
  67. Index: os-prober/os-prober
  68. ===================================================================
  69. --- os-prober.orig/os-prober
  70. +++ os-prober/os-prober
  71. @@ -1,7 +1,14 @@
  72. #!/bin/sh
  73. set -e
  74. -. /usr/share/os-prober/common.sh
  75. +# dash shell does not have "{varname}>&1" feature that bash shell has
  76. +# for auto-assignment of new filedescriptors.
  77. +# It is cumbersome to write the 'eval' to use our own variables in redirections.
  78. +# Therefore use fixed numbers.
  79. +export fd_result=3 # file descriptor for external results
  80. +export fd_logger=9 # file descriptor for input to logger
  81. +
  82. + . /usr/share/os-prober/common.sh
  83. newns "$@"
  84. require_tmpdir
  85. @@ -136,6 +143,7 @@ fi
  86. : >"$OS_PROBER_TMP/btrfs-vols"
  87. +( (
  88. for partition in $(partitions); do
  89. if ! mapped="$(mapdevfs "$partition")"; then
  90. log "Device '$partition' does not exist; skipping"
  91. @@ -200,3 +208,5 @@ for partition in $(partitions); do
  92. fi
  93. fi
  94. done
  95. +) 9>&1 | logger 1>&- # fd_logger
  96. +) 3>&1 # fd_result