Hi

Am 18.01.23 um 18:21 schrieb Mike:
Package: systemd
Version: 247.3-7+deb11u1
Severity: normal
X-Debbugs-Cc: mike.shaw.nz+deb...@gmail.com

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/foo@.service as:

     [Unit]
     Description=good old foo

     [Service]
     Type=oneshot
     ExecStart=/bin/env echo "%%i=[%i]   %%j=[%j] (from %n (foo@.service))"

Create a drop-in unit /etc/systemd/system/foo@.service.d/additional.conf as:

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

Reload the systemd units and run systemctl cat foo@.service.  The output shows 
the drop-in being correctly incorporated:

     # /lib/systemd/system/foo@.service
     [Unit]
     Description=good old foo

     [Service]
     Type=oneshot
     ExecStart=/bin/env echo "%%i=[%i]   %%j=[%j] (from %n (foo@.service))"

     # /etc/systemd/system/foo@.service.d/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/foo@.service 
/etc/systemd/system/foo-bar@.service

Reload the systemd units and run systemctl cat foo-bar@.service.  The output is 
identical to that of systemctl cat foo@.service
Now start the service with a %i specifer:

     systemctl start foo-bar@baz.service

The output is:

     ● foo@baz.service - good old foo
          Loaded: loaded (/lib/systemd/system/foo@.service; static)
          Drop-In: /etc/systemd/system/foo@.service.d
                  └─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 
foo-bar@baz.service (foo@.service))
     Nov 01 12:10:31 Intel-NUC env[56109]: %i=[baz]   %j=[foo] (from 
foo@baz.service (additional.conf))
     Nov 01 12:10:31 Intel-NUC systemd[1]: foo@baz.service: 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/foo-bar@.service 
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