diff --git a/Cargo.toml b/Cargo.toml index c2fa9b8..863b009 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,7 +32,7 @@ hyper-util = "0.1.7" hyper-rustls = { version = "0.27", features = ["http2"] } detee-sgx = { git = "ssh://git@gitea.detee.cloud/SGX/detee-sgx", branch = "hacker-challenge", features = ["tonic", "occlum", "sealing"] } - +once_cell = "1.20.2" env_logger = "0.11" [build-dependencies] diff --git a/src/persistence.rs b/src/persistence.rs index 60d937e..59f26dd 100644 --- a/src/persistence.rs +++ b/src/persistence.rs @@ -4,11 +4,15 @@ use detee_sgx::SgxError; use serde::{Deserialize, Serialize}; use serde_with::{base64::Base64, serde_as}; use std::io::Write; - +use once_cell::sync::Lazy; +use std::sync::Mutex; pub struct Logfile {} +static LOG_MUTEX: Lazy> = Lazy::new(|| Mutex::new(())); + impl Logfile { pub fn append(path: &str, msg: &str) -> Result<(), Box> { + let _lock = LOG_MUTEX.lock(); let mut file = std::fs::OpenOptions::new().create(true).append(true).open(path)?; file.write_all(msg.as_bytes())?; Ok(())