Skip to content

Commit 25b2a7f

Browse files
committed
mount/linux: use at_rawfd helper
1 parent 1bb08fc commit 25b2a7f

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/mount/linux.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use std::os::unix::io::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd};
21
use crate::errno::Errno;
2+
use crate::fcntl::at_rawfd;
33
use crate::{NixPath, Result};
44
use libc::{self, c_int, c_uint, c_ulong};
5+
use std::os::unix::io::{AsFd, AsRawFd, FromRawFd, OwnedFd, RawFd};
56

67
libc_bitflags!(
78
/// Used with [`mount`].
@@ -86,7 +87,7 @@ libc_bitflags!(
8687
MNT_DETACH;
8788
/// Mark the mount point as expired.
8889
MNT_EXPIRE;
89-
/// Don't dereference `target` if it is a symlink.
90+
/// Don't dereference `target` if it is a symlink.
9091
UMOUNT_NOFOLLOW;
9192
}
9293
);
@@ -190,8 +191,13 @@ pub fn open_tree<Fd: AsFd, P: ?Sized + NixPath>(
190191
flags: OpenTreeFlags,
191192
) -> Result<OwnedFd> {
192193
let res = pathname.with_nix_path(|cstr| unsafe {
193-
let fd = dirfd.map(|v| v.as_fd().as_raw_fd()).unwrap_or(-1);
194-
libc::syscall(libc::SYS_open_tree, fd, cstr.as_ptr(), flags.bits())
194+
let raw_dirfd = at_rawfd(dirfd.map(|v| v.as_fd().as_raw_fd()));
195+
libc::syscall(
196+
libc::SYS_open_tree,
197+
raw_dirfd,
198+
cstr.as_ptr(),
199+
flags.bits(),
200+
)
195201
})?;
196202
Errno::result(res).map(|r| unsafe { OwnedFd::from_raw_fd(r as RawFd) })
197203
}

0 commit comments

Comments
 (0)