Slide 1

Slide 1 text

2023-11-21 1/17 A journey to resolve the xdg-autostart-generator issue TAKEYAMA, Fuminobu 武山 文信

Slide 2

Slide 2 text

2023-11-21 2/17 The xdg-autostart-generator issue? ● In Jul., 2022, I received a report that IBus does not work under Tumbleweed – ibus-daemon did not start after login at all – No changes in IBus side – Only under KDE environment ● KDE Plasma just started to use xdg-autostart-generator for XDG Autostart ● Also affects other applications – fcitx, pkcs11-register, spice-vdagent, dropbox, ... https://bugzilla.opensuse.org/show_bug.cgi?id=1201421

Slide 3

Slide 3 text

2023-11-21 3/17 XDG Autostart ● A mechanism to start applications automatically after desktop login ● Applications specified in *.desktop files in – /etc/xdg/autostart – ~/.config/autostart ● Each desktop environment launches those application

Slide 4

Slide 4 text

2023-11-21 4/17 systemd-xdg-autostart-generator ● A new mechanism/implementation for XDG autostart ● Start applications by using Systemd as user services ● How? Convert *.desktop files dynamically to *.service files – /var/run/${uid}/systemd/generator.late/app-${name}@autostart.service

Slide 5

Slide 5 text

2023-11-21 5/17 An example of an auto-generated service file # Automatically generated by systemd-xdg-autostart-generator [Unit] Documentation=man:systemd-xdg-autostart-generator(8) SourcePath=/etc/xdg/autostart/ibus-autostart.desktop PartOf=graphical-session.target Description=IBus After=graphical-session.target [Service] Type=exec ExecStart=:/usr/bin/ibus-autostart Restart=no TimeoutSec=5s Slice=app.slice [Desktop Entry] Name=IBus GenericName=IBus Daemon Comment=Start IBus daemon Exec=ibus-autostart Icon=ibus-setup Terminal=false Type=Application StartupNotify=false NoDisplay=true X-KDE-autostart-after=panel X-KDE-StartupNotify=false ibus-autostart.desktop app-ibus\\[email protected] Convert dynamically

Slide 6

Slide 6 text

2023-11-21 6/17 Let’s back to the problem ● The generated service file looks fine but it does not work ● Two sub-problems 1. systemd-xdg-autostart-generator ignores/skips desktop files containing X-GNOME-Autostart-Phase key • A service file for IBus was not generated at all 2. Daemonized applications are soon killed by Systemd • Encountered after fixing the 1st problem

Slide 7

Slide 7 text

2023-11-21 7/17 (1) X-GNOME-Autostart-Phase ● Systemd ignored desktop files with X-G-A-P because such desktop files should be handled by GNOME – And expected to be unnecessary under the other DEs – Even though they are necessary for DEs other than GNOME ● Solutions – openSUSE side: ● removed unnecessary X-GNOME-Autostart-Phase from packages ● migrated from a XDG autostart desktop to a native Systemd service – Upstream side: ● check the current DE before starting a service by ExecCondition=/usr/lib/systemd/systemd-xdg-autostart-condition ● Do not skip desktop files anymore

Slide 8

Slide 8 text

2023-11-21 8/17 (2) Daemonized applications are soon killed by Systemd ● Daemonized (or forking) – Applications running background – A main process exits soon but their sub processes keep running $ ibus-daemon --daemonize # the main process exits soon after forking $ # but its children keep running in background

Slide 9

Slide 9 text

2023-11-21 9/17 Type=exec to cgroup ● When the main process of a service exits, Systemd stop the service if Type=exec – Systemd kills all the remaining processes of the stopped service ● So Type=exec cannot be used for daemonized applications because the main process exits soon ● Solution: ExitType=cgroup – The upstream introduced a new ExitType – A service exit when all the process (in the cgroup) of the service exits [Service] Type=exec ExecStart=:/usr/bin/ibus-autostart [Service] Type=exec ExitType=cgroup ExecStart=:/usr/bin/ibus-autostart Note: Type=forking cannot be applied for every applications in XDG autostart Type=simple might be enough, but I’m not sure why not

Slide 10

Slide 10 text

2023-11-21 10/17 State machine (ExitType=main) RUNNING SIGCHLD The main process exited. START DEAD FDs for output of the main process is opened. systemctl start Start the main process of service

Slide 11

Slide 11 text

2023-11-21 11/17 State machine (ExitType=cgroup) cgroup empty (all the process of a service exited) RUNNING SIGCHLD The main process exited. START DEAD FDs for output of the main process is opened. systemctl start Start the main process of service

Slide 12

Slide 12 text

2023-11-21 12/17 It still does not work ● IBus is soon killed due to timeout – It’s state does not change from START to RUNNING – It seems that Systemd cannot detect IBus has started successfully ● Race condition – systemd-xdg-autostart-generator terminating process a bit too eagerly? #27919 https://github.com/systemd/systemd/issues/27919

Slide 13

Slide 13 text

2023-11-21 13/17 What was happening? cgroup empty (all the process of a service exited) RUNNING SIGCHLD The main process exited. START DEAD FDs for output of the main process is opened. systemctl start undefined SIGCHLD The main process exited.

Slide 14

Slide 14 text

2023-11-21 14/17 Writing a patch ● Why SIGCHLD happens during the RUNNING state? – It’s signal – While an event that the main process has started in a queue, Systemd might catch the signal – If the application exits very quickly ● I wrote a patch and submitted to the upstream

Slide 15

Slide 15 text

2023-11-21 15/17 The last version (ExitType=cgroup) cgroup empty (all the process of a service exited) RUNNING SIGCHLD The main process exited. START DEAD FDs for output of the main process is opened. systemctl start OR SIGCHLD The main process exited.

Slide 16

Slide 16 text

2023-11-21 16/17 The current status in openSUSE ● Does this problem still reproduce even on Leap 15.5? – Yes – A workaround to disable systemd-xdg-autostart-generator $ kwriteconfig5 --file startkderc --group General --key systemdBoot false – Uses old Systemd and cannot import a new feature to resolve this issue – KDE maintainer would not roll back to the former mechanism ● Already fixed in Tumbleweed (with Systemd v254) – Still need test systemd-xdg-autostart-generator carefully https://bugzilla.opensuse.org/show_bug.cgi?id=1213156

Slide 17

Slide 17 text

2023-11-21 17/17 Conclusion ● KDE Plasma now uses systemd-xdg-autostart-generator for XDG autostart ● It did not work if a service has – X-GNOME-Autostart-Phase – A main process that forks child processes and exit soon ● This problem have been resolved in Tumbleweed but not in Leap 15.5 – The patch has been already merged by the upstream