On Sat, Sep 18, 2021 at 12:04 AM Philipp Rudo <prudo(a)redhat.com> wrote:
Hi Kairui,
On Fri, 17 Sep 2021 01:46:30 +0800
Kairui Song <kasong(a)redhat.com> wrote:
> Bash can help allocate unused FD, so avoid hardcoding FD.
>
> Signed-off-by: Kairui Song <kasong(a)redhat.com>
> ---
> kdumpctl | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> diff --git a/kdumpctl b/kdumpctl
> index 62c06bfb..048404b1 100755
> --- a/kdumpctl
> +++ b/kdumpctl
> @@ -661,11 +661,10 @@ load_kdump()
>
> ddebug "$KEXEC $KEXEC_ARGS $standard_kexec_args
--command-line=$KDUMP_COMMANDLINE --initrd=$TARGET_INITRD $KDUMP_KERNEL"
>
> - # The '12' represents an intermediate temporary file descriptor
> - # to store the standard error file descriptor '2', and later
> - # restore the error file descriptor with the file descriptor '12'
> - # and release it.
> - exec 12>&2
> + # Use an temporary file descriptor to store the standard error
> + # file descriptor '2', and later restore the error file descriptor
> + local temp_fd
> + exec {temp_fd}>&2
> exec 2>> $KDUMP_LOG_PATH/kdump.log
> PS4='+ $(date "+%Y-%m-%d %H:%M:%S") ${BASH_SOURCE}@${LINENO}:
'
> set -x
> @@ -677,7 +676,7 @@ load_kdump()
>
> ret=$?
> set +x
> - exec 2>&12 12>&-
> + eval "exec 2>&$temp_fd $temp_fd>&-"
do you really need the eval here? The way I understand it
exec 2>$temp_fd {temp_fd}>&-
should work just fine.
Thanks
Philipp
>
> remove_kdump_kernel_key
>
The eval is required, POSIX has some wired syntax parsing:
$ exec 2>/dev/null
works, but:
$ ab=2
$ exec $ab>/dev/null
dash: 2: exec: 2: not found
Will fail, the eval can fix that. spellcheck wiki says POSIX only
recognizes one digit after the `exec` call, or else it will be
interrupted as an executable name, so let's use eval to "workaround"
this.
--
Best Regards,
Kairui Song