flathub / org.kde.okular

https://flathub.org/apps/details/org.kde.okular
6 stars 13 forks source link

Flathub's Okular should use non-PID identifier on D-Bus or share a PID namespace for all instances #374

Open nihil-admirari opened 2 days ago

nihil-admirari commented 2 days ago

I've investigated https://github.com/flathub/org.kde.okular/issues/36, but couldn't comment.

Okular doesn't own org.kde.okular (unless started as -unique), rather it owns org.kde.okular-PID: https://github.com/KDE/okular/blob/master/shell/okular_main.cpp#L104. When opening a file, it scans for already existing org.kde.okular-NOT_MY_PID buses and then tries to attach to them.

The problem is that in Flatpak all PIDs are sandboxed, which can be verified by running

flatpak run --command=bash org.kde.okular -c 'echo "$$" && read tmp'

simultaneously in two terminals (both will print the PID of 2). Since Okular always gets a PID of 2, and since it always filters out buses with its own PID, it never finds a previous instance and always starts a new one.

There are two possible solutions that I can think of. The first one is to replace PID with e.g. a static QUuid in https://github.com/KDE/okular/blob/master/shell/shell.cpp#L292 and https://github.com/KDE/okular/blob/master/shell/okular_main.cpp#L104.

The second one relies on Flatpak's --parent-pid and --parent-share-pids: https://docs.flatpak.org/en/latest/flatpak-command-reference.html. When starting Okular in a Flatpak, an already running Flatpak instance should be detected and its PID passed to flatpak run of the new instance. I've no idea how it can be implemented in practice. I've tested it by running multiple Okular's in the PID namespace of init, but that kinda defeats the entire point of sandboxing:

flatpak run --parent-pid=1 --parent-share-pids org.kde.okular --command=okular ...

Also, Flatpak doesn't allow wildcard D-Bus permissions (https://docs.flatpak.org/en/latest/sandbox-permissions.html) unless it's a subname, and Okular's D-Bus name is not a subname. The entire session D-Bus needs to be exposed.

travier commented 2 days ago

Maybe we can use org.kde.okular.* instead?

nihil-admirari commented 1 day ago

Did that in https://github.com/flathub/org.kde.okular/pull/375. Now it uses org.kde.okular.Instance_ + hex representation of a UUID for D-Bus names.