@@ -2533,37 +2533,32 @@ pub enum CommanderError {
2533
2533
}
2534
2534
2535
2535
#[ derive( Debug ) ]
2536
- pub struct TerminateContainer ( Option < Command > ) ;
2536
+ pub struct TerminateContainer ( Option < ( String , Command ) > ) ;
2537
2537
2538
2538
impl TerminateContainer {
2539
- pub fn new ( command : Command ) -> Self {
2540
- Self ( Some ( command) )
2539
+ pub fn new ( name : String , command : Command ) -> Self {
2540
+ Self ( Some ( ( name , command) ) )
2541
2541
}
2542
2542
2543
2543
pub fn none ( ) -> Self {
2544
2544
Self ( None )
2545
2545
}
2546
2546
2547
2547
async fn terminate_now ( & mut self ) -> Result < ( ) , TerminateContainerError > {
2548
- if let Some ( mut kill_child) = self . take_command ( ) {
2549
- let o = kill_child. output ( ) . await ?;
2550
- Self :: report_failure ( o) ;
2548
+ use terminate_container_error:: * ;
2549
+
2550
+ if let Some ( ( name, mut kill_child) ) = self . 0 . take ( ) {
2551
+ let o = kill_child
2552
+ . output ( )
2553
+ . await
2554
+ . context ( TerminateContainerSnafu { name : & name } ) ?;
2555
+ Self :: report_failure ( name, o) ;
2551
2556
}
2552
2557
2553
2558
Ok ( ( ) )
2554
2559
}
2555
2560
2556
- fn take_command ( & mut self ) -> Option < Command > {
2557
- self . 0 . take ( ) . map ( |mut kill_child| {
2558
- kill_child
2559
- . stdin ( Stdio :: null ( ) )
2560
- . stdout ( Stdio :: null ( ) )
2561
- . stderr ( Stdio :: null ( ) ) ;
2562
- kill_child
2563
- } )
2564
- }
2565
-
2566
- fn report_failure ( s : std:: process:: Output ) {
2561
+ fn report_failure ( name : String , s : std:: process:: Output ) {
2567
2562
// We generally don't care if the command itself succeeds or
2568
2563
// not; the container may already be dead! However, let's log
2569
2564
// it in an attempt to debug cases where there are more
@@ -2575,28 +2570,28 @@ impl TerminateContainer {
2575
2570
let stdout = String :: from_utf8_lossy ( & s. stdout ) ;
2576
2571
let stderr = String :: from_utf8_lossy ( & s. stderr ) ;
2577
2572
2578
- error ! ( ?code, %stdout, %stderr, "Killing the container failed" ) ;
2573
+ error ! ( ?code, %stdout, %stderr, %name , "Killing the container failed" ) ;
2579
2574
}
2580
2575
}
2581
2576
}
2582
2577
2583
2578
impl Drop for TerminateContainer {
2584
2579
fn drop ( & mut self ) {
2585
- if let Some ( mut kill_child) = self . take_command ( ) {
2580
+ if let Some ( ( name , mut kill_child) ) = self . 0 . take ( ) {
2586
2581
match kill_child. as_std_mut ( ) . output ( ) {
2587
- Ok ( o) => Self :: report_failure ( o) ,
2588
- Err ( e) => error ! ( "Unable to kill the container while dropping: {e}" ) ,
2582
+ Ok ( o) => Self :: report_failure ( name , o) ,
2583
+ Err ( e) => error ! ( "Unable to kill container {name} while dropping: {e}" ) ,
2589
2584
}
2590
2585
}
2591
2586
}
2592
2587
}
2593
2588
2594
2589
#[ derive( Debug , Snafu ) ]
2595
2590
#[ snafu( module) ]
2596
- pub enum TerminateContainerError {
2597
- # [ snafu ( display ( "Unable to kill the child process" ) ) ]
2598
- # [ snafu ( context ( false ) ) ]
2599
- Execute { source : std:: io:: Error } ,
2591
+ # [ snafu ( display ( "Unable to kill the Docker container {name}" ) ) ]
2592
+ pub struct TerminateContainerError {
2593
+ name : String ,
2594
+ source : std:: io:: Error ,
2600
2595
}
2601
2596
2602
2597
pub trait Backend {
@@ -2710,8 +2705,8 @@ impl Backend for DockerBackend {
2710
2705
. arg ( "/playground" ) ;
2711
2706
2712
2707
let mut kill = Command :: new ( "docker" ) ;
2713
- kill. arg ( "kill" ) . args ( [ "--signal" , "KILL" ] ) . arg ( name) ;
2714
- let kill = TerminateContainer :: new ( kill) ;
2708
+ kill. arg ( "kill" ) . args ( [ "--signal" , "KILL" ] ) . arg ( & name) ;
2709
+ let kill = TerminateContainer :: new ( name , kill) ;
2715
2710
2716
2711
( command, kill)
2717
2712
}
0 commit comments