From 82e48fe89940bc0a2340022a604964a103c8722c Mon Sep 17 00:00:00 2001 From: Mehul <65443164+infiniteregrets@users.noreply.github.com> Date: Mon, 20 Jun 2022 13:37:20 -0400 Subject: [PATCH] Fix once cell renaimings (#159) --- CHANGELOG.md | 2 +- mirrord-layer/src/file.rs | 13 +++++++++---- mirrord-layer/src/lib.rs | 9 ++++----- mirrord-layer/src/sockets.rs | 11 +++++------ 4 files changed, 19 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f24e2b1e05..f1885ddae37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,8 +18,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how - CI: Collect mirrord-agent logs in case of failure in e2e. - Add "app" = "mirrord" label to the agent pod for log collection at ease. - CI: Add sleep after local app finishes loading for agent to load filter make tests less flaky. - - Handle relative paths for open, openat +- Fix once cell renamings, PR [#98165](https://github.com/rust-lang/rust/pull/98165) ## 2.2.1 ### Changed diff --git a/mirrord-layer/src/file.rs b/mirrord-layer/src/file.rs index cfe4f53dbb7..4b26bae1444 100644 --- a/mirrord-layer/src/file.rs +++ b/mirrord-layer/src/file.rs @@ -1,4 +1,9 @@ -use std::{collections::HashMap, env, lazy::SyncLazy, os::unix::io::RawFd, sync::Mutex}; +use std::{ + collections::HashMap, + env, + os::unix::io::RawFd, + sync::{LazyLock, Mutex}, +}; use libc::{c_int, O_ACCMODE, O_APPEND, O_CREAT, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY}; use mirrord_protocol::OpenOptionsInternal; @@ -9,7 +14,7 @@ pub(crate) mod hooks; pub(crate) mod ops; /// Regex that ignores system files + files in the current working directory. -static IGNORE_FILES: SyncLazy = SyncLazy::new(|| { +static IGNORE_FILES: LazyLock = LazyLock::new(|| { // To handle the problem of injecting `open` and friends into project runners (like in a call to // `node app.js`, or `cargo run app`), we're ignoring files from the current working directory. let current_dir = env::current_dir().unwrap(); @@ -46,8 +51,8 @@ struct RemoteFile { fd: RawFd, } -pub(crate) static OPEN_FILES: SyncLazy>> = - SyncLazy::new(|| Mutex::new(HashMap::with_capacity(4))); +pub(crate) static OPEN_FILES: LazyLock>> = + LazyLock::new(|| Mutex::new(HashMap::with_capacity(4))); pub(crate) trait OpenOptionsInternalExt { fn from_flags(flags: c_int) -> Self; diff --git a/mirrord-layer/src/lib.rs b/mirrord-layer/src/lib.rs index d84074cfde8..a1fa40f911b 100644 --- a/mirrord-layer/src/lib.rs +++ b/mirrord-layer/src/lib.rs @@ -7,8 +7,7 @@ use std::{ env, - lazy::{SyncLazy, SyncOnceCell}, - sync::Mutex, + sync::{LazyLock, Mutex, OnceLock}, }; use actix_codec::{AsyncRead, AsyncWrite}; @@ -54,11 +53,11 @@ mod tcp_mirror; use crate::{common::HookMessage, config::Config, macros::hook}; -static RUNTIME: SyncLazy = SyncLazy::new(|| Runtime::new().unwrap()); -static GUM: SyncLazy = SyncLazy::new(|| unsafe { Gum::obtain() }); +static RUNTIME: LazyLock = LazyLock::new(|| Runtime::new().unwrap()); +static GUM: LazyLock = LazyLock::new(|| unsafe { Gum::obtain() }); pub static mut HOOK_SENDER: Option> = None; -pub static ENABLED_FILE_OPS: SyncOnceCell = SyncOnceCell::new(); +pub static ENABLED_FILE_OPS: OnceLock = OnceLock::new(); #[ctor] fn init() { diff --git a/mirrord-layer/src/sockets.rs b/mirrord-layer/src/sockets.rs index 1eea0d236e2..f4dc397931f 100644 --- a/mirrord-layer/src/sockets.rs +++ b/mirrord-layer/src/sockets.rs @@ -2,10 +2,9 @@ //! absolute minimum use std::{ collections::{HashMap, VecDeque}, - lazy::SyncLazy, net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr}, os::unix::io::RawFd, - sync::{Arc, Mutex}, + sync::{Arc, LazyLock, Mutex}, }; use errno::{errno, set_errno, Errno}; @@ -22,11 +21,11 @@ use crate::{ HOOK_SENDER, }; -pub(crate) static SOCKETS: SyncLazy>>> = - SyncLazy::new(|| Mutex::new(HashMap::new())); +pub(crate) static SOCKETS: LazyLock>>> = + LazyLock::new(|| Mutex::new(HashMap::new())); -pub static CONNECTION_QUEUE: SyncLazy> = - SyncLazy::new(|| Mutex::new(ConnectionQueue::default())); +pub static CONNECTION_QUEUE: LazyLock> = + LazyLock::new(|| Mutex::new(ConnectionQueue::default())); /// Struct sent over the socket once created to pass metadata to the hook #[derive(Debug)]