systemd lsb-base integration script leaking shell variable changes which can break consumers

Bug #1940008 reported by Ryan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
systemd (Ubuntu)
Expired
Wishlist
Unassigned

Bug Description

I am using systemd version 248.3-1ubuntu3 from the impish repository.

It was compiled and built in the following manner:
# add impish deb-src repository to apt sources
apt build-dep systemd/impish
apt source -b systemd/impish

Once built, it was installed over the top of systemd 245.4-4ubuntu3.

I am running ubuntu 20.04.2.

The source tarball of systemd includes a file (./debian/systemd/lib/lsb/init-functions.d/40-systemd) which is intended to be installed into the drop-in script directory provided by the lsb-base package (/lib/lsb/init-functions.d).

The problem that I am having is that this file (which is sourced by any script which sources /lib/lsb/init-functions) is setting variables, and in doing so, accidentally overwriting variables which are configured by the calling script.

https://gist.github.com/TheWug/e120145f08e994d89e235e077a82ea75#file-40-systemd-L19

I noticed this when investigating why ipmiutil_wdt.service (provided by package ipmiutil) was failing to start. The problem is that the ipmiutil_wdt script, which makes use of init-functions, was statically setting some variables for later use, including one called $prog. $prog is then inadvertently overwritten by 40-systemd when ipmiutil_wdt sources /lib/lsb/init-functions.

I think this is systemd's bug because systemd's lsb-base drop-in is not being a "good neighbor" to the scripts with which it shares a controlling shell. Even if ipmiutil were to rewrite its ipmiutil-wdt script, any other such script provided by another package which tries to use a variable called $prog (or $executable, or $argument, or $service, or $state, or any of a handful of others) will find its feet being stepped on by systemd's drop-in.

I propose that the drop-in be modified to encapsulate all of this behavior where variables are assigned to within a function or subshell or something, so they can't accidentally contaminate the outside world.

Other related package versions:
lsb-base: 11.1.0ubuntu2
ipmiutil: 3.1.5-1

Revision history for this message
Ryan (wug) wrote :

I'm not a bash script architect, but I bodged together this workaround and the ipmiutil_wdt service starts correctly with it applied to my system:

https://gist.github.com/TheWug/1a7f509e040f10c05039acc06fe29d9e

Revision history for this message
Ryan (wug) wrote :

It also looks like, farther down, systemctl_redirect() leaks $service. Not sure if it's intentional or not, given that it works to protect its other variables, so maybe it could use some attention too.

https://gist.github.com/TheWug/e120145f08e994d89e235e077a82ea75#file-40-systemd-L70

Revision history for this message
Nick Rosbrook (enr0n) wrote :

 Is this still relevant?

Changed in systemd (Ubuntu):
status: New → Incomplete
importance: Undecided → Wishlist
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for systemd (Ubuntu) because there has been no activity for 60 days.]

Changed in systemd (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.