Skip to content

Commit a89ba2e

Browse files
authored
Merge pull request #5263 from jmarrero/systemd-wrap-1
kernel_install: unwrap systemd if it's wrapped
2 parents d431da4 + af7e4c2 commit a89ba2e

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

rust/src/kernel_install.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ fn add(root: &Dir, argv: &[&str]) -> Result<()> {
5858
anyhow::bail!("No kernel version provided");
5959
};
6060
tracing::debug!("Installing kernel kver={kver}");
61+
undo_systemctl_wrap()?;
6162
println!("Generating initramfs");
6263
crate::initramfs::run_dracut(root, &kver)?;
6364
println!("Running depmod");
65+
redo_systemctl_wrap()?;
6466
Command::new("depmod")
6567
.args(["-a", kver])
6668
.run()
@@ -113,6 +115,30 @@ pub fn main(argv: &[&str]) -> Result<u8> {
113115
}
114116
}
115117

118+
#[context("Unwrapping systemctl")]
119+
fn undo_systemctl_wrap() -> Result<()> {
120+
let bin_path = &Dir::open_ambient_dir("usr/bin", cap_std::ambient_authority())?;
121+
if !bin_path.exists("systemctl.rpmostreesave") {
122+
// Not wrapped, just return.
123+
return Ok(());
124+
}
125+
bin_path.rename("systemctl", &bin_path, "systemctl.backup")?;
126+
bin_path.rename("systemctl.rpmostreesave", &bin_path, "systemctl")?;
127+
Ok(())
128+
}
129+
130+
#[context("Wrapping systemctl")]
131+
fn redo_systemctl_wrap() -> Result<()> {
132+
let bin_path = &Dir::open_ambient_dir("usr/bin", cap_std::ambient_authority())?;
133+
if !bin_path.exists("systemctl.backup") {
134+
// We did not unwrap, just return.
135+
return Ok(());
136+
}
137+
bin_path.rename("systemctl", &bin_path, "systemctl.rpmostreesave")?;
138+
bin_path.rename("systemctl.backup", &bin_path, "systemctl")?;
139+
Ok(())
140+
}
141+
116142
#[cfg(test)]
117143
mod tests {
118144
use std::path::Path;

0 commit comments

Comments
 (0)