Skip to content

Commit 39b0a32

Browse files
authored
Merge pull request #1589 from cgwalters/journal-followups
log to journal if root
2 parents 84aba8e + 8768d70 commit 39b0a32

File tree

6 files changed

+11
-7
lines changed

6 files changed

+11
-7
lines changed

crates/lib/src/cli.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -910,7 +910,7 @@ fn prepare_for_write() -> Result<()> {
910910
crate::cli::require_root(false)?;
911911
ensure_self_unshared_mount_namespace()?;
912912
if crate::lsm::selinux_enabled()? && !crate::lsm::selinux_ensure_install()? {
913-
tracing::warn!("Do not have install_t capabilities");
913+
tracing::debug!("Do not have install_t capabilities");
914914
}
915915
ENTERED.store(true, Ordering::SeqCst);
916916
Ok(())
@@ -1215,9 +1215,8 @@ async fn usroverlay() -> Result<()> {
12151215
pub fn global_init() -> Result<()> {
12161216
// In some cases we re-exec with a temporary binary,
12171217
// so ensure that the syslog identifier is set.
1218-
let name = "bootc";
1219-
ostree::glib::set_prgname(name.into());
1220-
if let Err(e) = rustix::thread::set_name(&CString::new(name).unwrap()) {
1218+
ostree::glib::set_prgname(bootc_utils::NAME.into());
1219+
if let Err(e) = rustix::thread::set_name(&CString::new(bootc_utils::NAME).unwrap()) {
12211220
// This shouldn't ever happen
12221221
eprintln!("failed to set name: {e}");
12231222
}

crates/lib/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,7 @@ pub(crate) fn exec_in_host_mountns(args: &[std::ffi::OsString]) -> Result<()> {
918918
tracing::debug!("Using supermin workaround");
919919
rustix::process::chroot("/root").context("chroot")?;
920920
}
921-
Err(Command::new(cmd).args(args).exec()).context("exec")?
921+
Err(Command::new(cmd).args(args).arg0(bootc_utils::NAME).exec()).context("exec")?
922922
}
923923

924924
pub(crate) struct RootSetup {

crates/lib/src/lsm.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ pub(crate) fn selinux_ensure_install() -> Result<bool> {
110110
cmd.env(guardenv, tmpf);
111111
cmd.env(bootc_utils::reexec::ORIG, srcpath);
112112
cmd.args(std::env::args_os().skip(1));
113+
cmd.arg0(bootc_utils::NAME);
113114
cmd.log_debug();
114115
Err(anyhow::Error::msg(cmd.exec()).context("execve"))
115116
}

crates/utils/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ pub mod reexec;
1717
mod result_ext;
1818
pub use result_ext::*;
1919

20+
/// The name of our binary
21+
pub const NAME: &str = "bootc";
22+
2023
/// Intended for use in `main`, calls an inner function and
2124
/// handles errors by printing them.
2225
pub fn run_main<F>(f: F)

crates/utils/src/reexec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub fn reexec_with_guardenv(k: &str, prefix_args: &[&str]) -> Result<()> {
3636
};
3737
cmd.env(k, "1");
3838
cmd.args(std::env::args_os().skip(1));
39+
cmd.arg0(crate::NAME);
3940
tracing::debug!("Re-executing current process for {k}");
4041
Err(cmd.exec().into())
4142
}

crates/utils/src/tracing_util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ use tracing_subscriber::prelude::*;
44

55
/// Initialize tracing with the default configuration.
66
pub fn initialize_tracing() {
7-
// Always try to use journald subscriber if we're running under systemd
7+
// Always try to use journald subscriber if we're running as root;
88
// This ensures key messages (info, warn, error) go to the journal
9-
let journald_layer = if let Ok(()) = std::env::var("JOURNAL_STREAM").map(|_| ()) {
9+
let journald_layer = if rustix::process::getuid().is_root() {
1010
tracing_journald::layer()
1111
.ok()
1212
.map(|layer| layer.with_filter(tracing_subscriber::filter::LevelFilter::INFO))

0 commit comments

Comments
 (0)