Skip to content

Commit dd29865

Browse files
committed
kbuild: set EXIT trap before creating temporary directory
Swap the order of 'mkdir' and 'trap' just in case the subshell is interrupted between 'mkdir' and 'trap' although the effect might be subtle. This does not intend to make the cleanup perfect. There are more cases that miss to remove the tmp directory, for example: - When interrupted, dash does not invoke the EXIT trap (bash does) - 'rm' command might be interrupted before removing the directory I am not addressing all the cases since the tmp directory is harmless after all. Signed-off-by: Masahiro Yamada <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]>
1 parent 7193cda commit dd29865

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

scripts/Kconfig.include

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ failure = $(if-success,$(1),n,y)
2525

2626
# $(cc-option,<flag>)
2727
# Return y if the compiler supports <flag>, n otherwise
28-
cc-option = $(success,mkdir .tmp_$$; trap "rm -rf .tmp_$$" EXIT; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o)
28+
cc-option = $(success,trap "rm -rf .tmp_$$" EXIT; mkdir .tmp_$$; $(CC) -Werror $(CLANG_FLAGS) $(1) -c -x c /dev/null -o .tmp_$$/tmp.o)
2929

3030
# $(ld-option,<flag>)
3131
# Return y if the linker supports <flag>, n otherwise

scripts/Makefile.compiler

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ TMPOUT = $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_$$$$
2121
# automatically cleaned up.
2222
try-run = $(shell set -e; \
2323
TMP=$(TMPOUT)/tmp; \
24-
mkdir -p $(TMPOUT); \
2524
trap "rm -rf $(TMPOUT)" EXIT; \
25+
mkdir -p $(TMPOUT); \
2626
if ($(1)) >/dev/null 2>&1; \
2727
then echo "$(2)"; \
2828
else echo "$(3)"; \

0 commit comments

Comments
 (0)