public inbox for pbs-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: "Fabian Grünbichler" <f.gruenbichler@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox 1/2] sys: adapt to IO Safety changes in rustc
Date: Mon,  5 Aug 2024 13:59:07 +0200	[thread overview]
Message-ID: <20240805115908.634278-2-f.gruenbichler@proxmox.com> (raw)
In-Reply-To: <20240805115908.634278-1-f.gruenbichler@proxmox.com>

`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

  reply	other threads:[~2024-08-05 11:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240805115908.634278-2-f.gruenbichler@proxmox.com \
    --to=f.gruenbichler@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal