dbus2 / zbus-old

Rust D-Bus crate.
https://gitlab.freedesktop.org/dbus/zbus
Other
49 stars 13 forks source link

Session bus usage to talk to systemd fails on Ubuntu #253

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 17:35

Here is error details

MethodError(OwnedErrorName(ErrorName(Str(Owned("org.freedesktop.DBus.Error.Spawn.ChildExited")))), Some("Process org.freedesktop.systemd1 exited with status 1"), Msg { type: Error, sender: UniqueName(Str(Borrowed("org.freedesktop.DBus"))), reply-serial: 2, body: Signature: [
        s (115),
] })

same method working for blocking proxy though, need help ...

zeenix commented 2 years ago

I can't tell much w/o looking at your code but the error indicates a problem on the service side: the process you're talking to is exiting for some reason.

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 18:10

server side is systemd, it's running properly

zeenix commented 2 years ago

That's the only indication from the error. I can't help much w/o more information. Can you share your proxy code?

zeenix commented 2 years ago

Best if you could create a complete small reproducer so I can just run it on my machine and be able to debug what's going on.

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 18:37

#[zbus::dbus_proxy(
    interface = "org.freedesktop.systemd1.Manager",
    default_service = "org.freedesktop.systemd1",
    default_path = "/org/freedesktop/systemd1"
)]
trait SystemdManager {
    fn list_units(&self) -> zbus::Result<Vec<(String, String, String, String, String, String, zvariant::OwnedObjectPath, u32, String, zvariant::OwnedObjectPath)>>;
}
zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 18:38

that's the only function I am testing now ... - list_units it works for blocking proxy, but failed for nonblock one

zeenix commented 2 years ago

I ran this here and it seems to work perfectly fine here:

use zbus::{dbus_proxy, zvariant::OwnedObjectPath, Connection, Result};

#[dbus_proxy(
    interface = "org.freedesktop.systemd1.Manager",
    default_service = "org.freedesktop.systemd1",
    default_path = "/org/freedesktop/systemd1"
)]
trait SystemdManager {
    fn list_units(&self) -> zbus::Result<Vec<(String, String, String, String, String, String, OwnedObjectPath, u32, String, OwnedObjectPath)>>;
}

#[tokio::main]
async fn main() -> Result<()> {
    let connection = Connection::session().await?;

    let units = SystemdManagerProxy::new(&connection).await?.list_units().await?;
    for unit in units {
        println!("{}", unit.0);
    }

    Ok(())
}

Please make sure you're using the latest zbus release: 2.0.1.

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 19:15

yes, I copy ^^ your code and run with package version

zbus = "2.0.1"
tokio = { version = "1.11.0", features = ["macros", "rt", "rt-multi-thread"] }

os

x86_64 x86_64 GNU/Linux unbuntu

same error ChildExit

zeenix commented 2 years ago

yes, I copy ^^ your code and run with package version

zbus = "2.0.1"
tokio = { version = "1.11.0", features = ["macros", "rt", "rt-multi-thread"] }

I've the same here but tokio version is 1.15.0.

os

x86_64 x86_64 GNU/Linux unbuntu

same error ChildExit

Hmm.. I'm completely stumped then. The error is obviously coming from the bus or service side but given that blocking proxy code works fine is very strange.

zeenix commented 2 years ago

You're not running any of the components involved in a container, are you? That wouldn't explain how the blocking proxy would work, though.

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 19:36

What do you mean by container ? I am running ubuntu with virtualbox

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 19:38

yes, I am sure the blocking proxy works for list_units start/get_unit I have no luck for nonblock proxy with methods ^^

zeenix commented 2 years ago

What happens if you take my code exactly here and just change it to using blocking::Connection and SystemdManagerProxyBlocking? Does that still work (do remember to remote the async and tokio::main from the main function though)?

What do you mean by container ? I am running ubuntu with virtualbox

Nevermind then. :)

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 19:40

yes, when test nonblock, I didn't add tokio::main macro

zeenix commented 2 years ago

yes, when test nonblock, I didn't add tokio::main macro

You mean, you already tried this and it works w/o errors?

use zbus::{dbus_proxy, zvariant::OwnedObjectPath, blocking::Connection, Result};

#[dbus_proxy(
    interface = "org.freedesktop.systemd1.Manager",
    default_service = "org.freedesktop.systemd1",
    default_path = "/org/freedesktop/systemd1"
)]
trait SystemdManager {
    fn list_units(&self) -> zbus::Result<Vec<(String, String, String, String, String, String, OwnedObjectPath, u32, String, OwnedObjectPath)>>;
}

fn main() -> Result<()> {
    let connection = Connection::session()?;

    let units = SystemdManagerProxyBlocking::new(&connection)?.list_units()?;
    for unit in units {
        println!("{}", unit.0);
    }

    Ok(())
}

If so, I'm out of ideas. Maybe upgrading your tokio helps (just a blind guess that's unlike to work but I'm no other ideas anymore).

zeenix commented 2 years ago

For the record, on my Fedora both versions work flawlessly.

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 19:46

  1. correct, same code ^^ for nonblock
  2. tried tokio 1.15, no luck for nonblocking ...
zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 22:23

Oh ... Man, I see why, change

Connection::session()

to

Connection::system()
zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 13, 2022, 22:24

so , what's the difference session vs system ? dbus newbie ...

zeenix commented 2 years ago

weird. That doesn't explain why the blocking code works, at all. Were you using system with the blocking code?

so , what's the difference session vs system ? dbus newbie ...

From our book:

Typically, a Linux system has a system bus, and a session bus. The latter is per-user. It is also possible to have private buses or no bus at all (i-e direct peer-to-peer communication instead).

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 14, 2022, 01:36

yes, for blocking one I was using system

zeenix commented 2 years ago

So you didn't use the code I had provided then. 🤦‍♂️ It would have saved some time if you had. Anyway, glad to hear you got it working.

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 14, 2022, 02:31

actually, your code is using session https://gitlab.freedesktop.org/dbus/zbus/-/issues/243#note_1218819 it doesn't work at least for ubuntu

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 14, 2022, 02:38

And your official doc is using session as well for SystemdManagerProxy https://dbus.pages.freedesktop.org/zbus/client.html#properties

zeenix commented 2 years ago

In GitLab by @li.yu.sh0211 on Jan 14, 2022, 02:39

The problems is no longer block / nonblocking, but session vs system instead :smile:

zeenix commented 2 years ago

Yes, my code was using session in both version but you reported that my blocking code works, while it didn't. Obviously, you didn't try my (blocking) code but assumed it's the same as yours.

Anyway, good that you got it sorted.

As for code sample using session, I will change it to use system. It works fine on Fedora so we never noticed before that it's not working on other distros. Many thanks for reporting!

zeenix commented 2 years ago

mentioned in commit 0e128ec40e65cdc45c74f70bffff11a955443c56