What were you trying to do that didn't work?
Trying to restart the systemd --user instance, we can see that it often fails with the following error message:
Mar 26 07:44:04.186585 vm-systemduser9 systemd[5755]: Finished Exit the Session. Mar 26 07:44:04.186610 vm-systemduser9 systemd[5755]: Reached target Exit the Session. Mar 26 07:44:04.188297 vm-systemduser9 systemd[1]: user@1000.service: Deactivated successfully. Mar 26 07:44:04.188377 vm-systemduser9 systemd[1]: Stopped User Manager for UID 1000. Mar 26 07:44:04.189302 vm-systemduser9 systemd[1]: Starting User Manager for UID 1000... Mar 26 07:44:04.190066 vm-systemduser9 systemd[5776]: user@1000.service: Failed to attach to cgroup /user.slice/user-1000.slice/user@1000.service: Device or resource busy Mar 26 07:44:04.190083 vm-systemduser9 systemd[5776]: user@1000.service: Failed at step CGROUP spawning /usr/lib/systemd/systemd: Device or resource busy Mar 26 07:44:04.190296 vm-systemduser9 systemd[1]: user@1000.service: Main process exited, code=exited, status=219/CGROUP Mar 26 07:44:04.190390 vm-systemduser9 systemd[1]: user@1000.service: Failed with result 'exit-code'. Mar 26 07:44:04.190605 vm-systemduser9 systemd[1]: Failed to start User Manager for UID 1000.
As soon as I strace PID 1, I cannot reproduce, which seems to indicate some kind of race between stopping systemd --user and starting by PID 1 of the instance.
Using an audit rule to track modifications of the cgroup hierarchy (auditctl -w /sys/fs/cgroup/user.slice/user-1000.slice -p wa -k USER), I was able to find out that stopping systemd --user instance (here above PID 5755) cannot delete the init.scope node:
type=PROCTITLE msg=audit(03/26/2024 07:44:04.186:515) : proctitle=(systemd) type=PATH msg=audit(03/26/2024 07:44:04.186:515) : item=1 name=init.scope inode=9598 dev=00:19 mode=dir,755 ouid=user ogid=user rdev=00:00 obj=unconfined_u:object_r:cgroup_t:s0 nametype=DELETE cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 type=PATH msg=audit(03/26/2024 07:44:04.186:515) : item=0 name=/ inode=9563 dev=00:19 mode=dir,755 ouid=user ogid=user rdev=00:00 obj=system_u:object_r:cgroup_t:s0 nametype=PARENT cap_fp=none cap_fi=none cap_fe=0 cap_fver=0 cap_frootid=0 type=CWD msg=audit(03/26/2024 07:44:04.186:515) : cwd=/ type=SYSCALL msg=audit(03/26/2024 07:44:04.186:515) : arch=x86_64 syscall=unlinkat success=no exit=EBUSY(Device or resource busy) a0=0x9 a1=0x55b4d3d97d0b a2=0x200 a3=0x1000 items=2 ppid=1 pid=5755 auid=user uid=user gid=user euid=user suid=user fsuid=user egid=user sgid=user fsgid=user tty=(none) ses=32 comm=systemd exe=/usr/lib/systemd/systemd subj=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 key=USER
Please provide the package NVR for which bug is seen:
systemd-252
How reproducible:
Often
Steps to reproduce
- Login as a user to have the systemd --user instance spawned
- As root, restart user@UID.service unit
Expected results
Restarts successfully 100% of the time.
Actual results
Fails maybe half of the time or even more.