ci-automation/secret_to_file: Fix usage from subshell

This failed when used from ( secret_to_file ... VAR ; cat $VAR )
because ( ) starts a new subshell PID and secret_to_file's returned
/proc/PID/fd/X path was then using the wrong PID.
This commit is contained in:
Kai Lueke 2022-09-20 17:06:15 +02:00
parent 2716139010
commit 978c2aebd7

View File

@ -310,7 +310,8 @@ function secret_to_file() {
exec {fd}<>"${tmpfile}"
rm -f "${tmpfile}"
echo "${secret}" | base64 --decode >&${fd}
config_ref="/proc/${$}/fd/${fd}"
# Use BASHPID because we may be in a subshell but $$ is only the main shell's PID
config_ref="/proc/${BASHPID}/fd/${fd}"
}
# --