Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boo#1213156: systemd-xdg-autostart-generator cannot start several existing desktop files in Leap 15.5 #79

Open
wants to merge 5 commits into
base: SLE15-SP4
Choose a base branch
from

Conversation

ftake
Copy link
Contributor

@ftake ftake commented Jul 9, 2023

Back ports a series of patches to resolve xdg-autostart-generator cannot start some desktop files derived from 15.4 (boo#1213156)

unusual-thoughts and others added 4 commits July 3, 2023 23:23
This introduces `ExitType=main|cgroup` for services.
Similar to how `Type` specifies the launch of a service, `ExitType` is
concerned with how systemd determines that a service exited.

- If set to `main` (the current behavior), the service manager will consider
  the unit stopped when the main process exits.

- The `cgroup` exit type is meant for applications whose forking model is not
  known ahead of time and which might not have a specific main process.
  The service will stay running as long as at least one process in the cgroup
  is running. This is intended for transient or automatically generated
  services, such as graphical applications inside of a desktop environment.

Motivation for this is #16805. The original PR (#18782) was reverted (#20073)
after realizing that the exit status of "the last process in the cgroup" can't
reliably be known (#19385)

This version instead uses the main process exit status if there is one and just
listens to the cgroup empty event otherwise.

The advantages of a service with `ExitType=cgroup` over scopes are:
- Integrated logging / stdout redirection
- Avoids the race / synchronisation issue between launch and scope creation
- More extensive use of drop-ins and thus distro-level configuration:
  by moving from scopes to services we can have drop ins that will affect
  properties that can only be set during service creation,
  like `OOMPolicy` and security-related properties
- It makes systemd-xdg-autostart-generator usable by fixing [1], as obviously
  only services can be used in the generator, not scopes.

[1] https://bugs.kde.org/show_bug.cgi?id=433299
This fixes a bug[1] with some generated autostart app services which
fork and exit immediately after main application process start,
that caused them not to launch during session startup, as the entire
cgroup was immediately killed by systemd.

This can also happen with apps such as file browsers, whose initial
process will exit after the window is closed, but who intend to leave a
daemon child running.

Since the forking model of a .desktop application cannot be known at
service generation time otherwise, ExitType=cgroup is the only effective
way to fix this bug.

[1] https://bugs.kde.org/show_bug.cgi?id=433299
…esktops

Autostart files which contain the line gnome-autostart-phase are currently
completely skipped by systemd. This is because these are handled internally by
gnome startup through other means.

The problem is a number of desktop files that need to run on KDE too have this
flag set. Ideally they should just create systemd user units, but we're not at
this point universally yet.

This patch changes the logic so if the flag is set, we set NotShowIn-gnome,
which in turn would just not load decided at runtime.

As an optimisation if we would get conflicting OnlyShowIn lines we still
skip the file completely.

Example:
  $ rg 'Exec|Autostart-Phase' /etc/xdg/autostart/gnome-keyring-pkcs11.desktop
  Exec=/usr/bin/gnome-keyring-daemon --start --components=pkcs11
  X-GNOME-Autostart-Phase=PreDisplayServer

  $ cat '/tmp/xxx/app-gnome\x2dkeyring\[email protected]'
  [Unit]
  SourcePath=/etc/xdg/autostart/gnome-keyring-pkcs11.desktop
  ...
  [Service]
  ...
  ExecCondition=/usr/lib/systemd/systemd-xdg-autostart-condition "Unity:MATE" "GNOME"

Co-authored-by: Zbigniew Jędrzejewski-Szmek <[email protected]>
The current start + stop timeouts for xdg autostart files are *very*
short with 5s. On a busy system this might be too easy to hit even in
unintended case.

Apparently, the intention here was to cut the shutdown logic short.
(systemd/systemd#27919 (comment))
Let's hence stick to the very short timeout for that (under the
assumption that apps are written in a safe enough style to not lose data
if killed too early). But for starting XGD autostrat services, use our
regular timeouts.

See: #27919
@ftake
Copy link
Contributor Author

ftake commented Jul 9, 2023

waiting "core: fix race condition during startup of a service with ExitType=cgroup" is merged
systemd/systemd#28314

…roup

This commit allows service_sigchld_event() is executed before
service_dispatch_exec_io(), which might happen when a main process exits
very quickly.

Also do not check PID for service goodness because the main process have
already been exited in this case.

Fix: #27919
@ftake ftake changed the title WIP: boo#1213156: systemd-xdg-autostart-generator cannot start several existing desktop files in Leap 15.5 boo#1213156: systemd-xdg-autostart-generator cannot start several existing desktop files in Leap 15.5 Jul 14, 2023
@ftake ftake marked this pull request as ready for review July 14, 2023 15:00
@fbuihuu
Copy link
Collaborator

fbuihuu commented Jul 17, 2023

The target branch should be SUSE/v249. SLE15-SP4 contains the common stuff shared by all distros based on v249 (ie what's in SUSE/v249) plus changes that are really specific to SLE.

Also the upstream commits should be backported with git cherry-pick -x so the reference of the upstream commit is amended in the commit message. IOW they should contain the string "(cherry picked from commit xxx)".

If you get conflict when cherry-picking the upstream commits, please explain succinctly what you did and why. For trivial context adaptions, "adjust context" is fine. Please have a look at how this is formatted in the other commits.

@fbuihuu
Copy link
Collaborator

fbuihuu commented Jul 17, 2023

That said we're still considering whether it's safe to backport this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants