3434 */ 
3535
3636use  std:: { 
37+     collections:: HashMap , 
3738    path:: { Path ,  PathBuf } , 
3839    sync:: Arc , 
3940    time:: Duration , 
@@ -203,64 +204,60 @@ impl GlobalOpts {
203204        self . args ( ) 
204205    } 
205206
206-     fn  output ( & self )  -> Result < ( PathBuf ,  Vec < String > ) ,  Error >  { 
207+     fn  output ( & self )  -> Result < ( PathBuf ,  HashMap < String ,   String > ) ,  Error >  { 
207208        let  path = self 
208209            . command 
209210            . clone ( ) 
210211            . unwrap_or_else ( || PathBuf :: from ( "runc" ) ) ; 
211212
212213        let  command = utils:: binary_path ( path) . ok_or ( Error :: NotFound ) ?; 
213- 
214-         let  mut  args = Vec :: new ( ) ; 
214+         let  mut  global_args_map = HashMap :: < String ,  String > :: new ( ) ; 
215215
216216        // --root path : Set the root directory to store containers' state. 
217217        if  let  Some ( root)  = & self . root  { 
218-             args. push ( ROOT . into ( ) ) ; 
219-             args. push ( utils:: abs_string ( root) ?) ; 
218+             global_args_map. insert ( ROOT . into ( ) ,  utils:: abs_string ( root) ?) ; 
220219        } 
221220
222221        // --debug : Enable debug logging. 
223222        if  self . debug  { 
224-             args . push ( DEBUG . into ( ) ) ; 
223+             global_args_map . insert ( DEBUG . into ( ) ,   String :: new ( ) ) ; 
225224        } 
226225
227226        // --log path : Set the log destination to path. The default is to log to stderr. 
228227        if  let  Some ( log_path)  = & self . log  { 
229-             args. push ( LOG . into ( ) ) ; 
230-             args. push ( utils:: abs_string ( log_path) ?) ; 
228+             global_args_map. insert ( LOG . into ( ) ,  utils:: abs_string ( log_path) ?) ; 
231229        } 
232230
233231        // --log-format text|json : Set the log format (default is text). 
234-         args. push ( LOG_FORMAT . into ( ) ) ; 
235-         args. push ( self . log_format . to_string ( ) ) ; 
232+         global_args_map. insert ( LOG_FORMAT . into ( ) ,  self . log_format . to_string ( ) ) ; 
236233
237234        // --systemd-cgroup : Enable systemd cgroup support. 
238235        if  self . systemd_cgroup  { 
239-             args . push ( SYSTEMD_CGROUP . into ( ) ) ; 
236+             global_args_map . insert ( SYSTEMD_CGROUP . into ( ) ,   String :: new ( ) ) ; 
240237        } 
241238
242239        // --rootless true|false|auto : Enable or disable rootless mode. 
243240        if  let  Some ( mode)  = self . rootless  { 
244-             let  arg = format ! ( "{}={}" ,  ROOTLESS ,  mode) ; 
245-             args. push ( arg) ; 
241+             global_args_map. insert ( ROOTLESS . to_string ( ) ,  mode. to_string ( ) ) ; 
246242        } 
247-         Ok ( ( command,  args ) ) 
243+         Ok ( ( command,  global_args_map ) ) 
248244    } 
249245} 
250246
251247impl  Args  for  GlobalOpts  { 
252248    type  Output  = Result < Runc ,  Error > ; 
253249
254250    fn  args ( & self )  -> Self :: Output  { 
255-         let  ( command,  args )  = self . output ( ) ?; 
251+         let  ( command,  client_global_args )  = self . output ( ) ?; 
256252        let  executor = if  let  Some ( exec)  = self . executor . clone ( )  { 
257253            exec
258254        }  else  { 
259255            Arc :: new ( DefaultExecutor  { } ) 
260256        } ; 
257+ 
261258        Ok ( Runc  { 
262259            command, 
263-             args , 
260+             client_global_args , 
264261            spawner :  executor, 
265262        } ) 
266263    } 
@@ -353,6 +350,7 @@ impl CreateOpts {
353350#[ derive( Clone ,  Default ) ]  
354351pub  struct  ExecOpts  { 
355352    pub  io :  Option < Arc < dyn  Io > > , 
353+     pub  global_args :  HashMap < String ,  String > , 
356354    /// Path to where a pid file should be created. 
357355     pub  pid_file :  Option < PathBuf > , 
358356    /// Path to where a console socket should be created. 
@@ -591,19 +589,30 @@ mod tests {
591589        assert_eq ! ( KillOpts :: new( ) . all( true ) . args( ) ,  vec![ "--all" . to_string( ) ] , ) ; 
592590    } 
593591
592+     #[ allow( dead_code) ]  
593+     fn  map_to_vec ( map :  HashMap < String ,  String > )  -> Vec < String >  { 
594+         let  mut  args = Vec :: with_capacity ( map. len ( )  *  2 ) ; 
595+         for  ( key,  value)  in  map { 
596+             args. push ( key) ; 
597+             args. push ( value) ; 
598+         } 
599+         args
600+     } 
594601    #[ cfg( target_os = "linux" ) ]  
595602    #[ test]  
596603    fn  global_opts_test ( )  { 
597604        let  cfg = GlobalOpts :: default ( ) . command ( "true" ) ; 
598605        let  runc = cfg. build ( ) . unwrap ( ) ; 
599-         let  args = & runc. args ; 
606+         let  args_map = & runc. client_global_args ; 
607+ 
608+         let  args = map_to_vec ( args_map. clone ( ) ) ; 
600609        assert_eq ! ( args. len( ) ,  2 ) ; 
601610        assert ! ( args. contains( & LOG_FORMAT . to_string( ) ) ) ; 
602611        assert ! ( args. contains( & TEXT . to_string( ) ) ) ; 
603612
604613        let  cfg = GlobalOpts :: default ( ) . command ( "/bin/true" ) ; 
605614        let  runc = cfg. build ( ) . unwrap ( ) ; 
606-         assert_eq ! ( runc. args . len( ) ,  2 ) ; 
615+         assert_eq ! ( map_to_vec ( runc. client_global_args ) . len( ) ,  2 ) ; 
607616
608617        let  cfg = GlobalOpts :: default ( ) 
609618            . command ( "true" ) 
@@ -614,16 +623,17 @@ mod tests {
614623            . systemd_cgroup ( true ) 
615624            . rootless ( true ) ; 
616625        let  runc = cfg. build ( ) . unwrap ( ) ; 
617-         let  args = & runc. args ; 
626+         let  args = map_to_vec ( runc. client_global_args ) ; 
618627        assert ! ( args. contains( & ROOT . to_string( ) ) ) ; 
619628        assert ! ( args. contains( & DEBUG . to_string( ) ) ) ; 
620629        assert ! ( args. contains( & "/tmp" . to_string( ) ) ) ; 
621630        assert ! ( args. contains( & LOG . to_string( ) ) ) ; 
622631        assert ! ( args. contains( & "/tmp/runc.log" . to_string( ) ) ) ; 
623632        assert ! ( args. contains( & LOG_FORMAT . to_string( ) ) ) ; 
624633        assert ! ( args. contains( & JSON . to_string( ) ) ) ; 
625-         assert ! ( args. contains( & "--rootless=true" . to_string( ) ) ) ; 
634+ 
635+         assert ! ( args. contains( & "--rootless" . to_string( ) ) ) ; 
626636        assert ! ( args. contains( & SYSTEMD_CGROUP . to_string( ) ) ) ; 
627-         assert_eq ! ( args. len( ) ,  9 ) ; 
637+         assert_eq ! ( args. len( ) ,  12 ) ; 
628638    } 
629639} 
0 commit comments