Skip to content

Commit

Permalink
💩 zb: Hack to make connection handshake work inside Flatpak
Browse files Browse the repository at this point in the history
xdg-dbus-proxy can't handle pipelining[1], hence we need to handle
`NEGOTIATE_UNIX_FD` command's response before sending out `BEGIN` command
and `Hello` method call message.

We should remote this as soon as flatpak is fixed and fix is available in
major distros.

[1] flatpak/xdg-dbus-proxy#21
  • Loading branch information
zeenix committed May 8, 2024
1 parent d2df7e2 commit b1c97cf
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion zbus/src/connection/handshake/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,22 @@ impl Client {

let can_pass_fd = self.common.socket_mut().read_mut().can_pass_unix_fd();
if can_pass_fd {
commands.push(Command::NegotiateUnixFD);
// xdg-dbus-proxy can't handle pipelining, hence this special handling.
// FIXME: Remote this as soon as flatpak is fixed and fix is available in major distros.
if is_flatpak().await {
self.common.write_command(Command::NegotiateUnixFD).await?;
match self.common.read_command().await? {
Command::AgreeUnixFD => self.common.set_cap_unix_fd(true),
Command::Error(e) => warn!("UNIX file descriptor passing rejected: {e}"),
cmd => {
return Err(Error::Handshake(format!(
"Unexpected command from server: {cmd}"
)))
}
}
} else {
commands.push(Command::NegotiateUnixFD);
}
};
commands.push(Command::Begin);
let hello_method = if self.bus {
Expand Down Expand Up @@ -290,3 +305,16 @@ async fn receive_hello_response(
m => Err(Error::Handshake(format!("Unexpected messgage `{m:?}`"))),
}
}

async fn is_flatpak() -> bool {
#[cfg(unix)]
{
crate::abstractions::file::metadata("/.flatpak-info")
.await
.is_ok()
}
#[cfg(not(unix))]
{
false
}
}

0 comments on commit b1c97cf

Please sign in to comment.