summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2021-06-20 14:23:38 +0200
committerMatthias Schiffer <mschiffer@universe-factory.net>2021-06-20 14:23:38 +0200
commitbe9a8479aaf63794e450e885165842704bf70bf1 (patch)
tree63f135ae97060ba54ad4f21ef08d73a5089c25dd /src
parent9d31c921b3d83e67d8eb03458b43aeb81c4d0b8c (diff)
downloadrebel-be9a8479aaf63794e450e885165842704bf70bf1.tar
rebel-be9a8479aaf63794e450e885165842704bf70bf1.zip
util/unix: use OpenOptions to avoid unsafe
Diffstat (limited to 'src')
-rw-r--r--src/util/unix.rs24
1 files changed, 11 insertions, 13 deletions
diff --git a/src/util/unix.rs b/src/util/unix.rs
index b5e4d33..0edf228 100644
--- a/src/util/unix.rs
+++ b/src/util/unix.rs
@@ -1,11 +1,12 @@
-use std::{fs::File, io::Result, os::unix::prelude::*, path::Path};
-
-use nix::{
- fcntl::{self, OFlag},
- sys::stat::Mode,
- unistd,
+use std::{
+ fs::{File, OpenOptions},
+ io::Result,
+ os::unix::prelude::*,
+ path::Path,
};
+use nix::unistd;
+
use super::ToIOResult;
pub struct SetEUID(unistd::Uid);
@@ -56,13 +57,10 @@ impl Drop for Chdir {
}
pub fn chdir<P: AsRef<Path>>(path: P) -> Result<Chdir> {
- let fd = fcntl::open(
- ".",
- OFlag::O_PATH | OFlag::O_CLOEXEC | OFlag::O_NOFOLLOW,
- Mode::empty(),
- )
- .to_io_result()?;
- let file = unsafe { File::from_raw_fd(fd) };
+ let file = OpenOptions::new()
+ .read(true)
+ .custom_flags(libc::O_PATH | libc::O_CLOEXEC | libc::O_NOFOLLOW)
+ .open(".")?;
unistd::chdir(path.as_ref()).to_io_result()?;