From 9d080fc1fa3fa8cdda19efca0a2bae37072ce9da Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 8 Jan 2021 16:20:10 +0000 Subject: [PATCH] Port Rust journal bits to cxx-rs This is cleaner if we move the "catch and print errors" into the Rust side. We lose the "print errors as red" part but eh we can readd that later Rust side. --- rust/src/journal.rs | 19 +++++-------------- rust/src/lib.rs | 7 ++++++- src/app/rpmostree-builtin-status.cxx | 8 +------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/rust/src/journal.rs b/rust/src/journal.rs index 45daf7c659..d53268b354 100644 --- a/rust/src/journal.rs +++ b/rust/src/journal.rs @@ -25,7 +25,7 @@ fn print_staging_failure_msg(msg: Option<&str>) -> Result<()> { } /// Look for a failure from ostree-finalized-stage.service in the journal of the previous boot. -fn journal_print_staging_failure() -> Result<()> { +fn impl_journal_print_staging_failure() -> Result<()> { let mut j = journal::OpenOptions::default() .system(true) .local_only(true) @@ -138,18 +138,9 @@ fn journal_print_staging_failure() -> Result<()> { print_staging_failure_msg(None) } -mod ffi { - use super::*; - use glib_sys; - use libc; - - use crate::ffiutil::*; - - #[no_mangle] - pub extern "C" fn ror_journal_print_staging_failure( - gerror: *mut *mut glib_sys::GError, - ) -> libc::c_int { - int_glib_error(journal_print_staging_failure(), gerror) +pub(crate) fn journal_print_staging_failure() { + if let Err(e) = impl_journal_print_staging_failure() { + // Let's not make this fatal + eprintln!("warning: Failed to query journal: {}", e); } } -pub use self::ffi::*; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 1ffeebcebc..470dca475e 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -62,6 +62,11 @@ mod ffi { ) -> Result; } + // journal.rs + extern "Rust" { + fn journal_print_staging_failure(); + } + // scripts.rs extern "Rust" { fn script_is_ignored(pkg: &str, script: &str) -> bool; @@ -116,7 +121,7 @@ use crate::core::*; mod history; pub use self::history::*; mod journal; -pub use self::journal::*; +pub(crate) use self::journal::*; mod initramfs; pub(crate) use self::initramfs::*; mod lockfile; diff --git a/src/app/rpmostree-builtin-status.cxx b/src/app/rpmostree-builtin-status.cxx index e45c952ba6..8ea334f203 100644 --- a/src/app/rpmostree-builtin-status.cxx +++ b/src/app/rpmostree-builtin-status.cxx @@ -287,13 +287,7 @@ print_daemon_state (RPMOSTreeSysroot *sysroot_proxy, g_print ("State: %s\n", txn_proxy ? "busy" : "idle"); - /* this is a bit of a hack; it's just to avoid duplicating this logic Rust side */ - g_print ("%s%s", get_red_start (), get_bold_start ()); - g_autoptr(GError) local_error = NULL; - if (!ror_journal_print_staging_failure (&local_error)) - /* let's not make it fatal if somehow this fails */ - g_print ("Warning: failed to query journal: %s\n", local_error->message); - g_print ("%s%s", get_bold_end (), get_red_end ()); + rpmostreecxx::journal_print_staging_failure (); if (g_str_equal (policy, "none")) {