Skip to content

Commit ae87d30

Browse files
committed
update(): pass sysroot as parameter
Remove duplicated sysroot as `openat::Dir::open("/")` and pass as a parameter
1 parent 743244c commit ae87d30

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

src/bootupd.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,15 @@ fn ensure_writable_boot() -> Result<()> {
215215
}
216216

217217
/// daemon implementation of component update
218-
pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
218+
pub(crate) fn update(name: &str, sysroot: &openat::Dir) -> Result<ComponentUpdateResult> {
219219
let mut state = SavedState::load_from_disk("/")?.unwrap_or_default();
220220
let component = component::new_from_name(name)?;
221221
let inst = if let Some(inst) = state.installed.get(name) {
222222
inst.clone()
223223
} else {
224224
anyhow::bail!("Component {} is not installed", name);
225225
};
226-
let sysroot = openat::Dir::open("/")?;
227-
let update = component.query_update(&sysroot)?;
226+
let update = component.query_update(sysroot)?;
228227
let update = match update.as_ref() {
229228
Some(p) if inst.meta.can_upgrade_to(p) => p,
230229
_ => return Ok(ComponentUpdateResult::AtLatestVersion),
@@ -235,6 +234,7 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
235234
let mut pending_container = state.pending.take().unwrap_or_default();
236235
let interrupted = pending_container.get(component.name()).cloned();
237236
pending_container.insert(component.name().into(), update.clone());
237+
let sysroot = sysroot.try_clone()?;
238238
let mut state_guard =
239239
SavedState::acquire_write_lock(sysroot).context("Failed to acquire write lock")?;
240240
state_guard
@@ -408,7 +408,7 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
408408
Ok(())
409409
}
410410

411-
pub(crate) fn client_run_update() -> Result<()> {
411+
pub(crate) fn client_run_update(sysroot: &openat::Dir) -> Result<()> {
412412
crate::try_fail_point!("update");
413413
let status: Status = status()?;
414414
if status.components.is_empty() && status.adoptable.is_empty() {
@@ -421,7 +421,7 @@ pub(crate) fn client_run_update() -> Result<()> {
421421
ComponentUpdatable::Upgradable => {}
422422
_ => continue,
423423
};
424-
match update(name)? {
424+
match update(name, sysroot)? {
425425
ComponentUpdateResult::AtLatestVersion => {
426426
// Shouldn't happen unless we raced with another client
427427
eprintln!(
@@ -656,7 +656,8 @@ mod tests {
656656
fn test_failpoint_update() {
657657
let guard = fail::FailScenario::setup();
658658
fail::cfg("update", "return").unwrap();
659-
let r = client_run_update();
659+
let sysroot = openat::Dir::open("/").expect("open /");
660+
let r = client_run_update(&sysroot);
660661
assert_eq!(r.is_err(), true);
661662
guard.teardown();
662663
}

src/cli/bootupctl.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
use crate::bootupd;
2-
use anyhow::Result;
2+
use anyhow::{Context, Result};
33
use clap::Parser;
44
use log::LevelFilter;
55

6+
use std::os::unix::io::AsRawFd;
67
use std::os::unix::process::CommandExt;
78
use std::process::{Command, Stdio};
89

@@ -129,7 +130,14 @@ impl CtlCommand {
129130
/// Runner for `update` verb.
130131
fn run_update() -> Result<()> {
131132
ensure_running_in_systemd()?;
132-
bootupd::client_run_update()
133+
let sysroot = openat::Dir::open("/").context("Opening root dir")?;
134+
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd());
135+
let dest_root = std::fs::read_link(dest_fd)?;
136+
137+
let devices = crate::blockdev::get_devices(&dest_root)
138+
.with_context(|| "while looking for parent devices")?;
139+
crate::blockdev::init_parent_devices(devices);
140+
bootupd::client_run_update(&sysroot)
133141
}
134142

135143
/// Runner for `update` verb.

0 commit comments

Comments
 (0)