-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #299 from cgwalters/bootc-label
Add suggestion for `LABEL containers.bootc 1`
- Loading branch information
Showing
7 changed files
with
82 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//! Thin wrapper for systemd journaling; these APIs are no-ops | ||
//! when not running under systemd. Only use them when | ||
use std::collections::HashMap; | ||
use std::sync::atomic::{AtomicBool, Ordering}; | ||
|
||
/// Set to true if we failed to write to the journal once | ||
static EMITTED_JOURNAL_ERROR: AtomicBool = AtomicBool::new(false); | ||
|
||
/// Wrapper for structured logging which is an explicit no-op | ||
/// when systemd is not in use (e.g. in a container). | ||
pub(crate) fn journal_send<K, V>( | ||
priority: libsystemd::logging::Priority, | ||
msg: &str, | ||
vars: impl Iterator<Item = (K, V)>, | ||
) where | ||
K: AsRef<str>, | ||
V: AsRef<str>, | ||
{ | ||
if !libsystemd::daemon::booted() { | ||
return; | ||
} | ||
if let Err(e) = libsystemd::logging::journal_send(priority, msg, vars) { | ||
if !EMITTED_JOURNAL_ERROR.swap(true, Ordering::SeqCst) { | ||
eprintln!("failed to write to journal: {e}"); | ||
} | ||
} | ||
} | ||
|
||
/// Wrapper for writing to systemd journal which is an explicit no-op | ||
/// when systemd is not in use (e.g. in a container). | ||
#[allow(dead_code)] | ||
pub(crate) fn journal_print(priority: libsystemd::logging::Priority, msg: &str) { | ||
let vars: HashMap<&str, &str> = HashMap::new(); | ||
journal_send(priority, msg, vars.into_iter()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/// This label is expected to be present on compatible base images. | ||
pub(crate) const BOOTC_COMPAT_LABEL: &str = "containers.bootc"; | ||
/// The current single well-known value for the label. | ||
pub(crate) const COMPAT_LABEL_V1: &str = "1"; |