This repository was archived by the owner on Jan 15, 2025. It is now read-only.
File tree 4 files changed +18
-12
lines changed
4 files changed +18
-12
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,7 @@ hex = "0.4.3"
24
24
indicatif = " 0.16.0"
25
25
once_cell = " 1.9"
26
26
libc = " 0.2.92"
27
- nix = " 0.23 "
27
+ rustix = " 0.31.3 "
28
28
oci-spec = " 0.5.0"
29
29
openat = " 0.1.20"
30
30
openat-ext = " 0.2.0"
Original file line number Diff line number Diff line change 1
- use std:: os:: unix:: prelude:: { CommandExt , RawFd } ;
1
+ use rustix:: fd:: { FromRawFd , IntoRawFd } ;
2
+ use rustix:: io:: OwnedFd ;
3
+ use std:: os:: unix:: prelude:: CommandExt ;
4
+ use std:: sync:: Arc ;
2
5
3
6
pub ( crate ) trait CommandRedirectionExt {
4
7
/// Pass a file descriptor into the target process.
5
- /// IMPORTANT: `fd` must be valid (i.e. cannot be closed) until after [`std::Process::Command::spawn`] or equivalent is invoked.
6
- fn take_fd_n ( & mut self , fd : i32 , target : i32 ) -> & mut Self ;
8
+ fn take_fd_n ( & mut self , fd : Arc < OwnedFd > , target : i32 ) -> & mut Self ;
7
9
}
8
10
9
11
#[ allow( unsafe_code) ]
10
12
impl CommandRedirectionExt for std:: process:: Command {
11
- fn take_fd_n ( & mut self , fd : i32 , target : i32 ) -> & mut Self {
13
+ fn take_fd_n ( & mut self , fd : Arc < OwnedFd > , target : i32 ) -> & mut Self {
12
14
unsafe {
13
15
self . pre_exec ( move || {
14
- nix:: unistd:: dup2 ( fd, target as RawFd )
15
- . map ( |_r| ( ) )
16
- . map_err ( |e| std:: io:: Error :: new ( std:: io:: ErrorKind :: Other , format ! ( "{}" , e) ) )
16
+ let target = rustix:: io:: OwnedFd :: from_raw_fd ( target) ;
17
+ rustix:: io:: dup2 ( & * fd, & target) ?;
18
+ // Intentionally leak into the child.
19
+ let _ = target. into_raw_fd ( ) ;
20
+ Ok ( ( ) )
17
21
} ) ;
18
22
}
19
23
self
Original file line number Diff line number Diff line change @@ -169,8 +169,8 @@ impl<'a> OciWriter<'a> {
169
169
170
170
#[ context( "Writing OCI" ) ]
171
171
pub ( crate ) fn complete ( self ) -> Result < ( ) > {
172
- let utsname = nix :: sys :: utsname :: uname ( ) ;
173
- let machine = utsname . machine ( ) ;
172
+ let uname = rustix :: process :: uname ( ) ;
173
+ let machine = uname . machine ( ) . to_str ( ) . unwrap ( ) ;
174
174
let arch = MACHINE_TO_OCI . get ( machine) . unwrap_or ( & machine) ;
175
175
let arch = oci_image:: Arch :: from ( * arch) ;
176
176
Original file line number Diff line number Diff line change @@ -13,12 +13,13 @@ use anyhow::{anyhow, Context};
13
13
use camino:: { Utf8Component , Utf8Path , Utf8PathBuf } ;
14
14
use ostree:: gio;
15
15
use ostree:: prelude:: FileExt ;
16
+ use rustix:: fd:: FromFd ;
16
17
use std:: collections:: BTreeMap ;
17
18
use std:: convert:: TryInto ;
18
19
use std:: io:: { BufWriter , Write } ;
19
- use std:: os:: unix:: prelude:: AsRawFd ;
20
20
use std:: path:: Path ;
21
21
use std:: process:: Stdio ;
22
+ use std:: sync:: Arc ;
22
23
use tokio:: io:: { AsyncRead , AsyncReadExt , AsyncWrite } ;
23
24
use tracing:: instrument;
24
25
@@ -197,13 +198,14 @@ pub async fn write_tar(
197
198
} ;
198
199
let mut c = std:: process:: Command :: new ( "ostree" ) ;
199
200
let repofd = repo. dfd_as_file ( ) ?;
201
+ let repofd = Arc :: new ( rustix:: io:: OwnedFd :: from_into_fd ( repofd) ) ;
200
202
{
201
203
let c = c
202
204
. stdin ( Stdio :: piped ( ) )
203
205
. stdout ( Stdio :: piped ( ) )
204
206
. stderr ( Stdio :: piped ( ) )
205
207
. args ( & [ "commit" ] ) ;
206
- c. take_fd_n ( repofd. as_raw_fd ( ) , 3 ) ;
208
+ c. take_fd_n ( repofd. clone ( ) , 3 ) ;
207
209
c. arg ( "--repo=/proc/self/fd/3" ) ;
208
210
if let Some ( sepolicy) = sepolicy. as_ref ( ) {
209
211
c. arg ( "--selinux-policy" ) ;
You can’t perform that action at this time.
0 commit comments