Hi

Am 18.01.23 um 18:21 schrieb Mike:
Package: systemd
Version: 247.3-7+deb11u1
Severity: normal
X-Debbugs-Cc: [email protected]

Dear Maintainer,

Under certain circumstances I'm seeing inconsistent values for the %j specifier 
used in service and drop-in units.
To reproduce:

Create a systemd unit /lib/systemd/system/[email protected] as:

     [Unit]
     Description=good old foo

     [Service]
     Type=oneshot
     ExecStart=/bin/env echo "%%i=[%i]   %%j=[%j] (from %n ([email protected]))"

Create a drop-in unit /etc/systemd/system/[email protected]/additional.conf as:

     [Service]
     ExecStart=/bin/env echo "%%i=[%i]   %%j=[%j] (from %n (additional.conf))"

Reload the systemd units and run systemctl cat [email protected].  The output shows 
the drop-in being correctly incorporated:

     # /lib/systemd/system/[email protected]
     [Unit]
     Description=good old foo

     [Service]
     Type=oneshot
     ExecStart=/bin/env echo "%%i=[%i]   %%j=[%j] (from %n ([email protected]))"

     # /etc/systemd/system/[email protected]/additional.conf
     [Service]
     ExecStart=/bin/env echo "%%i=[%i]   %%j=[%j] (from %n (additional.conf))"

Now create a symlink which contains a %j specifier:

     sudo ln -sv /lib/systemd/system/[email protected] 
/etc/systemd/system/[email protected]

Reload the systemd units and run systemctl cat [email protected].  The output is 
identical to that of systemctl cat [email protected]
Now start the service with a %i specifer:

     systemctl start [email protected]

The output is:

     ● [email protected] - good old foo
          Loaded: loaded (/lib/systemd/system/[email protected]; static)
          Drop-In: /etc/systemd/system/[email protected]
                  └─additional.conf
          Active: inactive (dead)

     Nov 01 12:10:31 Intel-NUC systemd[1]: Starting good old foo...
     Nov 01 12:10:31 Intel-NUC env[56108]: %i=[baz]   %j=[bar] (from 
[email protected] ([email protected]))
     Nov 01 12:10:31 Intel-NUC env[56109]: %i=[baz]   %j=[foo] (from 
[email protected] (additional.conf))
     Nov 01 12:10:31 Intel-NUC systemd[1]: [email protected]: Succeeded.
     Nov 01 12:10:31 Intel-NUC systemd[1]: Finished good old foo.

This shows that - in a single invocation - the value for %i is constant but the 
value for %j changes from 'bar' to 'foo'.  I would have expected the value of 
%j to be 'bar' throughout.  This may not be a bug, but - IMHO - this changing 
of values is unintuitive and I have been unable to find documentation that 
states the expected behaviour in this situation.  Happy to accept that I have 
confused/abused systemd with my custom /etc/systemd/system/[email protected] 
symlink.


Ideally, such issues should be tested with the latest version of systemd (or at least v251) and then reported upstream.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to