* [pbs-devel] [PATCH proxmox 1/2] sys: adapt to IO Safety changes in rustc
2024-08-05 11:59 [pbs-devel] [PATCH proxmox 0/2] sys: rustc 1.80/IO-safety compat Fabian Grünbichler
@ 2024-08-05 11:59 ` Fabian Grünbichler
2024-08-05 11:59 ` [pbs-devel] [PATCH proxmox 2/2] sys: make fd::cwd crate-internal Fabian Grünbichler
2024-08-06 11:54 ` [pbs-devel] applied-series: [PATCH proxmox 0/2] sys: rustc 1.80/IO-safety compat Wolfgang Bumiller
2 siblings, 0 replies; 4+ messages in thread
From: Fabian Grünbichler @ 2024-08-05 11:59 UTC (permalink / raw)
To: pbs-devel
`OwnedFd`s are now (rustc 1.80+) checked for validity when dropped in a debug
build, to catch usage after closing. Unfortunately those checks don't account
for the special value `AT_FDCWD` (-100) which is not a "real" FD, but a magic
constant used by many libc functions to signify operations starting at the
current working directory.
changing our `cwd` helper to open the CWD for real, instead of just returning
the magic value that pretends to be an FD, works around those limitations with
the least API churn.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
technically the changed return type is a breaking change, but see next
patch..
proxmox-sys/src/fd.rs | 6 +++---
proxmox-sys/src/fs/dir.rs | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/proxmox-sys/src/fd.rs b/proxmox-sys/src/fd.rs
index ad12e663..073dd08d 100644
--- a/proxmox-sys/src/fd.rs
+++ b/proxmox-sys/src/fd.rs
@@ -2,9 +2,9 @@
use std::os::unix::io::AsRawFd;
-use nix::fcntl::OFlag;
use nix::sys::stat::Mode;
use nix::NixPath;
+use nix::{fcntl::OFlag, sys::stat};
use std::os::unix::io::{FromRawFd, OwnedFd, RawFd};
@@ -23,8 +23,8 @@ pub fn change_cloexec(fd: RawFd, on: bool) -> Result<(), anyhow::Error> {
Ok(())
}
-pub fn cwd() -> OwnedFd {
- unsafe { OwnedFd::from_raw_fd(libc::AT_FDCWD) }
+pub fn cwd() -> Result<OwnedFd, nix::Error> {
+ open(".", OFlag::O_DIRECTORY, stat::Mode::empty())
}
pub fn open<P>(path: &P, oflag: OFlag, mode: Mode) -> Result<OwnedFd, nix::Error>
diff --git a/proxmox-sys/src/fs/dir.rs b/proxmox-sys/src/fs/dir.rs
index 807a00ad..a7a95b02 100644
--- a/proxmox-sys/src/fs/dir.rs
+++ b/proxmox-sys/src/fs/dir.rs
@@ -120,7 +120,7 @@ fn create_path_do(
}
Some(Component::CurDir) => {
let _ = iter.next();
- crate::fd::cwd()
+ crate::fd::cwd()?
}
Some(Component::ParentDir) => {
let _ = iter.next();
@@ -128,7 +128,7 @@ fn create_path_do(
}
Some(Component::Normal(_)) => {
// simply do not advance the iterator, heavy lifting happens in create_path_at_do()
- crate::fd::cwd()
+ crate::fd::cwd()?
}
None => bail!("create_path on empty path?"),
};
--
2.39.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [pbs-devel] [PATCH proxmox 2/2] sys: make fd::cwd crate-internal
2024-08-05 11:59 [pbs-devel] [PATCH proxmox 0/2] sys: rustc 1.80/IO-safety compat Fabian Grünbichler
2024-08-05 11:59 ` [pbs-devel] [PATCH proxmox 1/2] sys: adapt to IO Safety changes in rustc Fabian Grünbichler
@ 2024-08-05 11:59 ` Fabian Grünbichler
2024-08-06 11:54 ` [pbs-devel] applied-series: [PATCH proxmox 0/2] sys: rustc 1.80/IO-safety compat Wolfgang Bumiller
2 siblings, 0 replies; 4+ messages in thread
From: Fabian Grünbichler @ 2024-08-05 11:59 UTC (permalink / raw)
To: pbs-devel
it's not used by anything outside of proxmox-sys.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
---
alternatively, could also be inlined completely..
proxmox-sys/src/fd.rs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/proxmox-sys/src/fd.rs b/proxmox-sys/src/fd.rs
index 073dd08d..8d85bd2e 100644
--- a/proxmox-sys/src/fd.rs
+++ b/proxmox-sys/src/fd.rs
@@ -23,7 +23,7 @@ pub fn change_cloexec(fd: RawFd, on: bool) -> Result<(), anyhow::Error> {
Ok(())
}
-pub fn cwd() -> Result<OwnedFd, nix::Error> {
+pub(crate) fn cwd() -> Result<OwnedFd, nix::Error> {
open(".", OFlag::O_DIRECTORY, stat::Mode::empty())
}
--
2.39.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
^ permalink raw reply [flat|nested] 4+ messages in thread