From 67aace1356c68cc4a48dc516e95e7614a003e343 Mon Sep 17 00:00:00 2001 From: kuangmingfu Date: Tue, 30 Jul 2024 17:05:09 +0800 Subject: [PATCH] redirect stderr to shim log --- 1 | 12 ++++++++++++ crates/runc-shim/src/main.rs | 3 ++- crates/shim/src/logger.rs | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 1 diff --git a/1 b/1 new file mode 100644 index 00000000..fbbe221a --- /dev/null +++ b/1 @@ -0,0 +1,12 @@ +optimize signals handle + +# 请为您的变更输入提交说明。以 '#' 开始的行将被忽略,而一个空的提交 +# 说明将会终止提交。 +# +# 日期: Tue Jul 30 18:27:47 2024 +0800 +# +# 位于分支 f3 +# 要提交的变更: +# 修改: crates/runc-shim/src/main.rs +# 修改: crates/shim/src/asynchronous/mod.rs +# diff --git a/crates/runc-shim/src/main.rs b/crates/runc-shim/src/main.rs index 2998f2f8..492d3422 100644 --- a/crates/runc-shim/src/main.rs +++ b/crates/runc-shim/src/main.rs @@ -15,8 +15,9 @@ */ use std::env; -use tokio::runtime::Builder; + use containerd_shim::{asynchronous::run, parse}; +use tokio::runtime::Builder; mod cgroup_memory; mod common; diff --git a/crates/shim/src/logger.rs b/crates/shim/src/logger.rs index aafed120..6c7466d4 100644 --- a/crates/shim/src/logger.rs +++ b/crates/shim/src/logger.rs @@ -19,6 +19,7 @@ use std::{ fmt::Write as fmtwrite, fs::{File, OpenOptions}, io::{self, Write}, + os::unix::io::AsRawFd, path::Path, str::FromStr, sync::Mutex, @@ -58,6 +59,15 @@ impl FifoLogger { file: Mutex::new(f), }) } + + #[allow(dead_code)] + pub fn get_raw_fd(&self) -> io::Result { + let file = self + .file + .lock() + .map_err(|_| io::Error::new(io::ErrorKind::Other, "Mutex poisoned"))?; + Ok(file.as_raw_fd()) + } } pub(crate) struct SimpleWriteVistor { @@ -152,6 +162,10 @@ fn configure_logging_level(debug: bool, default_log_level: &str) { } else { debug_level }; + let raw_fd = logger.get_raw_fd().unwrap(); + unsafe { + libc::dup2(raw_fd, libc::STDERR_FILENO); + } log::set_max_level(level); }