core: Fix tempetc guard to be no-op if /etc exists
This is further hardening to prevent a situation like https://github.com/coreos/rpm-ostree/issues/2771 where we would crash on an ostree-based host that has both `/etc` and `/usr/etc` as physical directories. That shouldn't happen after the bwrap fix, but we might as well be more correct here.
This commit is contained in:
parent
8758b0faa2
commit
a798175a85
@ -19,11 +19,12 @@ pub struct TempEtcGuard {
|
||||
renamed_etc: bool,
|
||||
}
|
||||
|
||||
/// Detect if we have /usr/etc and no /etc, and rename if so.
|
||||
pub(crate) fn prepare_tempetc_guard(rootfs: i32) -> CxxResult<Box<TempEtcGuard>> {
|
||||
let rootfs = ffi_view_openat_dir(rootfs);
|
||||
let has_usretc = rootfs.exists("usr/etc")?;
|
||||
let has_etc = rootfs.exists("etc")?;
|
||||
let mut renamed_etc = false;
|
||||
if has_usretc {
|
||||
if !has_etc && rootfs.exists("usr/etc")? {
|
||||
// In general now, we place contents in /etc when running scripts
|
||||
rootfs.local_rename("usr/etc", "etc")?;
|
||||
// But leave a compat symlink, as we used to bind mount, so scripts
|
||||
|
Loading…
Reference in New Issue
Block a user