Bash can help allocate unused FD, so avoid hardcoding FD and
avoid the subshell call.
Signed-off-by: Kairui Song <kasong(a)redhat.com>
---
kdumpctl | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 16f6e81a..62c06bfb 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -20,6 +20,7 @@ TARGET_INITRD=""
FADUMP_REGISTER_SYS_NODE="/sys/kernel/fadump_registered"
#kdump shall be the default dump mode
DEFAULT_DUMP_MODE="kdump"
+KDUMP_LOCK_FD=
image_time=0
standard_kexec_args="-d -p"
@@ -46,17 +47,17 @@ single_instance_lock()
{
local rc timeout=5
- if ! exec 9> /var/lock/kdump; then
+ if ! exec {KDUMP_LOCK_FD}> /var/lock/kdump; then
derror "Create file lock failed"
exit 1
fi
- flock -n 9
+ flock -n $KDUMP_LOCK_FD
rc=$?
while [[ $rc -ne 0 ]]; do
dinfo "Another app is currently holding the kdump lock; waiting for it to
exit..."
- flock -w $timeout 9
+ flock -w $timeout $KDUMP_LOCK_FD
rc=$?
done
}
@@ -1382,7 +1383,6 @@ main()
rebuild
;;
condrestart) ;;
-
propagate)
propagate_ssh_key
;;
@@ -1405,11 +1405,6 @@ main()
# Other kdumpctl instances will block in queue, until this one exits
single_instance_lock
-# To avoid fd 9 leaking, we invoke a subshell, close fd 9 and call main.
-# So that fd isn't leaking when main is invoking a subshell.
-(
- exec 9<&-
- main "$@"
-)
+main "$@"
exit $?
--
2.31.1