On Thu, Feb 24, 2022 at 05:49:33PM +0100, Philipp Rudo wrote:
Hi Coiby,
> 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?
Sorry for not being clear enough.
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
Although I only suggested removing this return originally (which obvious
is incorrect if I read the remaining code in reload_fadump),
fi
fi
- return 1
+ return
actually it works with this return also removed.
}
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".
If we modify your example to the same if/else/fi structure as
reload_fadump,
if false; then
false
else
true
fi && echo "return value is 0" || echo "return value is 1"
this will print "return value is 0". And changing the only true to
false will print "return value is 1".
Thanks
Philipp
--
Best regards,
Coiby