Skip to content

Commit

Permalink
flatpak-integrator: use more sophisticated code to pass around fds
Browse files Browse the repository at this point in the history
the previous approach didn't pass stdout/err properly causing the
host->browser communication to fail while browser->host was working
fine.

BUG: 500000
  • Loading branch information
hsitter committed Feb 16, 2025
1 parent f2aa82e commit 0709617
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions flatpak-integrator/flatpak-host-wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,25 @@

set -eu

args=$(printf \'%s\' "$1"
shift
printf ", '%s'" "$@"
printf '\n')
# This packs $1 and $2 into a single string for gdbus of the form "'$1', '$2'\n"
args=$(printf "'%s', '%s'\n" "$1" "$2")

# The descriptor madness needs some explaining:
# We expect the forked gdbus to pick up three descriptors from us: 3, 4, and 5, respectively presenting our
# stdin, stdout, and stderr. This is because we need our io set to be distinct from gdbus' io set so gdbus doesn't write
# invalid data on the pipes and breaks stuff (e.g. it'd write the return value of the call but that is invalid nonesense to firefox).
#
# 3<&0: dup our input stdin (i.e. 0) to gdbus' fd 3
# 4>&1: dup our output stdout (i.e. 1) to gdbus' fd 4
# 5>&2: dup our output stderr (i.e. 2) to gdbus' fd 5
# 1>/dev/null: redirect gdbus' stdout to /dev/null because we don't care about it
#
# gdbus will then send 3,4,5 into dbus, effectively forwarding our descriptors. We meanwhile ignore their stdout.
gdbus call \
--session \
--dest org.kde.plasma.browser.integration \
--object-path /org/kde/plasma/browser/integration \
--method org.kde.plasma.browser.integration.FlatpakIntegrator.Link \
["$args"] 0 1 2 > /dev/stderr
["$args"] 3 4 5 3<&0 4>&1 5>&2 1>/dev/null

sleep infinity

0 comments on commit 0709617

Please sign in to comment.