Skip to content

Commit 8da6b5c

Browse files
committed
Add more debug/trace logs
This helped me debug a selinux regression. Signed-off-by: Colin Walters <[email protected]>
1 parent 841d831 commit 8da6b5c

File tree

3 files changed

+8
-0
lines changed

3 files changed

+8
-0
lines changed

lib/src/cli.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,21 @@ pub(crate) enum Opt {
113113
pub(crate) async fn ensure_self_unshared_mount_namespace() -> Result<()> {
114114
let uid = cap_std_ext::rustix::process::getuid();
115115
if !uid.is_root() {
116+
tracing::debug!("Not root, assuming no need to unshare");
116117
return Ok(());
117118
}
118119
let recurse_env = "_ostree_unshared";
119120
let ns_pid1 = std::fs::read_link("/proc/1/ns/mnt").context("Reading /proc/1/ns/mnt")?;
120121
let ns_self = std::fs::read_link("/proc/self/ns/mnt").context("Reading /proc/self/ns/mnt")?;
121122
// If we already appear to be in a mount namespace, or we're already pid1, we're done
122123
if ns_pid1 != ns_self {
124+
tracing::debug!("Already in a mount namespace");
123125
return Ok(());
124126
}
125127
if std::env::var_os(recurse_env).is_some() {
126128
let am_pid1 = cap_std_ext::rustix::process::getpid().is_init();
127129
if am_pid1 {
130+
tracing::debug!("We are pid 1");
128131
return Ok(());
129132
} else {
130133
anyhow::bail!("Failed to unshare mount namespace");

lib/src/lsm.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ pub(crate) fn selinux_ensure_install() -> Result<()> {
2929
if p.exists() {
3030
tracing::debug!("Removing temporary file");
3131
std::fs::remove_file(p).context("Removing {p:?}")?;
32+
} else {
33+
tracing::debug!("Assuming we now have a privileged (e.g. install_t) label");
3234
}
3335
return Ok(());
3436
}
@@ -50,6 +52,7 @@ pub(crate) fn selinux_ensure_install() -> Result<()> {
5052
let mut cmd = Command::new(&tmpf);
5153
cmd.env(guardenv, tmpf);
5254
cmd.args(std::env::args_os().skip(1));
55+
tracing::debug!("Re-executing");
5356
Err(anyhow::Error::msg(cmd.exec()).context("execve"))
5457
}
5558

lib/src/reexec.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use fn_error_context::context;
88
#[context("Reexec self")]
99
pub(crate) fn reexec_with_guardenv(k: &str, prefix_args: &[&str]) -> Result<()> {
1010
if std::env::var_os(k).is_some() {
11+
tracing::trace!("Skipping re-exec due to env var {k}");
1112
return Ok(());
1213
}
1314
let self_exe = std::fs::read_link("/proc/self/exe")?;
@@ -22,5 +23,6 @@ pub(crate) fn reexec_with_guardenv(k: &str, prefix_args: &[&str]) -> Result<()>
2223
};
2324
cmd.env(k, "1");
2425
cmd.args(std::env::args_os().skip(1));
26+
tracing::debug!("Re-executing current process for {k}");
2527
Err(cmd.exec().into())
2628
}

0 commit comments

Comments
 (0)