From d0d952d1fa4eedd4dc0c0b3109b4ee15f3693001 Mon Sep 17 00:00:00 2001 From: Jonathan Schwender <55576758+jschwe@users.noreply.github.com> Date: Wed, 13 Aug 2025 11:51:40 +0200 Subject: [PATCH] build(deps): bump nix from 0.29.0 to 0.30.1 (#38650) Bumps [nix](https://github.com/nix-rust/nix) from 0.29.0 to 0.30.1. - [Changelog](https://github.com/nix-rust/nix/blob/master/CHANGELOG.md) - [Commits](https://github.com/nix-rust/nix/compare/v0.29.0...v0.30.1) Closes: #38145 Testing: Covered by existing tests Signed-off-by: Jonathan Schwender --- Cargo.lock | 4 ++-- Cargo.toml | 2 +- ports/servoshell/egl/log.rs | 23 +++++++++++++++-------- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5ead42d73dd..09fe9e5c347 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -687,7 +687,7 @@ dependencies = [ "libc", "log", "mach2", - "nix 0.29.0", + "nix 0.30.1", "rustc-demangle", "serde_json", ] @@ -7773,7 +7773,7 @@ dependencies = [ "napi-ohos", "net", "net_traits", - "nix 0.29.0", + "nix 0.30.1", "objc2-app-kit 0.3.1", "objc2-foundation 0.3.1", "ohos-abilitykit-sys", diff --git a/Cargo.toml b/Cargo.toml index a72cf189843..1a18cb7e22c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -106,7 +106,7 @@ mime = "0.3.13" mime_guess = "2.0.5" mozangle = "0.5.3" net_traits = { path = "components/shared/net" } -nix = "0.29" +nix = "0.30" nom = "8.0.0" num-traits = "0.2" num_cpus = "1.17.0" diff --git a/ports/servoshell/egl/log.rs b/ports/servoshell/egl/log.rs index 86c86356a52..325b31031ec 100644 --- a/ports/servoshell/egl/log.rs +++ b/ports/servoshell/egl/log.rs @@ -4,7 +4,7 @@ //! Helper Module to redirect stdout/stderr to the logging sink -use std::os::fd::{AsRawFd, IntoRawFd, RawFd}; +use std::os::fd::{IntoRawFd, RawFd}; use std::thread; use log::{debug, error, info, warn}; @@ -34,12 +34,19 @@ pub(crate) fn redirect_stdout_and_stderr() -> Result<(), LogRedirectError> { // The first step is to redirect stdout and stderr to the logs. // We redirect stdout and stderr to a custom descriptor. let (readerfd, writerfd) = nix::unistd::pipe().map_err(LogRedirectError::CreatePipeFailed)?; - // Leaks the writer fd. We want to log for the whole program lifetime. - let raw_writerfd = writerfd.into_raw_fd(); - let _fd = nix::unistd::dup2(raw_writerfd, RawFd::from(1)) - .map_err(LogRedirectError::RedirectToPipeFailed)?; - let _fd = nix::unistd::dup2(raw_writerfd, RawFd::from(2)) - .map_err(LogRedirectError::RedirectToPipeFailed)?; + // SAFETY: `writerfd`, `fd1` and `fd2` are all `OwnedFd`s for the same file. + // We take care to leak all 3 of them to ensure the writerfd is not closed, and thus + // naturally also prevent double closes. + unsafe { + let fd1 = nix::unistd::dup2_raw(&writerfd, RawFd::from(1)) + .map_err(LogRedirectError::RedirectToPipeFailed)?; + let fd2 = nix::unistd::dup2_raw(&writerfd, RawFd::from(2)) + .map_err(LogRedirectError::RedirectToPipeFailed)?; + // Leaks the writer fds. We want to log for the whole program lifetime. + let _ = writerfd.into_raw_fd(); + let _ = fd1.into_raw_fd(); + let _ = fd2.into_raw_fd(); + } // Then we spawn a thread whose only job is to read from the other side of the // pipe and redirect to the logs. @@ -52,7 +59,7 @@ pub(crate) fn redirect_stdout_and_stderr() -> Result<(), LogRedirectError> { loop { let result = { let read_into = &mut buf[cursor..]; - nix::unistd::read(readerfd.as_raw_fd(), read_into) + nix::unistd::read(&readerfd, read_into) }; let end = match result {