From 550ed754da5aed3367f713f56bfd34ba5a1840b5 Mon Sep 17 00:00:00 2001 From: Grzegorz Jaszczyk Date: Fri, 18 Mar 2022 08:05:30 +0000 Subject: [PATCH] sys_util: netlink: implement AsRawDescriptor for netlink generic socket In order to use netlink generic socket together with WaitContext, AsRawDescriptor needs to be implemented. BUG=b:197247746, b:205072342 TEST=Use NetlinkGenericSocket with WaitContext and successfully use it for threads Change-Id: I99c9d508c86395f104a7a2f17a1726b753c9698b Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3528638 Reviewed-by: Daniel Verkamp Tested-by: kokoro Commit-Queue: Tomasz Nowicki --- common/sys_util/src/netlink.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/sys_util/src/netlink.rs b/common/sys_util/src/netlink.rs index 8db241e02f..b7fb40dfcd 100644 --- a/common/sys_util/src/netlink.rs +++ b/common/sys_util/src/netlink.rs @@ -9,7 +9,9 @@ use libc::EINVAL; use sys_util_core::LayoutAllocation; -use super::{errno_result, Error, FromRawDescriptor, Result, SafeDescriptor}; +use super::{ + errno_result, AsRawDescriptor, Error, FromRawDescriptor, RawDescriptor, Result, SafeDescriptor, +}; // Custom nlmsghdr struct that can be declared DataInit. #[repr(C)] @@ -101,6 +103,12 @@ pub struct NetlinkGenericSocket { sock: SafeDescriptor, } +impl AsRawDescriptor for NetlinkGenericSocket { + fn as_raw_descriptor(&self) -> RawDescriptor { + self.sock.as_raw_descriptor() + } +} + impl NetlinkGenericSocket { /// Create and bind a new `NETLINK_GENERIC` socket. pub fn new(nl_groups: u32) -> Result {