Bug#931719: 40-systemd: line 11: 1: unbound variable when sourcing /lib/lsb/init-functions with $1 unset

Thomas Bätzler thomas at baetzler.de
Thu Jul 11 16:15:00 BST 2019


Hi Mert,

On 10.07.2019 at 17:47, Mert Dirik wrote:
>>> After upgrading to Debian 10 we noticed a slightly different behaviour
>>> in  /lib/lsb/init-functions.d/40-systemd which caused one of our scripts
>>> to break and which also causes some /etc/init.d files like
>>> /etc/init.d/mysql
>>> to no longer to display their help text when calling them without a
>>> parameter.
>>>
>>> The root cause are accesses to the $1 and $2 variables without checking
>>> if they are defined beforehand. When running code using "set -u", this
>>> causes the above mentioned error.
>>>
> Which command did you use to make that happen? I'm asking because I
> can't test it right now.

To wit:

  root at kvm1:~# /etc/init.d/rsync
  Usage: /etc/init.d/rsync {start|stop|reload|force-reload|restart|status}

vs.

  root at kvm1:~# /etc/init.d/mysql
  /lib/lsb/init-functions.d/40-systemd: line 11: 1: unbound variable


[Suggested patch]

> It seems OK.
>
> What I'd rather do is drop the "##*/" substitution, and set a default
> value if $1 is unset, and let the statement continue:
>
>           executable="$__init_d_script_name"
>           argument="$1"
>       elif [ "${0##*/}" = "init-d-script" ] ||
> -         [ "${0##*/}" = "${1##*/}" ]; then # scripts run with old
> init-d-script
> +         [ "${0}" = "${1:-}" ]; then # scripts run with old  init-d-script
>           executable="$1"
> -        argument="$2"
> +        argument="${2:-}"
>       else # plain old scripts
>           executable="$0"
>           argument="$1"
>
> Dropping the "##*/" substitution isn't actually related to this change
> but dropping it allows the use of ":-" syntax in the same line. I was
> in fact thinking about dropping it irrelevant to this issue.
>
>
> Another important issue here is the use of "set -e" and "set -u" on
> the /etc/init.d/mysql script. It is ineffective right now because
> later in 40-systemd file they are set back to their defaults (set +e
> and set +u). I don't know the policy or best practices about this
> topic but either one of the scripts should be accommodated to be in
> compliance with the other.
>
> I'm sorry I can't test any of this right now as I don't have a
> suitable and up-to-date test system ready and I'm not sure when I'll
> be.


In this case, line 16 has to be changed to 'argument="${1:-}', too (last 
line of your patch), since the call without argument falls through to 
the else branch, i.e.

     # diff -C1 40-systemd.orig 40-systemd
     *** 40-systemd.orig     2019-07-09 16:27:19.380695186 +0200
     --- 40-systemd  2019-07-11 16:58:33.113302048 +0200
     ***************
     *** 10,17 ****
           elif [ "${0##*/}" = "init-d-script" ] ||
     !          [ "${0##*/}" = "${1##*/}" ]; then # scripts run with 
old  init-d-script
           executable="$1"
     !         argument="$2"
           else # plain old scripts
           executable="$0"
     !         argument="$1"
           fi
     --- 10,17 ----
           elif [ "${0##*/}" = "init-d-script" ] ||
     !          [ "${0}" = "${1:-}" ]; then # scripts run with old 
init-d-script
           executable="$1"
     !         argument="${2:-}"
           else # plain old scripts
           executable="$0"
     !         argument="${1:-}"
           fi


Behaviour after the change:

  # /etc/init.d/mysql
  Usage: /etc/init.d/mysql 
start|stop|restart|reload|force-reload|status|bootstrap


HTH,
Thomas



More information about the Pkg-systemd-maintainers mailing list