@@ -444,7 +444,7 @@ impl ImageProxy {
444
444
} ;
445
445
446
446
// Verify semantic version
447
- let ( protover, _ ) : ( String , ( ) ) = r. impl_request ( "Initialize" , [ ( ) ; 0 ] ) . await ?;
447
+ let protover: String = r. impl_request_nofds ( "Initialize" , [ ( ) ; 0 ] ) . await ?;
448
448
tracing:: debug!( "Remote protocol version: {protover}" ) ;
449
449
let protover = semver:: Version :: parse ( protover. as_str ( ) ) ?;
450
450
// Previously we had a feature to opt-in to requiring newer versions using `if cfg!()`.
@@ -460,6 +460,7 @@ impl ImageProxy {
460
460
Ok ( r)
461
461
}
462
462
463
+ /// Create and send a request. Should only be used by impl_request.
463
464
async fn impl_request_raw < T : serde:: de:: DeserializeOwned + Send + ' static , F : FromReplyFds > (
464
465
sockfd : Arc < Mutex < OwnedFd > > ,
465
466
req : Request ,
@@ -509,6 +510,8 @@ impl ImageProxy {
509
510
Ok ( r)
510
511
}
511
512
513
+ /// Create a request that may return file descriptors, and also check for an unexpected
514
+ /// termination of the child process.
512
515
#[ instrument( skip( args) ) ]
513
516
async fn impl_request < T : serde:: de:: DeserializeOwned + Send + ' static , F : FromReplyFds > (
514
517
& self ,
@@ -527,6 +530,16 @@ impl ImageProxy {
527
530
}
528
531
}
529
532
533
+ /// A synchronous invocation which does not return any file descriptors.
534
+ async fn impl_request_nofds < T : serde:: de:: DeserializeOwned + Send + ' static > (
535
+ & self ,
536
+ method : & str ,
537
+ args : impl IntoIterator < Item = impl Into < serde_json:: Value > > ,
538
+ ) -> Result < T > {
539
+ let ( r, ( ) ) = self . impl_request ( method, args) . await ?;
540
+ Ok ( r)
541
+ }
542
+
530
543
#[ instrument]
531
544
async fn finish_pipe ( & self , pipeid : PipeId ) -> Result < ( ) > {
532
545
tracing:: debug!( "closing pipe" ) ;
@@ -537,14 +550,16 @@ impl ImageProxy {
537
550
#[ instrument]
538
551
pub async fn open_image ( & self , imgref : & str ) -> Result < OpenedImage > {
539
552
tracing:: debug!( "opening image" ) ;
540
- let ( imgid, ( ) ) = self . impl_request ( "OpenImage" , [ imgref] ) . await ?;
553
+ let imgid = self . impl_request_nofds ( "OpenImage" , [ imgref] ) . await ?;
541
554
Ok ( OpenedImage ( imgid) )
542
555
}
543
556
544
557
#[ instrument]
545
558
pub async fn open_image_optional ( & self , imgref : & str ) -> Result < Option < OpenedImage > > {
546
559
tracing:: debug!( "opening image" ) ;
547
- let ( imgid, ( ) ) = self . impl_request ( "OpenImageOptional" , [ imgref] ) . await ?;
560
+ let imgid = self
561
+ . impl_request_nofds ( "OpenImageOptional" , [ imgref] )
562
+ . await ?;
548
563
if imgid == 0 {
549
564
Ok ( None )
550
565
} else {
@@ -554,9 +569,7 @@ impl ImageProxy {
554
569
555
570
#[ instrument]
556
571
pub async fn close_image ( & self , img : & OpenedImage ) -> Result < ( ) > {
557
- tracing:: debug!( "closing image" ) ;
558
- let ( r, ( ) ) = self . impl_request ( "CloseImage" , [ img. 0 ] ) . await ?;
559
- Ok ( r)
572
+ self . impl_request_nofds ( "CloseImage" , [ img. 0 ] ) . await
560
573
}
561
574
562
575
async fn read_finish_pipe ( & self , pipe : FinishPipe ) -> Result < Vec < u8 > > {
@@ -714,7 +727,7 @@ impl ImageProxy {
714
727
if !layer_info_proto_version ( ) . matches ( & self . protover ) {
715
728
return Ok ( None ) ;
716
729
}
717
- let ( layers, ( ) ) = self . impl_request ( "GetLayerInfo" , [ img. 0 ] ) . await ?;
730
+ let layers = self . impl_request_nofds ( "GetLayerInfo" , [ img. 0 ] ) . await ?;
718
731
Ok ( Some ( layers) )
719
732
}
720
733
0 commit comments