From: Kairui Song <kasong at redhat.com>
Only acquire the single instance lock when necessary.
For some commands, like showmem, estimate or help, there is no reason
for kdumpctl to be blocked.
Signed-off-by: Kairui Song <kasong(a)redhat.com>
Signed-off-by: Lichen Liu <lichliu(a)redhat.com>
---
kdumpctl | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/kdumpctl b/kdumpctl
index 7e561fd..e63adea 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1764,18 +1764,21 @@ main()
case "$1" in
start)
+ single_instance_lock
if ! start; then
derror "Starting kdump: [FAILED]"
exit 1
fi
;;
stop)
+ single_instance_lock
if ! stop; then
derror "Stopping kdump: [FAILED]"
exit 1
fi
;;
status)
+ single_instance_lock
EXIT_CODE=0
is_kernel_loaded "$DEFAULT_DUMP_MODE"
case "$?" in
@@ -1791,9 +1794,11 @@ main()
exit $EXIT_CODE
;;
reload)
+ single_instance_lock
reload
;;
restart)
+ single_instance_lock
if ! stop; then
derror "Stopping kdump: [FAILED]"
exit 1
@@ -1804,11 +1809,13 @@ main()
fi
;;
rebuild)
+ single_instance_lock
rebuild
;;
condrestart) ;;
propagate)
+ single_instance_lock
propagate_ssh_key
;;
showmem)
@@ -1821,15 +1828,18 @@ main()
get_default_crashkernel "$2"
;;
reset-crashkernel)
+ single_instance_lock
shift
reset_crashkernel "$@"
;;
_reset-crashkernel-after-update)
+ single_instance_lock
if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then
reset_crashkernel_after_update
fi
;;
_reset-crashkernel-for-installed_kernel)
+ single_instance_lock
if [[ $(kdump_get_conf_val auto_reset_crashkernel) != no ]]; then
reset_crashkernel_for_installed_kernel "$2"
fi
@@ -1850,9 +1860,6 @@ if [[ ! -f $KDUMP_CONFIG_FILE ]]; then
exit 1
fi
-# 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.
(
--
2.40.1