Skip to content

Commit

Permalink
redirect stderr to shim log
Browse files Browse the repository at this point in the history
  • Loading branch information
mingfukuang committed Aug 2, 2024
1 parent 8fe320d commit 67aace1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
12 changes: 12 additions & 0 deletions 1
Original file line number Diff line number Diff line change
@@ -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
#
3 changes: 2 additions & 1 deletion crates/runc-shim/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
14 changes: 14 additions & 0 deletions crates/shim/src/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -58,6 +59,15 @@ impl FifoLogger {
file: Mutex::new(f),
})
}

#[allow(dead_code)]
pub fn get_raw_fd(&self) -> io::Result<libc::c_int> {
let file = self
.file
.lock()
.map_err(|_| io::Error::new(io::ErrorKind::Other, "Mutex poisoned"))?;
Ok(file.as_raw_fd())
}
}

pub(crate) struct SimpleWriteVistor {
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 67aace1

Please sign in to comment.