On Wed, Aug 31, 2016 at 12:29:59PM +0200, Dejan Muhamedagic wrote:
> > Also remember that sometimes we set a "local" variable in a function
> > and expect it to be visible in nested functions, but also set a new
> > value in a nested function and expect that value to be reflected
> > in the outer scope (up to the last "local").
> 
> I hope that this wasn't (ab)used much, it doesn't sound like it
> would be easy to follow.
> 
> > diff --git a/heartbeat/ocf-shellfuncs.in b/heartbeat/ocf-shellfuncs.in
> > index 6d9669d..4151630 100644
> > --- a/heartbeat/ocf-shellfuncs.in
> > +++ b/heartbeat/ocf-shellfuncs.in
> > @@ -920,3 +920,37 @@ ocf_is_true "$OCF_TRACE_RA" && ocf_start_trace
> >  if ocf_is_true "$HA_use_logd"; then
> >     : ${HA_LOGD:=yes}
> >  fi
> > +
> > +# We use a lot of function local variables with the "local" keyword.
> > +# Which works fine with dash and bash,
> > +# but does not work with e.g. ksh.
> > +# Fail cleanly with a sane error message,
> > +# if the current shell does not feel compatible.
> > +
> > +__ocf_check_for_incompatible_shell_l2()
> > +{
> > +   [ $__ocf_check_for_incompatible_shell_k = v1 ] || return 1
> > +   local __ocf_check_for_incompatible_shell_k=v2
> > +   [ $__ocf_check_for_incompatible_shell_k = v2 ] || return 1
> > +   return 0
> > +}
> > +
> > +__ocf_check_for_incompatible_shell_l1()
> > +{
> > +   [ $__ocf_check_for_incompatible_shell_k = v0 ] || return 1
> 
> If there's no "local" and that in the function below fails, won't
> this produce a syntax error (due to __ocf_..._k being undefined)?

Which is ok with me, still return 1 ;-)

> > +   local __ocf_check_for_incompatible_shell_k=v1
> > +   __ocf_check_for_incompatible_shell_l2

This ^^ needs to be:
> > +   __ocf_check_for_incompatible_shell_l2 || return 1

> > +   [ $__ocf_check_for_incompatible_shell_k = v1 ] || return 1
> > +   return 0
> > +}
> > +
> > +__ocf_check_for_incompatible_shell()
> > +{
> > +   local __ocf_check_for_incompatible_shell_k=v0

Similarly, this:
> > +   __ocf_check_for_incompatible_shell_l1

should be
> > +   __ocf_check_for_incompatible_shell_l1 || return 1

> > +   [ $__ocf_check_for_incompatible_shell_k = v0 ] && return 0
> > +   ocf_exit_reason "Current shell seems to be incompatible. We suggest 
> > dash or bash (compatible)."
> > +   exit $OCF_ERR_GENERIC
> > +}
> > +
> > +__ocf_check_for_incompatible_shell
> 
> Looks good otherwise. If somebody's willing to test it on
> solaris...

There is a ksh93 for linux as well, and it appears to be very similar to
the one apparenly shipped with solaris. But yes, you are right ;-)

    Lars


_______________________________________________
Users mailing list: Users@clusterlabs.org
http://clusterlabs.org/mailman/listinfo/users

Project Home: http://www.clusterlabs.org
Getting started: http://www.clusterlabs.org/doc/Cluster_from_Scratch.pdf
Bugs: http://bugs.clusterlabs.org

Reply via email to