scripts/check-local-export: avoid 'wait $!' for process substitution
Subsystems (3)
PATCH v2 1/1 scripts/check-local-export: avoid 'wait $!' for process substitution
Bash>=4.4 supports 'wait $!' to check the exit status of a process substitution, but some people using older bash versions reported an error like this:
./scripts/check-local-export: line 54: wait: pid 17328 is not a child of this shell
I used the process substitution because a pipeline executes each command in a subshell; variables modified within the while-loop in the subshell context would be lost after the subshell terminates.
Fortunately, Bash>=4.2 supports the 'lastpipe' option, which runs the last element of a pipeline in the current shell process.
Also, set 'pipefail' to catch errors from ${NM}.
Bash 4.2, released in 2011, is 5 years older than Bash 4.4.
---
Changes in v2:
- Add bash to Documentation/process/changes.rst
Documentation/process/changes.rst | 12 +++++++++++ scripts/check-local-export | 35 ++++++++++++++++++------------- 2 files changed, 32 insertions(+), 15 deletions(-)
Documentation/process/changes.rst +12 -0
@@ -32,6 +32,7 @@ you probably needn't concern yourself with pcmciautils. GNU C 5.1 gcc --version Clang/LLVM (optional) 11.0.0 clang --version GNU make 3.81 make --version +bash 4.2 bash --version binutils 2.23 ld -v flex 2.5.35 flex --version bison 2.0 bison --version
@@ -84,6 +85,12 @@ Make You will need GNU make 3.81 or later to build the kernel. +Bash +---- + +Some bash scripts are used for the kernel build. +Bash 4.2 or newer is needed. + Binutils --------
@@ -362,6 +369,11 @@ Make - <ftp://ftp.gnu.org/gnu/make/> +Bash +---- + +- <ftp://ftp.gnu.org/gnu/bash/> + Binutils --------
scripts/check-local-export +20 -15
@@ -8,11 +8,30 @@ set -e +# catch errors from ${NM} +set -o pipefail + +# Run the last element of a pipeline in the current shell. +# Without this, the while-loop would be executed in a subshell, and +# the changes made to 'symbol_types' and 'export_symbols' would be lost. +shopt -s lastpipe + declare -A symbol_types declare -a export_symbols exit_code=0 +# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) shows +# 'no symbols' diagnostic (but exits with 0). It is harmless and hidden by +# '2>/dev/null'. However, it suppresses real error messages as well. Add a +# hand-crafted error message here. +# +# Use --quiet instead of 2>/dev/null when we upgrade the minimum version of +# binutils to 2.37, llvm to 13.0.0. +# +# Then, the following line will be really simple: +# ${NM} --quiet ${1} | +{ ${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } } | while read value type name do # Skip the line if the number of fields is less than 3.
@@ -37,21 +56,7 @@ do if [[ ${name} == __ksymtab_* ]]; then export_symbols+=(${name#__ksymtab_}) fi - - # If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) - # shows 'no symbols' diagnostic (but exits with 0). It is harmless and - # hidden by '2>/dev/null'. However, it suppresses real error messages - # as well. Add a hand-crafted error message here. - # - # Use --quiet instead of 2>/dev/null when we upgrade the minimum version - # of binutils to 2.37, llvm to 13.0.0. - # - # Then, the following line will be really simple: - # done < <(${NM} --quiet ${1}) -done < <(${NM} ${1} 2>/dev/null || { echo "${0}: ${NM} failed" >&2; false; } ) - -# Catch error in the process substitution -wait $! +done for name in "${export_symbols[@]}" do
Signature · 1 line
2.32.0
Quoted 11 lines · Masahiro Yamada
Bash>=4.4 supports 'wait $!' to check the exit status of a process substitution, but some people using older bash versions reported an error like this:
Reported-by Tetsuo Handa <[email protected]>Reported-by Michael Ellerman <[email protected]>Reported-by Wang Yugui <[email protected]>Tested-by Tetsuo Handa <[email protected]>Tested-by Jon Hunter <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>
Some comments below.
Documentation/process/changes.rst you probably needn't concern yourself with pcmciautils. · line 35
Quoted 9 lines
Documentation/process/changes.rst +1
-0@@ -32,6 +32,7 @@ you probably needn't concern yourself with pcmciautils. GNU C 5.1 gcc --version Clang/LLVM (optional) 11.0.0 clang --version GNU make 3.81 make --version +bash 4.2 bash --version
/usr/bin/env bash
and definitely /bin/bash
both show up a lot in kernel sources. At this point, I think bash is a requirement at this point, so it's good to document it finally.
Documentation/process/changes.rst you probably needn't concern yourself with pcmciautils.
Quoted 7 lines
Documentation/process/changes.rst +7
-0+# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) shows +# 'no symbols' diagnostic (but exits with 0). It is harmless and hidden by +# '2>/dev/null'. However, it suppresses real error messages as well. Add a +# hand-crafted error message here. +# +# Use --quiet instead of 2>/dev/null when we upgrade the minimum version of +# binutils to 2.37, llvm to 13.0.0.
Might be nice to include TODO: in the comment block. Vim will highlight these in comments.
Signature · 2 lines
Thanks, ~Nick Desaulniers
Quoted 33 lines · Nick Desaulniers
Quoted 11 lines · Masahiro Yamada
Bash>=4.4 supports 'wait $!' to check the exit status of a process substitution, but some people using older bash versions reported an error like this:
Reported-by Tetsuo Handa <[email protected]>Reported-by Michael Ellerman <[email protected]>Reported-by Wang Yugui <[email protected]>Tested-by Tetsuo Handa <[email protected]>Tested-by Jon Hunter <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>Acked-by Nick Desaulniers <[email protected]>Some comments below.
Documentation/process/changes.rst you probably needn't concern yourself with pcmciautils. · line 35
Quoted 9 lines
Documentation/process/changes.rst +1
-0@@ -32,6 +32,7 @@ you probably needn't concern yourself with pcmciautils. GNU C 5.1 gcc --version Clang/LLVM (optional) 11.0.0 clang --version GNU make 3.81 make --version +bash 4.2 bash --version
/usr/bin/envbash
and definitely/bin/bash
both show up a lot in kernel sources. At this point, I think bash is a requirement at this point, so it's good to document it finally.
Quoted 10 lines
Documentation/process/changes.rst you probably needn't concern yourself with pcmciautils.
Quoted 7 lines
Documentation/process/changes.rst +7
-0+# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) shows +# 'no symbols' diagnostic (but exits with 0). It is harmless and hidden by +# '2>/dev/null'. However, it suppresses real error messages as well. Add a +# hand-crafted error message here. +# +# Use --quiet instead of 2>/dev/null when we upgrade the minimum version of +# binutils to 2.37, llvm to 13.0.0.Might be nice to include
TODO:in the comment block. Vim will highlight these in comments.
OK. will do.
Thanks.
Signature · 2 lines
Best Regards Masahiro Yamada
Sedat Dilek
Tested-byQuoted 7 lines · Nick Desaulniers
Quoted 5 lines · Masahiro Yamada
Bash>=4.4 supports 'wait $!' to check the exit status of a process substitution, but some people using older bash versions reported an error like this:
Quoted 9 lines
Quoted 6 lines
Reported-by Tetsuo Handa <[email protected]>Reported-by Michael Ellerman <[email protected]>Reported-by Wang Yugui <[email protected]>Tested-by Tetsuo Handa <[email protected]>Tested-by Jon Hunter <[email protected]>Signed-off-by Masahiro Yamada <[email protected]>Acked-by Nick Desaulniers <[email protected]>
-Sedat-
Quoted 31 lines
Some comments below.
Documentation/process/changes.rst you probably needn't concern yourself with pcmciautils. · line 35
Quoted 9 lines
Documentation/process/changes.rst +1
-0@@ -32,6 +32,7 @@ you probably needn't concern yourself with pcmciautils. GNU C 5.1 gcc --version Clang/LLVM (optional) 11.0.0 clang --version GNU make 3.81 make --version +bash 4.2 bash --version
/usr/bin/envbash
and definitely/bin/bash
both show up a lot in kernel sources. At this point, I think bash is a requirement at this point, so it's good to document it finally.Documentation/process/changes.rst you probably needn't concern yourself with pcmciautils.
Quoted 7 lines
Documentation/process/changes.rst +7
-0+# If there is no symbol in the object, ${NM} (both GNU nm and llvm-nm) shows +# 'no symbols' diagnostic (but exits with 0). It is harmless and hidden by +# '2>/dev/null'. However, it suppresses real error messages as well. Add a +# hand-crafted error message here. +# +# Use --quiet instead of 2>/dev/null when we upgrade the minimum version of +# binutils to 2.37, llvm to 13.0.0.Might be nice to include
TODO:in the comment block. Vim will highlight these in comments.--
Thanks,
~Nick Desaulniers