Skip to content

Commit f2da19b

Browse files
committed
subprocess_launcher: Take owned fds
1 parent 0ece903 commit f2da19b

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

gio/src/subprocess_launcher.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
#[cfg(any(unix, all(docsrs, unix)))]
4-
use std::os::unix::io::IntoRawFd;
4+
use std::os::unix::io::{AsFd, AsRawFd, IntoRawFd, OwnedFd};
55

66
#[cfg(unix)]
77
use glib::translate::*;
@@ -22,40 +22,41 @@ impl SubprocessLauncher {
2222
#[cfg(unix)]
2323
#[cfg_attr(docsrs, doc(cfg(unix)))]
2424
#[doc(alias = "g_subprocess_launcher_take_fd")]
25-
pub fn take_fd(&self, source_fd: impl IntoRawFd, target_fd: impl IntoRawFd) {
25+
pub fn take_fd(&self, source_fd: OwnedFd, target_fd: impl AsFd) {
26+
let source_raw_fd = source_fd.into_raw_fd();
27+
let target_raw_fd = target_fd.as_fd().as_raw_fd();
2628
unsafe {
27-
ffi::g_subprocess_launcher_take_fd(
28-
self.to_glib_none().0,
29-
source_fd.into_raw_fd(),
30-
target_fd.into_raw_fd(),
31-
);
29+
ffi::g_subprocess_launcher_take_fd(self.to_glib_none().0, source_raw_fd, target_raw_fd);
3230
}
3331
}
3432

3533
#[cfg(unix)]
3634
#[cfg_attr(docsrs, doc(cfg(unix)))]
3735
#[doc(alias = "g_subprocess_launcher_take_stderr_fd")]
38-
pub fn take_stderr_fd(&self, fd: impl IntoRawFd) {
36+
pub fn take_stderr_fd(&self, fd: Option<OwnedFd>) {
3937
unsafe {
40-
ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, fd.into_raw_fd());
38+
let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
39+
ffi::g_subprocess_launcher_take_stderr_fd(self.to_glib_none().0, raw_fd);
4140
}
4241
}
4342

4443
#[cfg(unix)]
4544
#[cfg_attr(docsrs, doc(cfg(unix)))]
4645
#[doc(alias = "g_subprocess_launcher_take_stdin_fd")]
47-
pub fn take_stdin_fd(&self, fd: impl IntoRawFd) {
46+
pub fn take_stdin_fd(&self, fd: Option<OwnedFd>) {
47+
let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
4848
unsafe {
49-
ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, fd.into_raw_fd());
49+
ffi::g_subprocess_launcher_take_stdin_fd(self.to_glib_none().0, raw_fd);
5050
}
5151
}
5252

5353
#[cfg(unix)]
5454
#[cfg_attr(docsrs, doc(cfg(unix)))]
5555
#[doc(alias = "g_subprocess_launcher_take_stdout_fd")]
56-
pub fn take_stdout_fd(&self, fd: impl IntoRawFd) {
56+
pub fn take_stdout_fd(&self, fd: Option<OwnedFd>) {
57+
let raw_fd = fd.map_or(-1, |fd| fd.into_raw_fd());
5758
unsafe {
58-
ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, fd.into_raw_fd());
59+
ffi::g_subprocess_launcher_take_stdout_fd(self.to_glib_none().0, raw_fd);
5960
}
6061
}
6162
}

0 commit comments

Comments
 (0)