dbus2 / zbus-old

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

FD closed before I can use it #226

Closed zeenix closed 1 year ago

zeenix commented 2 years ago

In GitLab by @wezm on Oct 26, 2021, 24:48

zbus version: 2.0.0-beta.7
Rust version: rustc 1.56.0 (09c42c458 2021-10-18)
Kernel version: 5.14.12-arch1-1
D-Bus version: 1.12.20-1
Udisks2 version: 2.9.4-1

I'm using zbus to talk to UDisks2. I used zbus_xmlgen to generate a proxy for the Block interface. I'm calling the OpenDevice method and getting back an fd, however attempting to use the fd always gives a Bad file descriptor error. In strace I can see that it appears to be closed immediately.

I saw the note on Message but I'm not sure how to do that with a generated proxy.

My code:

    fn open_device_udisks(
        connection: &Connection,
        object_path: Option<&OwnedObjectPath>,
    ) -> Result<File, PlatformError> {
        let object_path = object_path.unwrap(); // FIXME: Restructure things so this isn't an Option

        let block_dev = BlockProxyBlocking::builder(&connection)
            .path(object_path)?
            .build()?;

        let options = HashMap::from([("flags", Value::from(libc::O_DIRECT))]);
        let fd = block_dev.open_device("rw", options)?;

        // NOTE(unsafe): Probably safe as we trust the value we got from from UDisks2/zbus/D-Bus
        let file = unsafe { File::from_raw_fd(fd.as_raw_fd()) };
        dbg!(file.metadata());
        Ok(file)
    }
}

The generated proxy:

//! # DBus interface proxies for: `org.freedesktop.UDisks2.Block`
//!
//! This code was generated by `zbus-xmlgen` `2.0.0-beta.7` from DBus introspection data.
//! Source: `Interface '/org/freedesktop/UDisks2/block_devices/sdd' from service 'org.freedesktop.UDisks2' on system bus`.
//!
//! You may prefer to adapt it, instead of using it verbatim.
//!
//! More information can be found in the
//! [Writing a client proxy](https://dbus.pages.freedesktop.org/zbus/client.html)
//! section of the zbus documentation.
//!
//! This DBus object implements
//! [standard DBus interfaces](https://dbus.freedesktop.org/doc/dbus-specification.html),
//! (`org.freedesktop.DBus.*`) for which the following zbus proxies can be used:
//!
//! * [`zbus::fdo::PropertiesProxy`]
//! * [`zbus::fdo::IntrospectableProxy`]
//! * [`zbus::fdo::PeerProxy`]
//!
//! …consequently `zbus-xmlgen` did not generate code for the above interfaces.

use zbus::dbus_proxy;

#[dbus_proxy(
    interface = "org.freedesktop.UDisks2.Block",
    default_service = "org.freedesktop.UDisks2"
)]
trait Block {
    /// AddConfigurationItem method
    fn add_configuration_item(
        &self,
        item: &(
            &str,
            std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
        ),
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<()>;

    /// Format method
    fn format(
        &self,
        type_: &str,
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<()>;

    /// GetSecretConfiguration method
    fn get_secret_configuration(
        &self,
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<
        Vec<(
            String,
            std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
        )>,
    >;

    /// OpenDevice method
    fn open_device(
        &self,
        mode: &str,
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<zbus::zvariant::Fd>;

    /// OpenForBackup method
    fn open_for_backup(
        &self,
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<zbus::zvariant::Fd>;

    /// OpenForBenchmark method
    fn open_for_benchmark(
        &self,
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<zbus::zvariant::Fd>;

    /// OpenForRestore method
    fn open_for_restore(
        &self,
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<zbus::zvariant::Fd>;

    /// RemoveConfigurationItem method
    fn remove_configuration_item(
        &self,
        item: &(
            &str,
            std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
        ),
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<()>;

    /// Rescan method
    fn rescan(
        &self,
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<()>;

    /// UpdateConfigurationItem method
    fn update_configuration_item(
        &self,
        old_item: &(
            &str,
            std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
        ),
        new_item: &(
            &str,
            std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
        ),
        options: std::collections::HashMap<&str, zbus::zvariant::Value<'_>>,
    ) -> zbus::Result<()>;

    /// Configuration property
    #[dbus_proxy(property)]
    fn configuration(
        &self,
    ) -> zbus::Result<
        Vec<(
            String,
            std::collections::HashMap<String, zbus::zvariant::OwnedValue>,
        )>,
    >;

    /// CryptoBackingDevice property
    #[dbus_proxy(property)]
    fn crypto_backing_device(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;

    /// Device property
    #[dbus_proxy(property)]
    fn device(&self) -> zbus::Result<Vec<u8>>;

    /// DeviceNumber property
    #[dbus_proxy(property)]
    fn device_number(&self) -> zbus::Result<u64>;

    /// Drive property
    #[dbus_proxy(property)]
    fn drive(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;

    /// HintAuto property
    #[dbus_proxy(property)]
    fn hint_auto(&self) -> zbus::Result<bool>;

    /// HintIconName property
    #[dbus_proxy(property)]
    fn hint_icon_name(&self) -> zbus::Result<String>;

    /// HintIgnore property
    #[dbus_proxy(property)]
    fn hint_ignore(&self) -> zbus::Result<bool>;

    /// HintName property
    #[dbus_proxy(property)]
    fn hint_name(&self) -> zbus::Result<String>;

    /// HintPartitionable property
    #[dbus_proxy(property)]
    fn hint_partitionable(&self) -> zbus::Result<bool>;

    /// HintSymbolicIconName property
    #[dbus_proxy(property)]
    fn hint_symbolic_icon_name(&self) -> zbus::Result<String>;

    /// HintSystem property
    #[dbus_proxy(property)]
    fn hint_system(&self) -> zbus::Result<bool>;

    /// Id property
    #[dbus_proxy(property)]
    fn id(&self) -> zbus::Result<String>;

    /// IdLabel property
    #[dbus_proxy(property)]
    fn id_label(&self) -> zbus::Result<String>;

    /// IdType property
    #[dbus_proxy(property)]
    fn id_type(&self) -> zbus::Result<String>;

    /// IdUUID property
    #[dbus_proxy(property)]
    fn id_uuid(&self) -> zbus::Result<String>;

    /// IdUsage property
    #[dbus_proxy(property)]
    fn id_usage(&self) -> zbus::Result<String>;

    /// IdVersion property
    #[dbus_proxy(property)]
    fn id_version(&self) -> zbus::Result<String>;

    /// MDRaid property
    #[dbus_proxy(property)]
    fn mdraid(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;

    /// MDRaidMember property
    #[dbus_proxy(property)]
    fn mdraid_member(&self) -> zbus::Result<zbus::zvariant::OwnedObjectPath>;

    /// PreferredDevice property
    #[dbus_proxy(property)]
    fn preferred_device(&self) -> zbus::Result<Vec<u8>>;

    /// ReadOnly property
    #[dbus_proxy(property)]
    fn read_only(&self) -> zbus::Result<bool>;

    /// Size property
    #[dbus_proxy(property)]
    fn size(&self) -> zbus::Result<u64>;

    /// Symlinks property
    #[dbus_proxy(property)]
    fn symlinks(&self) -> zbus::Result<Vec<Vec<u8>>>;

    /// UserspaceMountOptions property
    #[dbus_proxy(property)]
    fn userspace_mount_options(&self) -> zbus::Result<Vec<String>>;
}

strace, note close(8) immediately before statx(8) and generation of the error message:

read(5, 0x7ffc1aaa76a0, 8)              = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x7f41ac000cbc, FUTEX_WAKE_PRIVATE, 1) = 1
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=4294967295, u64=18446744073709551615}}], 1000, -1) = 1
read(5, "\1\0\0\0\0\0\0\0", 8)          = 8
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x563873783f3c, FUTEX_WAKE_PRIVATE, 1) = 1
sendmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\1\0\1$\0\0\0\265\0\0\0\264\0\0\0\1\1o\0*\0\0\0/org/fre"..., iov_len=236}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 236
futex(0x56387379e088, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=4294967295, u64=18446744073709551615}}], 1000, -1) = 1
read(5, "\1\0\0\0\0\0\0\0", 8)          = 8
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=0, u64=0}}], 1000, -1) = 1
read(5, 0x7ffc1aaa70c0, 8)              = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x7f41ac000cb8, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x563873783f38, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x56387379e08c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x563873797950, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x563873797950, FUTEX_WAKE_PRIVATE, 1) = 0
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=0, u64=0}}], 1000, -1) = 1
read(5, 0x7ffc1aaa70c0, 8)              = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x7f41ac000cbc, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x563873783f3c, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x56387379e088, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x563873797950, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x563873797950, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x563873783eb0, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x563873783eb0, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x563873783eb0, FUTEX_WAKE_PRIVATE, 1) = 0read(5, 0x7ffc1aaa76a0, 8)              = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x7f41ac000cbc, FUTEX_WAKE_PRIVATE, 1) = 1
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=4294967295, u64=18446744073709551615}}], 1000, -1) = 1
read(5, "\1\0\0\0\0\0\0\0", 8)          = 8
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x563873783f3c, FUTEX_WAKE_PRIVATE, 1) = 1
sendmsg(3, {msg_name=NULL, msg_namelen=0, msg_iov=[{iov_base="l\1\0\1$\0\0\0\265\0\0\0\264\0\0\0\1\1o\0*\0\0\0/org/fre"..., iov_len=236}], msg_iovlen=1, msg_controllen=0, msg_flags=0}, 0) = 236
futex(0x56387379e088, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=4294967295, u64=18446744073709551615}}], 1000, -1) = 1
read(5, "\1\0\0\0\0\0\0\0", 8)          = 8
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=0, u64=0}}], 1000, -1) = 1
read(5, 0x7ffc1aaa70c0, 8)              = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x7f41ac000cb8, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x563873783f38, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x56387379e08c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x563873797950, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x563873797950, FUTEX_WAKE_PRIVATE, 1) = 0
timerfd_settime(6, 0, {it_interval={tv_sec=0, tv_nsec=0}, it_value={tv_sec=0, tv_nsec=0}}, NULL) = 0
epoll_ctl(4, EPOLL_CTL_MOD, 6, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
epoll_wait(4, [{events=EPOLLIN, data={u32=0, u64=0}}], 1000, -1) = 1
read(5, 0x7ffc1aaa70c0, 8)              = -1 EAGAIN (Resource temporarily unavailable)
epoll_ctl(4, EPOLL_CTL_MOD, 5, {events=EPOLLIN|EPOLLPRI|EPOLLERR|EPOLLHUP|EPOLLRDHUP|EPOLLONESHOT, data={u32=4294967295, u64=18446744073709551615}}) = 0
futex(0x7f41ac000cbc, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x563873783f3c, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x56387379e088, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x563873797950, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x563873797950, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x563873783eb0, FUTEX_WAKE_PRIVATE, 1) = 1
futex(0x563873783eb0, FUTEX_WAIT_PRIVATE, 2, NULL) = -1 EAGAIN (Resource temporarily unavailable)
futex(0x563873783eb0, FUTEX_WAKE_PRIVATE, 1) = 0
futex(0x56387379e08c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
close(8)                                = 0
statx(8, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, 0x7ffc1aaa87d0) = -1 EBADF (Bad file descriptor)
write(2, "[", 1[)                        = 1
write(2, "inscribe/src/platform/linux.rs", 30inscribe/src/platform/linux.rs) = 30
write(2, ":", 1:)                        = 1
write(2, "287", 3287)                      = 3
write(2, "] ", 2] )                       = 2
write(2, "file.metadata()", 15file.metadata())         = 15
write(2, " = ", 3 = )                      = 3
write(2, "Err", 3Err)                      = 3
write(2, "(\n", 2(
)                      = 2
write(2, "    ", 4    )                     = 4
write(2, "Os", 2Os)                       = 2
write(2, " {\n", 3 {
)                     = 3
write(2, "    ", 4    )                     = 4
write(2, "    ", 4    )                     = 4
write(2, "code", 4code)                     = 4
write(2, ": ", 2: )                       = 2
write(2, "9", 19)                        = 1
write(2, ",\n", 2,
)                      = 2
write(2, "    ", 4    )                     = 4
write(2, "    ", 4    )                     = 4
write(2, "kind", 4kind)                     = 4
write(2, ": ", 2: )                       = 2
write(2, "Uncategorized", 13Uncategorized)           = 13
write(2, ",\n", 2,
)                      = 2
write(2, "    ", 4    )                     = 4
write(2, "    ", 4    )                     = 4
write(2, "message", 7message)                  = 7
write(2, ": ", 2: )                       = 2
write(2, "\"", 1")                       = 1
write(2, "Bad file descriptor", 19Bad file descriptor)     = 19

futex(0x56387379e08c, FUTEX_WAIT_BITSET_PRIVATE|FUTEX_CLOCK_REALTIME, 0, NULL, FUTEX_BITSET_MATCH_ANY) = 0
futex(0x56387379d5f0, FUTEX_WAKE_PRIVATE, 1) = 0
close(8)                                = 0
statx(8, "", AT_STATX_SYNC_AS_STAT|AT_EMPTY_PATH, STATX_ALL, 0x7ffc1aaa87d0) = -1 EBADF (Bad file descriptor)
write(2, "[", 1[)                        = 1
write(2, "inscribe/src/platform/linux.rs", 30inscribe/src/platform/linux.rs) = 30
write(2, ":", 1:)                        = 1
write(2, "287", 3287)                      = 3
write(2, "] ", 2] )                       = 2
write(2, "file.metadata()", 15file.metadata())         = 15
write(2, " = ", 3 = )                      = 3
write(2, "Err", 3Err)                      = 3
write(2, "(\n", 2(
)                      = 2
write(2, "    ", 4    )                     = 4
write(2, "Os", 2Os)                       = 2
write(2, " {\n", 3 {
)                     = 3
write(2, "    ", 4    )                     = 4
write(2, "    ", 4    )                     = 4
write(2, "code", 4code)                     = 4
write(2, ": ", 2: )                       = 2
write(2, "9", 19)                        = 1
write(2, ",\n", 2,
)                      = 2
write(2, "    ", 4    )                     = 4
write(2, "    ", 4    )                     = 4
write(2, "kind", 4kind)                     = 4
write(2, ": ", 2: )                       = 2
write(2, "Uncategorized", 13Uncategorized)           = 13
write(2, ",\n", 2,
)                      = 2
write(2, "    ", 4    )                     = 4
write(2, "    ", 4    )                     = 4
write(2, "message", 7message)                  = 7
write(2, ": ", 2: )                       = 2
write(2, "\"", 1")                       = 1
write(2, "Bad file descriptor", 19Bad file descriptor)     = 19
zeenix commented 2 years ago

In GitLab by @elmarco on Oct 26, 2021, 10:55

Hi @wezm, by default zbus will keep ownership of returned message FDs.

There are a few ways this can be solved (to avoid extra dup() if necessary), but the most straightforward is to return an OwnedFd, and call into_raw_fd(). We should probably update xmlgen to return OwnedFd by default.

zeenix commented 2 years ago

In GitLab by @wezm on Oct 26, 2021, 12:51

Ahh thank you. I had actually tried OwnedFd previously and still had issues. into_raw_fd vs. as_raw_fd was the bit I was missing. Feel free to close this issue.

Update: I am curious about this if you can spare the time, but it's certainly not super important:

There are a few ways this can be solved (to avoid extra dup() if necessary)

zeenix commented 2 years ago

We should probably update xmlgen to return OwnedFd by default.

This part was taken care of by !412. So close this.