From 9027bb8afbba1b877d86d3d63c35b53297aa344c Mon Sep 17 00:00:00 2001 From: Marc Schoolderman Date: Mon, 7 Oct 2024 16:57:40 +0200 Subject: [PATCH] incorporate comments from @pvdrz --- src/system/mod.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/system/mod.rs b/src/system/mod.rs index 16b52a2fb..5ae667999 100644 --- a/src/system/mod.rs +++ b/src/system/mod.rs @@ -108,7 +108,10 @@ impl FileCloser { fn close_range(min_fd: c_uint, max_fd: c_uint) -> io::Result<()> { if min_fd <= max_fd { - // SAFETY: this function is safe to call with these arguments + // SAFETY: this function is safe to call: + // - any errors while closing a specific fd will be effectively ignored + // - if the provided range or flags are invalid, that will be reported + // as an error but will not cause undefined behaviour cerr(unsafe { libc::close_range(min_fd, max_fd, 0) })?; } @@ -584,7 +587,8 @@ impl Process { /// Get the session id for the current process pub fn session_id() -> ProcessId { - // SAFETY: "If pid is 0, getsid() returns the session ID of the calling process." + // SAFETY: this function is explicitly safe to call with argument 0, + // and more generally getsid will never cause memory safety issues. unsafe { libc::getsid(0) } }