From e51151ec35f4dcc3b9f8f10719df76b93abc4285 Mon Sep 17 00:00:00 2001 From: Michael Prokop Date: Tue, 26 Apr 2022 13:12:46 +0200 Subject: [PATCH] TT#173500 Create tmpfiles with template name We want to be able to track down any left-behind tmp files, so ensure we're creating them with according file names. Change-Id: I1aa0ccdb8834e8aef919f1f028028c1bb14cbd01 --- hooks/pre-commit | 4 ++-- scripts/build | 2 +- scripts/check | 2 +- scripts/clean | 8 ++++---- scripts/del | 2 +- scripts/get | 4 ++-- scripts/patch | 8 ++++---- scripts/services | 6 +++--- scripts/set | 2 +- testsuite/ngcp-network | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/hooks/pre-commit b/hooks/pre-commit index 5d10fcdb..0cd7409d 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -16,7 +16,7 @@ fi filter_ignore() { if [ -e ".gitignore" ]; then - listfile="$( mktemp -t ngcpcfg-git.XXXXXXXXXX )" + listfile="$(mktemp -t ngcpcfg-git.XXXXXXXXXX)" (git ls-files -oi --exclude-standard; git ls-files -oi --exclude-standard --directory) | sort | uniq > "$listfile" || true sed 's/^\.\///' | grep -xFvf "$listfile" rm -f "$listfile" @@ -94,7 +94,7 @@ generate_metadata() { ' } -ngcpcfg_perms=$(mktemp) +ngcpcfg_perms=$(mktemp -t ngcpcfg-perms.XXXXXXXXXX) chown root:root "${ngcpcfg_perms}" # Make sure the file is not readable by others, since it can leak # information about contents of non-readable directories diff --git a/scripts/build b/scripts/build index 898702d4..41f12b03 100755 --- a/scripts/build +++ b/scripts/build @@ -63,7 +63,7 @@ build_config_files_instances() { fi log_debug "${RUNNER} ${HELPER}/instances-info $*" - inst_cfg=$(mktemp) + inst_cfg=$(mktemp -t ngcpcfg-build.XXXXXXXXXX ) while IFS=":" read -r -a info; do source=${info[0]} target=${info[1]} diff --git a/scripts/check b/scripts/check index 226151ac..3a375c3e 100755 --- a/scripts/check +++ b/scripts/check @@ -156,7 +156,7 @@ validate_config() { case "${config_type}" in config|constants) c_cleanup=true - c="$(mktemp --tmpdir "ngcpcfg-${config_type}-XXXXXXXXXX.yml")" + c="$(mktemp -t "ngcpcfg-check-${config_type}.XXXXXXXXXX.yml")" "${SCRIPTS}/cat" "${config_type}" >"$c" ;; *) diff --git a/scripts/clean b/scripts/clean index 9f182bc3..aee32f62 100755 --- a/scripts/clean +++ b/scripts/clean @@ -111,7 +111,7 @@ clean_untracked() { log_info "Removing all untracked files (if any):" local tmp - tmp=$(mktemp) + tmp=$(mktemp -t ngcpcfg-clean-untracked.XXXXXXXXXX) log_debug "git clean -n -f -d -x" if ! git clean -n -f -d -x > "${tmp}" ; then @@ -152,7 +152,7 @@ clean_stash() { log_info "Removing all stashes (if any):" local tmp - tmp=$(mktemp) + tmp=$(mktemp -t ngcpcfg-clean-stash.XXXXXXXXXX) log_debug "git stash list" if ! git stash list > "${tmp}" ; then @@ -193,7 +193,7 @@ clean_old_local_branches() { log_info "Removing all old branches (if any):" local tmp - tmp=$(mktemp) + tmp=$(mktemp -t ngcpcfg-clean-oldbranch.XXXXXXXXXX) log_debug "git branch" if ! git branch > "${tmp}" ; then @@ -244,7 +244,7 @@ clean_reset_master() { fi local tmp - tmp=$(mktemp) + tmp=$(mktemp -t ngcpcfg-clean-reset.XXXXXXXXXX) log_debug "git diff origin/master..master" if ! git diff origin/master..master > "${tmp}" ; then diff --git a/scripts/del b/scripts/del index 9d20ba93..ce6038f8 100755 --- a/scripts/del +++ b/scripts/del @@ -63,7 +63,7 @@ log_debug "Deleting option '${option}' from '${file}'" perl_line="delete \$yaml->{${option//./\}->\{}};" log_debug "perl line: ${perl_line}" -tmp=$(mktemp) +tmp=$(mktemp -t ngcpcfg-del.XXXXXXXXXX) log_debug "Temporary perl file: ${tmp}" cat > "${tmp}" << EOF diff --git a/scripts/get b/scripts/get index b60f677f..4c21ec9d 100755 --- a/scripts/get +++ b/scripts/get @@ -11,9 +11,9 @@ get_value() { # assume safe defaults umask 0077 - input_file="$(mktemp)" + input_file="$(mktemp -t ngcpcfg-get-in.XXXXXXXXXX)" echo "[% $value %]" > "${input_file}" - output_file="$(mktemp)" + output_file="$(mktemp -t ngcpcfg-get-out.XXXXXXXXXX)" if "${HELPER}/tt2-process" -p -q "${ARGS[@]}" "${input_file}" "${output_file}" >/dev/null 2>&1 ; then cat "${output_file}" diff --git a/scripts/patch b/scripts/patch index 712385d7..880db727 100755 --- a/scripts/patch +++ b/scripts/patch @@ -38,7 +38,7 @@ patch_search() { shift # remove the first 'patchtt/customtt' local files=("$@") local fileslist - fileslist=$(mktemp) + fileslist=$(mktemp -t ngcpcfg-patch-search.XXXXXXXXXX) local regexp="" local hosts=() @@ -127,7 +127,7 @@ patch_apply() { local template="${patch%%.patchtt*}.tt2" local customtt="${patch//.patchtt/.customtt}" local patch_output - patch_output=$(mktemp) + patch_output=$(mktemp -t ngcpcfg-patch-out.XXXXXXXXXX) local patch_opts=() patch_opts+=("--input=${patch}") @@ -199,9 +199,9 @@ patch_import_customtt() { local patchtt="${customtt_file//.customtt/.patchtt}" local tmp_patchtt - tmp_patchtt=$(mktemp) + tmp_patchtt=$(mktemp -t ngcpcfg-patch-import.XXXXXXXXXX) local diff_output - diff_output=$(mktemp) + diff_output=$(mktemp -t ngcpcfg-patch-diff.XXXXXXXXXX) # diff exit status is 0 if inputs are the same, 1 if different, 2 if trouble. diff --git a/scripts/services b/scripts/services index 20df26c9..38faf6e3 100755 --- a/scripts/services +++ b/scripts/services @@ -73,7 +73,7 @@ exec_wrapper() { # get rid of "./" and "//" in file names normalize_files() { - NORMALIZED_FILES="$(mktemp)" + NORMALIZED_FILES="$(mktemp -t ngcpcfg-services-norm.XXXXXXXXXX)" log_debug "NORMALIZED_FILES = ${NORMALIZED_FILES}" CLEANUP_FILES+=("${NORMALIZED_FILES}") @@ -89,7 +89,7 @@ normalize_files() { # restart HA just after monit (see MT#17163) # restart other services in alphabetical order sort_service_list() { - SORTED_LIST="$(mktemp)" + SORTED_LIST="$(mktemp -t ngcpcfg-services-sorted.XXXXXXXXXX)" log_debug "SORTED_LIST = ${SORTED_LIST}" CLEANUP_FILES+=("${SORTED_LIST}") @@ -305,7 +305,7 @@ fi log_debug "systemd_daemon_reload_preset function" systemd_daemon_reload_preset -TMPFILE="$(mktemp)" +TMPFILE="$(mktemp -t ngcpcfg-services-tmp.XXXXXXXXXX)" log_debug "TMPFILE = ${TMPFILE}" log_debug "OUTPUT_DIRECTORY=${OUTPUT_DIRECTORY}" diff --git a/scripts/set b/scripts/set index 3309a681..486b8755 100755 --- a/scripts/set +++ b/scripts/set @@ -97,7 +97,7 @@ else value="\"${value}\"" fi -tmp=$(mktemp) +tmp=$(mktemp -t ngcpcfg-set.XXXXXXXXXX) log_debug "Temporary perl file: ${tmp}" cat > "${tmp}" << EOF diff --git a/testsuite/ngcp-network b/testsuite/ngcp-network index 3670bc1e..8b492b6b 100644 --- a/testsuite/ngcp-network +++ b/testsuite/ngcp-network @@ -12,7 +12,7 @@ PATH=$PATH:../t/fixtures/bin/ count=0 RC=0 -OUTPUT=$(mktemp) || exit 1 +OUTPUT=$(mktemp -t ngcpcfg-testsuite.XXXXXXXXXX) || exit 1 # generated files rm -rf testfiles