Hi Stephen, Thank you for your feedback and sorry for the delay with my reply.
> Second, I am assuming like all good scripts, this is set -e. So you
nope -- I removed set -e since
/etc/init.d/skeleton
states:
# Do NOT "set -e"
since it would cause the script to fail on any failed call to
function/command, which it shouldn't do but rather process return value.
and indeed simple example shows that even if I go with -ne ... || I
would get early exit from the script if a function returns non-0:
> cat 2.sh
#!/bin/sh
#set -e
failingfunc()
{
return 2
}
failingfunc
[ $? -ne 2 ] || echo HERE1
echo HERE2
> sh -e -x 2.sh
+ failingfunc
+ return 2
> sh -x 2.sh
+ failingfunc
+ return 2
+ '[' 2 -ne 2 ']'
+ echo HERE1
HERE1
+ echo HERE2
HERE2
> want your test to always be true, meaning you probably want:
> [ $? -ne 2 ] || rm -f $PIDFILE. Otherwise the first condition of your
> and'ed statement is false, and the whole line is false, and it exits.
the solution seems to be wrapping pidofproc in () to spawn another
subshell (or I think we can || result=$?, and then process $result instead of
$?)
> cat 3.sh
#!/bin/sh
#set -e
failingfunc()
{
return 2
}
( failingfunc )
[ $? -ne 2 ] || echo HERE1
echo HERE2
> sh -e -x 3.sh
+ failingfunc
+ return 2
+ '[' 2 -ne 2 ']'
+ echo HERE1
HERE1
+ echo HERE2
HERE2
But then to enable -e in every init.d script every start-stop-daemon
call should be wrapped in such way, or am I missing something?
> You also probably don't need to recursively remove a single file, and I
> imagine it's vaguely safer in the event that $PIDFILE expands wrongly.
That is very true! I will take care about that - thank you!
--
.-.
=------------------------------ /v\ ----------------------------=
Keep in touch // \\ (yoh@|www.)onerussian.com
Yaroslav Halchenko /( )\ ICQ#: 60653192
Linux User ^^-^^ [175555]
pgp2bw27Je42n.pgp
Description: PGP signature

