Skip to content

Commit

Permalink
Fix issues when running with docker-in-docker
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <[email protected]>
  • Loading branch information
jprendes committed Nov 16, 2023
1 parent 88ae039 commit 289efd2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
20 changes: 19 additions & 1 deletion crates/libcontainer/src/rootfs/mount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,28 @@ impl Mount {
tracing::debug!("cgroup mounts: {:?}", host_mounts);

// get process cgroups
let ppid = std::os::unix::process::parent_id();
let ppid = if ppid == 0 { std::process::id() } else { ppid };
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

0 comments on commit 289efd2

Please sign in to comment.