Skip to content

Commit

Permalink
[antlir2][rpms] prevent /dev/null from existing
Browse files Browse the repository at this point in the history
Summary:
We need to make sure shitty rpm scripts aren't trying to write to `/dev/null`
(and possibly friends).

Test Plan:
```
❯ buck2 build --show-output fbcode//tupperware/image/base/impl:base.c9.os[debug][package_manager][subvol]
BUILD SUCCEEDED
fbcode//tupperware/image/base/impl:base.c9.os[debug][package_manager][subvol] buck-out/v2/gen/fbcode/f88b3f368c9334db/tupperware/image/base/impl/__base.c9.os__/subvol-package_manager_compile

vmagro@devvm11640.ftw0 in fbsource
❯ ls buck-out/v2/gen/fbcode/f88b3f368c9334db/tupperware/image/base/impl/__base.c9.os__/subvol-package_manager_compile/dev
```

Reviewed By: epilatow

Differential Revision: D49062146

fbshipit-source-id: f4327d922a3ef1eb2fbe7f7d467b5e11299796cb
  • Loading branch information
vmagro authored and facebook-github-bot committed Sep 7, 2023
1 parent 360b1a7 commit cf1be55
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions antlir/antlir2/features/BUCK
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ feature_impl(
feature_impl(
name = "rpm",
deps = [
"nix",
"serde_json",
"//antlir/buck/buck_label:buck_label",
],
Expand Down
16 changes: 16 additions & 0 deletions antlir/antlir2/features/rpm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use buck_label::Label;
use nix::mount::MntFlags;
use nix::mount::MsFlags;
use serde::de::Error as _;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -330,6 +332,16 @@ fn run_dnf_driver(
})
.context("while serializing dnf-driver input")?;

std::fs::create_dir_all(ctx.dst_path("/dev")).context("while ensuring /dev exists")?;
nix::mount::mount(
Some("devtmpfs"),
&ctx.dst_path("/dev"),
Some("devtmpfs"),
MsFlags::empty(),
None::<&str>,
)
.context("while mounting /dev in installroot")?;

let mut child = Command::new("/__antlir2__/dnf/driver")
.arg(&input)
.stdout(Stdio::piped())
Expand All @@ -344,6 +356,10 @@ fn run_dnf_driver(
events.push(event);
}
let result = child.wait().context("while waiting for dnf-driver")?;

nix::mount::umount2(&ctx.dst_path("/dev"), MntFlags::empty())
.context("while unmounting /dev from installroot")?;

if !result.success() {
Err(Error::msg("dnf-driver failed"))
} else {
Expand Down

0 comments on commit cf1be55

Please sign in to comment.