fix: keep watching the boot when the service manager connection drops

This commit is contained in:
Willem Vanhulle committed 2026-10-25 13:55:26 +01:00
1 parent 4710230129
commit cba3e404f9
2 files changed
+45 -30

No files matched your search

+18 -5
View File
@@ -45,10 +45,6 @@ impl UnitRecord {
.min() .min()
} }
fn is_pending(&self) -> bool {
matches!(self.progress, Progress::Pending(_))
}
fn is_finished(&self) -> bool { fn is_finished(&self) -> bool {
matches!(self.progress, Progress::Finished(_)) matches!(self.progress, Progress::Finished(_))
} }
@@ -243,7 +239,7 @@ impl BootState {
let Root::Queued(root) = &self.root else { let Root::Queued(root) = &self.root else {
return false; return false;
}; };
self.units.get(root).is_some_and(|root| !root.is_pending()) self.units.get(root).is_some_and(UnitRecord::is_finished)
} }
#[must_use] #[must_use]
@@ -318,6 +314,23 @@ mod tests {
assert!(state.is_complete()); assert!(state.is_complete());
} }
#[test]
fn reconnecting_keeps_the_boot_running() {
let mut state = sample();
state.forget_jobs();
assert!(!state.is_complete());
}
#[test]
fn boot_completes_once_the_requeued_root_job_is_gone() {
let mut state = sample();
state.forget_jobs();
state.queue_job(20, "graphical.target", JobKind::BringsUp, 6000 * MS);
assert!(!state.is_complete());
state.finish_job(20, JobResult::Done, 7000 * MS);
assert!(state.is_complete());
}
#[test] #[test]
fn display_manager_activation_does_not_complete_the_boot() { fn display_manager_activation_does_not_complete_the_boot() {
let mut state = sample(); let mut state = sample();
+27 -25
View File
@@ -56,10 +56,9 @@ impl Link {
} }
} }
enum RootFs { enum RootSwitch {
Initrd, NotQueued,
SwitchingTo(Sysroot), Queued(Sysroot),
Host,
} }
struct TrackedUnit { struct TrackedUnit {
@@ -73,7 +72,7 @@ struct BusFeed {
phase: Phase, phase: Phase,
link: Link, link: Link,
unit_paths: HashMap<Path<'static>, String>, unit_paths: HashMap<Path<'static>, String>,
root_fs: RootFs, root_switch: RootSwitch,
gave_origin: bool, gave_origin: bool,
} }
@@ -100,11 +99,7 @@ impl BusFeed {
Self { Self {
scope, scope,
target, target,
root_fs: if phase == Phase::Initrd { root_switch: RootSwitch::NotQueued,
RootFs::Initrd
} else {
RootFs::Host
},
phase, phase,
link: Link::connecting(), link: Link::connecting(),
unit_paths: HashMap::new(), unit_paths: HashMap::new(),
@@ -169,7 +164,7 @@ impl BusFeed {
fn lose_connection(&mut self) -> Vec<ScreenInput> { fn lose_connection(&mut self) -> Vec<ScreenInput> {
let at = monotonic_now(); let at = monotonic_now();
let RootFs::SwitchingTo(sysroot) = mem::replace(&mut self.root_fs, RootFs::Host) else { let RootSwitch::Queued(sysroot) = &self.root_switch else {
if self.phase == Phase::Shutdown { if self.phase == Phase::Shutdown {
return boot_inputs(vec![BootChange::ManagerExited { at }]); return boot_inputs(vec![BootChange::ManagerExited { at }]);
} }
@@ -179,6 +174,7 @@ impl BusFeed {
if let Err(error) = sysroot.enter() { if let Err(error) = sysroot.enter() {
return vec![ScreenInput::Failed(error.into())]; return vec![ScreenInput::Failed(error.into())];
} }
self.root_switch = RootSwitch::NotQueued;
self.unit_paths.clear(); self.unit_paths.clear();
self.phase = Phase::Host; self.phase = Phase::Host;
self.link = Link::connecting(); self.link = Link::connecting();
@@ -206,20 +202,25 @@ impl BusFeed {
Ok(target.clone()) Ok(target.clone())
} }
async fn origin_change( async fn boot_progress_changes(
&mut self, &mut self,
connection: &mut BusConnection, connection: &mut BusConnection,
) -> Result<Vec<BootChange>, Error> { ) -> Result<Vec<BootChange>, Error> {
if self.gave_origin { let boot_in_progress = connection.boot_in_progress().await?;
return Ok(Vec::new()); let origin = (!self.gave_origin).then(|| {
} BootChange::SetOrigin(if boot_in_progress {
Duration::ZERO
} else {
monotonic_now()
})
});
self.gave_origin = true; self.gave_origin = true;
if connection.boot_in_progress().await? { let finished = if boot_in_progress {
return Ok(vec![BootChange::SetOrigin(Duration::ZERO)]); Vec::new()
} } else {
Ok(once(BootChange::SetOrigin(monotonic_now())) self.boot_finished()
.chain(self.boot_finished()) };
.collect()) Ok(origin.into_iter().chain(finished).collect())
} }
async fn track_all( async fn track_all(
@@ -262,7 +263,7 @@ impl BusFeed {
.filter(|job| shutting_down || job.kind == JobKind::BringsUp) .filter(|job| shutting_down || job.kind == JobKind::BringsUp)
.collect(); .collect();
let requested_root = self.requested_root(connection, &jobs).await?; let requested_root = self.requested_root(connection, &jobs).await?;
let origin_change = self.origin_change(connection).await?; let boot_progress = self.boot_progress_changes(connection).await?;
let tracked_root = self.track(connection, &requested_root).await; let tracked_root = self.track(connection, &requested_root).await;
let root = tracked_root let root = tracked_root
.as_ref() .as_ref()
@@ -288,7 +289,7 @@ impl BusFeed {
}, },
); );
let queued_at = monotonic_now(); let queued_at = monotonic_now();
Ok(origin_change Ok(boot_progress
.into_iter() .into_iter()
.chain(tracked_root.and_then(|tracked| tracked.change)) .chain(tracked_root.and_then(|tracked| tracked.change))
.chain(tracked_handoff.and_then(|tracked| tracked.change)) .chain(tracked_handoff.and_then(|tracked| tracked.change))
@@ -374,11 +375,12 @@ impl BusFeed {
let unit = tracked let unit = tracked
.as_ref() .as_ref()
.map_or(unit, |tracked| tracked.name.clone()); .map_or(unit, |tracked| tracked.name.clone());
if matches!(self.root_fs, RootFs::Initrd) if self.phase == Phase::Initrd
&& matches!(self.root_switch, RootSwitch::NotQueued)
&& unit == SWITCH_ROOT_UNIT && unit == SWITCH_ROOT_UNIT
&& let Ok(sysroot) = Sysroot::hold() && let Ok(sysroot) = Sysroot::hold()
{ {
self.root_fs = RootFs::SwitchingTo(sysroot); self.root_switch = RootSwitch::Queued(sysroot);
} }
tracked tracked
.and_then(|tracked| tracked.change) .and_then(|tracked| tracked.change)