Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix emulated cgroups v1 subsystem when running docker-in-docker #2532

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions crates/libcontainer/src/rootfs/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Mount {
panic!("libcontainer can't run in a Legacy or Hybrid cgroup setup without the v1 feature");
#[cfg(feature = "v1")]
self.mount_cgroup_v1(mount, options).map_err(|err| {
tracing::error!("failed to mount cgroup v2: {}", err);
tracing::error!("failed to mount cgroup v1: {}", err);
err
})?
}
Expand Down Expand Up @@ -171,10 +171,29 @@ impl Mount {
tracing::debug!("cgroup mounts: {:?}", host_mounts);

// get process cgroups
let ppid = std::os::unix::process::parent_id();
// The non-zero ppid means that the PID Namespace is not separated.
let ppid = if ppid == 0 { std::process::id() } else { ppid };
utam0k marked this conversation as resolved.
Show resolved Hide resolved
let root_cgroups = Process::new(ppid as i32)?.cgroups()?.0;
let process_cgroups: HashMap<String, String> = Process::myself()?
.cgroups()?
.into_iter()
.map(|c| (c.controllers.join(","), c.pathname))
.map(|c| {
let hierarchy = c.hierarchy;
// When youki itself is running inside a container, the cgroup path
// will include the path of pid-1, which needs to be stripped before
// mounting.
let root_pathname = root_cgroups
.iter()
.find(|c| c.hierarchy == hierarchy)
.map(|c| c.pathname.as_ref())
.unwrap_or("");
let path = c
.pathname
.strip_prefix(root_pathname)
.unwrap_or(&c.pathname);
(c.controllers.join(","), path.to_owned())
})
.collect();
tracing::debug!("Process cgroups: {:?}", process_cgroups);

Expand Down
10 changes: 9 additions & 1 deletion crates/youki/src/observability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,15 @@ where
let journald = config.systemd_log;

let systemd_journald = if journald {
Some(tracing_journald::layer()?.with_syslog_identifier("youki".to_string()))
match tracing_journald::layer() {
Ok(layer) => Some(layer.with_syslog_identifier("youki".to_string())),
Err(err) => {
// Do not fail if we can't open syslog, just print a warning.
// This is the case in, e.g., docker-in-docker.
eprintln!("failed to initialize syslog logging: {:?}", err);
None
}
}
} else {
None
};
Expand Down