@@ -12,9 +12,7 @@ pub(crate) mod osconfig;
1212
1313use std:: io:: Write ;
1414use std:: os:: fd:: AsFd ;
15- use std:: os:: unix:: process:: CommandExt ;
1615use std:: path:: Path ;
17- use std:: process:: Command ;
1816use std:: str:: FromStr ;
1917use std:: sync:: Arc ;
2018use std:: time:: Duration ;
@@ -40,6 +38,7 @@ use serde::{Deserialize, Serialize};
4038
4139use self :: baseline:: InstallBlockDeviceOpts ;
4240use crate :: containerenv:: ContainerExecutionInfo ;
41+ use crate :: hostexec:: run_in_host_mountns;
4342use crate :: mount:: Filesystem ;
4443use crate :: task:: Task ;
4544use crate :: utils:: sigpolicy_from_opts;
@@ -727,35 +726,6 @@ async fn initialize_ostree_root_from_self(
727726 Ok ( aleph)
728727}
729728
730- /// Run a command in the host mount namespace
731- pub ( crate ) fn run_in_host_mountns ( cmd : & str ) -> Command {
732- let mut c = Command :: new ( "/proc/self/exe" ) ;
733- c. args ( [ "exec-in-host-mount-namespace" , cmd] ) ;
734- c
735- }
736-
737- #[ context( "Re-exec in host mountns" ) ]
738- pub ( crate ) fn exec_in_host_mountns ( args : & [ std:: ffi:: OsString ] ) -> Result < ( ) > {
739- let ( cmd, args) = args
740- . split_first ( )
741- . ok_or_else ( || anyhow:: anyhow!( "Missing command" ) ) ?;
742- tracing:: trace!( "{cmd:?} {args:?}" ) ;
743- let pid1mountns = std:: fs:: File :: open ( "/proc/1/ns/mnt" ) . context ( "open pid1 mountns" ) ?;
744- nix:: sched:: setns ( pid1mountns. as_fd ( ) , nix:: sched:: CloneFlags :: CLONE_NEWNS ) . context ( "setns" ) ?;
745- rustix:: process:: chdir ( "/" ) . context ( "chdir" ) ?;
746- // Work around supermin doing chroot() and not pivot_root
747- // https://github.com/libguestfs/supermin/blob/5230e2c3cd07e82bd6431e871e239f7056bf25ad/init/init.c#L288
748- if !Utf8Path :: new ( "/usr" ) . try_exists ( ) . context ( "/usr" ) ?
749- && Utf8Path :: new ( "/root/usr" )
750- . try_exists ( )
751- . context ( "/root/usr" ) ?
752- {
753- tracing:: debug!( "Using supermin workaround" ) ;
754- rustix:: process:: chroot ( "/root" ) . context ( "chroot" ) ?;
755- }
756- Err ( Command :: new ( cmd) . args ( args) . exec ( ) ) . context ( "exec" ) ?
757- }
758-
759729#[ context( "Querying skopeo version" ) ]
760730fn require_skopeo_with_containers_storage ( ) -> Result < ( ) > {
761731 let out = Task :: new_cmd ( "skopeo --version" , run_in_host_mountns ( "skopeo" ) )
0 commit comments