Hi Coiby,
On Wed, 23 Feb 2022 08:45:15 +0800
Coiby Xu <coxu(a)redhat.com> wrote:
Hi Philipp,
On Tue, Feb 22, 2022 at 11:22:20AM +0100, Philipp Rudo wrote:
>Hi Coiby,
>
>On Tue, 22 Feb 2022 15:07:12 +0800
>Coiby Xu <coxu(a)redhat.com> wrote:
>
[...]
>> >
>> > start_fadump()
>> >@@ -966,8 +959,6 @@ start_dump()
>> > else
>> > load_kdump
>> > fi
>> >-
>> >- return $?
>> > }
>> >
>> > check_failure_action_config()
>> >@@ -1076,7 +1067,7 @@ reload()
>> >
>> > if [[ $DEFAULT_DUMP_MODE == "fadump" ]]; then
>> > reload_fadump
>> >- return $?
>> >+ return
>> > else
>> > if ! stop_kdump; then
>> > derror "Stopping kdump: [FAILED]"
>> >@@ -1140,7 +1131,7 @@ reload_fadump()
>> > # to handle such scenario.
>> > if stop_fadump; then
>> > start_fadump
>> >- return $?
>> >+ return
>>
>> I'm curious for start_fadump and reload_fadump both of which may return 1,
>> why only return normal status?
>
>There is no "normal status" you can return. When you omit the return
>value 'return' will automatically return the status of the last
>executed command. Thus 'return' and 'return $?' are identical.
Thanks for correcting my misunderstanding! But why not simply removing
"return $?" instead?
I don't fully understand your question. Do you mean doing something like
this?
diff --git a/kdumpctl b/kdumpctl
index 630e56f..24c266f 100755
--- a/kdumpctl
+++ b/kdumpctl
@@ -1121,11 +1121,10 @@ reload_fadump()
# to handle such scenario.
if stop_fadump; then
start_fadump
- return
fi
fi
- return 1
+ return
}
stop()
Unfortunately that won't work as expected. The problem is that in bash
control statements like 'if' or 'for' do have a return value. This is
usually the return value of the last command executed _or_ 0 if, e.g. no
test condition is true for 'if' (for a full list see 'Compound Commands'
section in the bash man page). Thus the above will change the return
value in the case that stop_fadump fails.
You can test that behavior with this snippet
if false; then
false
fi && echo "return value is 0" || echo "return value is 1"
which will print "return value is 0". However, when you update
'if false;' to 'if true;' then it will print "return value is
1".
Thanks
Philipp