Init: Introduce support for conditionally spawning services

depending on the architecture and selected board. With this the
migration of initfs daemons to service definitions is almost done.
This commit is contained in:
bjorn3
2026-02-28 16:55:26 +01:00
parent 9624cd3c2c
commit e86dbfa17e
12 changed files with 75 additions and 11 deletions
+18 -1
View File
@@ -50,6 +50,7 @@ impl InitConfig {
}
#[derive(Clone, Deserialize)]
#[serde(deny_unknown_fields)]
struct SwitchRoot {
prefix: PathBuf,
etcdir: PathBuf,
@@ -112,7 +113,7 @@ fn run(
unit::UnitKind::Target {} => {
if config.log_debug {
eprintln!(
"Started target {}",
"Reached target {}",
unit.info.description.as_ref().unwrap_or(&unit.id.0),
);
}
@@ -171,6 +172,22 @@ fn main() {
let runtime_target = UnitId("00_runtime.target".to_owned());
'a: while let Some(unit) = pending_units.pop_front() {
if let Some(condition_architecture) = &unit_store.unit(&unit).info.condition_architecture {
if !condition_architecture
.iter()
.any(|arch| arch == std::env::consts::ARCH)
{
continue 'a;
}
}
if let Some(condition_board) = &unit_store.unit(&unit).info.condition_board {
if !condition_board
.iter()
.any(|board| Some(&**board) == option_env!("BOARD"))
{
continue 'a;
}
}
if unit_store.unit(&unit).info.default_dependencies {
if pending_units.contains(&runtime_target) {
pending_units.push_back(unit);
+1
View File
@@ -6,6 +6,7 @@ use std::process::Command;
use serde::Deserialize;
#[derive(Clone, Debug, Deserialize)]
#[serde(deny_unknown_fields)]
pub struct Service {
pub cmd: String,
#[serde(default)]
+9
View File
@@ -77,12 +77,16 @@ pub struct Unit {
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
pub struct UnitInfo {
pub description: Option<String>,
#[serde(default = "true_bool")]
pub default_dependencies: bool,
#[serde(default)]
pub requires_weak: Vec<UnitId>,
pub condition_architecture: Option<Vec<String>>,
// FIXME replace this with hwd reading from the devicetree
pub condition_board: Option<Vec<String>>,
}
fn true_bool() -> bool {
@@ -97,17 +101,20 @@ pub enum UnitKind {
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct SerializedService {
unit: UnitInfo,
service: Service,
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct SerializedTarget {
unit: UnitInfo,
}
#[derive(Deserialize)]
#[serde(deny_unknown_fields)]
struct SerializedSwitchRoot {
unit: UnitInfo,
switchroot: SwitchRoot,
@@ -143,6 +150,8 @@ impl Unit {
description: None,
default_dependencies: true,
requires_weak,
condition_architecture: None,
condition_board: None,
},
UnitKind::LegacyScript { script },
warnings,