diff options
author | rillig <rillig@pkgsrc.org> | 2019-03-24 08:40:07 +0000 |
---|---|---|
committer | rillig <rillig@pkgsrc.org> | 2019-03-24 08:40:07 +0000 |
commit | 8b2219f391ca708a50c81e8f893565588daacce6 (patch) | |
tree | b13253c20947d1760c9a3fb938119cdea0e38be0 /mk | |
parent | ee1bede6af794009180195452a03da9af1359fe7 (diff) | |
download | pkgsrc-8b2219f391ca708a50c81e8f893565588daacce6.tar.gz |
mk/tools: fix quoting when logging tool invocations
When a package or the infrastructure defined a tool with custom
TOOLS_ARGS or TOOLS_SCRIPT containing special characters, these could
lead to unintuitive interactions at the time when that tool invocation
was logged in the tool wrapper log. Some of the logging output ended up
on stdout, while some of the normal output ended up in the log, and parts
of the quoted arguments were even evaluated as shell commands.
The logging of the wrapped tool commands is not perfect yet, but at least
it's much more predictable now.
Diffstat (limited to 'mk')
-rw-r--r-- | mk/tools/create.mk | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/mk/tools/create.mk b/mk/tools/create.mk index a6e8d0ae5e7..db2974f1ed8 100644 --- a/mk/tools/create.mk +++ b/mk/tools/create.mk @@ -1,4 +1,4 @@ -# $NetBSD: create.mk,v 1.9 2019/03/22 22:13:21 rillig Exp $ +# $NetBSD: create.mk,v 1.10 2019/03/24 08:40:07 rillig Exp $ # # Copyright (c) 2005, 2006 The NetBSD Foundation, Inc. # All rights reserved. @@ -137,8 +137,6 @@ TOOLS_CMD.${_t_}?= ${TOOLS_DIR}/bin/${_t_} TOOLS_PATH.${_t_}?= ${FALSE} TOOLS_SCRIPT_DFLT.${_t_}= \ ${TOOLS_PATH.${_t_}} ${TOOLS_ARGS.${_t_}} "$$@" -_TOOLS_LOGSCRIPT_DFLT.${_t_}= \ - ${TOOLS_PATH.${_t_}} ${TOOLS_ARGS.${_t_}} $$* override-tools: ${TOOLS_CMD.${_t_}} @@ -151,18 +149,24 @@ ${TOOLS_CMD.${_t_}}: if ${TEST} -n ${TOOLS_SCRIPT.${_t_}:Q}""; then \ create=wrapper; \ script=${TOOLS_SCRIPT.${_t_}:Q}; \ - logscript="$$script"; \ + logprefix='"set args "$$@"; shift; "'; \ + logmain=${TOOLS_SCRIPT.${_t_}:Q:Q}; \ + logsuffix=''; \ elif ${TEST} -n ${TOOLS_PATH.${_t_}:Q}""; then \ if ${TEST} -n ${TOOLS_ARGS.${_t_}:Q}""; then \ create=wrapper; \ script=${TOOLS_SCRIPT_DFLT.${_t_}:Q}; \ - logscript=${_TOOLS_LOGSCRIPT_DFLT.${_t_}:Q}; \ + logprefix=''; \ + logmain=${TOOLS_PATH.${_t_}:Q:Q}\"\ \"${TOOLS_ARGS.${_t_}:Q:Q}; \ + logsuffix=' "$$*"'; \ else \ case ${TOOLS_PATH.${_t_}:Q}"" in \ /*) create=symlink ;; \ *) create=wrapper; \ script=${TOOLS_SCRIPT_DFLT.${_t_}:Q}; \ - logscript=${_TOOLS_LOGSCRIPT_DFLT.${_t_}:Q}; \ + logprefix=''; \ + logmain=${TOOLS_PATH.${_t_}:Q:Q}\"\ \"; \ + logsuffix=' "$$*"'; \ esac; \ fi; \ else \ @@ -173,7 +177,9 @@ ${TOOLS_CMD.${_t_}}: { ${ECHO} '#!'${TOOLS_SHELL:Q}; \ ${ECHO} 'wrapperlog="$${TOOLS_WRAPPER_LOG-'${_TOOLS_WRAP_LOG:Q}'}"'; \ ${ECHO} '${ECHO} "[*] "'${.TARGET:Q}'" $$*" >> $$wrapperlog'; \ - ${ECHO} "${ECHO} \"<.> $$logscript\" >> \$$wrapperlog"; \ + ${ECHO} 'logprefix='$$logprefix; \ + ${ECHO} 'logmain='$$logmain; \ + ${ECHO} "${ECHO} '<.>' \"\$$logprefix\$$logmain\"$$logsuffix >> \$$wrapperlog"; \ ${ECHO} "$$script"; \ } > ${.TARGET:Q}; \ ${CHMOD} +x ${.TARGET:Q}; \ |