Skip to content

systemctl link should refuse when target is inside systemd own's hierarchy #24605

Closed

Description

@volter

systemd version the issue has been seen with

251

Used distribution

Debian Bullseye Backports

Linux kernel version used

5.10.0

CPU architectures issue was seen on

x86_64

Component

systemctl

Expected behaviour you didn't see

Symlinked units can be used just like in previous releases, for instance 241.

Unexpected behaviour you saw

Symlinked unit files are considered "bad" by systemctl, can "not be found" and consequently not be enabled or started.

Steps to reproduce the problem

mkdir /etc/systemd/system/mydir
cat > /etc/systemd/system/mydir/test.service <<EOF
[Unit]
Description=Test

[Service]
ExecStart=/bin/sleep infinity

[Install]
WantedBy=multi-user.target
EOF

systemctl link /etc/systemd/system/mydir/test.service
#Created symlink /etc/systemd/system/test.service → /etc/systemd/system/mydir/test.service.
systemctl daemon-reload
#Nothing bad in the journal

systemctl list-unit-files
systemctl start test
#Failed to start test.service: Unit test.service not found.
systemctl enable test
#Failed to enable unit: Refusing to operate on alias name or linked unit file: test.service

Additional program output to the terminal or log subsystem illustrating the issue

Personally, I feel that https://github.com/systemd/systemd/issues/22000 was not resolved and that this report is a duplicate.

Activity

  1. added
    bug 🐛
    on Sep 8, 2022
  2. added this to the v252 milestone on Sep 8, 2022
  3. mrc0mmand commented on Sep 8, 2022

    @mrc0mmand
    Member

    Behaves the same with the latest main:

    -bash-5.1# journalctl -b -o short-monotonic --grep bar.service
    [3683340.083172] H systemd[1]: bar.service: Failed to load configuration: No such file or directory
    [3683340.083404] H systemd[1]: bar.service: Collecting.
    [3683346.358175] H systemd[1]: bar.service: unit self-alias: bar.service → bar.service, ignoring.
    [3683356.750922] H systemd[1]: bar.service: unit self-alias: bar.service → bar.service, ignoring.
    [3683363.780780] H systemd[1]: bar.service: Failed to load configuration: No such file or directory
    [3683363.780992] H systemd[1]: bar.service: Collecting.
    
    # ls -lR /etc/systemd/system | grep bar
    lrwxrwxrwx 1 root root   35 Sep  8 16:11 bar.service -> /etc/systemd/system/foo/bar.service
    -rw-r--r-- 1 root root 30 Sep  8 16:10 bar.service
    
    -bash-5.1# systemctl status bar.service
    Unit bar.service could not be found.
    -bash-5.1# systemctl start bar.service
    Failed to start bar.service: Unit bar.service not found.
    -bash-5.1# systemctl enable bar.service
    Failed to enable unit: Refusing to operate on alias name or linked unit file: bar.service
    
  4. mrc0mmand commented on Sep 8, 2022

    @mrc0mmand
    Member

    /* Check if the symlink remain inside of of our search path.
    * If yes, it is an alias. Verify that it is valid.
    *
    * If no, then this is a linked unit file or mask, and we don't care about the target name
    * when loading units, and we return the link *source* (resolve_destination_target == false);
    * When this is called for installation purposes, we want the final destination,
    * so we return the *target*.
    */
    const char *tail = path_startswith_strv(simplified, search_path);
    if (tail) { /* An alias */

    Shouldn't this use full path comparison instead of just startswith? Since /etc/systemd/system/foo/bar.service is not in our search path, as we don't go through subdirs, but it's going to match against /etc/systemd/system/ in this case.

    /cc @keszybz

  5. bluca commented on Oct 18, 2022

    @bluca
    Member

    While we should have a better error message on enable, and refuse the link operation, we cannot support a model where users have their own custom hierarchies within the systemd directories. It is of course possible to store units outside the systemd directories and link them in, that should be supported.

  6. changed the title [-]Linked unit files are not found[/-] [+]systemctl link should refuse when target is inside systemd own's hierarchy[/+] on Oct 18, 2022
  7. added a commit that references this issue on Oct 20, 2022
    adcd6e2
  8. added 3 commits that reference this issue on Oct 20, 2022
    ac888a0
    580d0b4
    a6f318a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 🐛systemctl

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions