@@ -25,6 +25,22 @@ use rustix::process::{getrlimit, setrlimit, Resource};
2525
2626const KRUN_CONFIG : & str = "KRUN_CONFIG" ;
2727
28+ fn parse_config ( config_path : String ) -> Result < GuestConfiguration > {
29+ let mut config_file = File :: open ( & config_path) ?;
30+ let mut config_buf = Vec :: new ( ) ;
31+ config_file. read_to_end ( & mut config_buf) ?;
32+ fs:: remove_file ( config_path) . context ( "Unable to delete temporary muvm configuration file" ) ?;
33+ if let Ok ( krun_config_path) = env:: var ( KRUN_CONFIG ) {
34+ fs:: remove_file ( krun_config_path)
35+ . context ( "Unable to delete temporary krun configuration file" ) ?;
36+ // SAFETY: We are single-threaded at this point
37+ env:: remove_var ( KRUN_CONFIG ) ;
38+ }
39+ // SAFETY: We are single-threaded at this point
40+ env:: remove_var ( "KRUN_WORKDIR" ) ;
41+ Ok ( serde_json:: from_slice :: < GuestConfiguration > ( & config_buf) ?)
42+ }
43+
2844fn main ( ) -> Result < ( ) > {
2945 env_logger:: init ( ) ;
3046
@@ -38,9 +54,13 @@ fn main() -> Result<()> {
3854 } ,
3955 "muvm-remote" => {
4056 let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
41- let mut command_args = env:: args ( ) . skip ( 1 ) ;
42- let command = command_args. next ( ) . context ( "command name" ) ?;
43- return rt. block_on ( server_main ( PathBuf :: from ( command) , command_args. collect ( ) ) ) ;
57+ let config_path =
58+ env:: var ( "MUVM_REMOTE_CONFIG" ) . context ( "expected MUVM_REMOTE_CONFIG to be set" ) ?;
59+ let options = parse_config ( config_path) ?;
60+ return rt. block_on ( server_main (
61+ options. command . command ,
62+ options. command . command_args ,
63+ ) ) ;
4464 } ,
4565 _ => { /* continue with all-in-one mode */ } ,
4666 }
@@ -53,19 +73,7 @@ fn main() -> Result<()> {
5373 let config_path = env:: args ( )
5474 . nth ( 1 )
5575 . context ( "expected configuration file path" ) ?;
56- let mut config_file = File :: open ( & config_path) ?;
57- let mut config_buf = Vec :: new ( ) ;
58- config_file. read_to_end ( & mut config_buf) ?;
59- fs:: remove_file ( config_path) . context ( "Unable to delete temporary muvm configuration file" ) ?;
60- if let Ok ( krun_config_path) = env:: var ( KRUN_CONFIG ) {
61- fs:: remove_file ( krun_config_path)
62- . context ( "Unable to delete temporary krun configuration file" ) ?;
63- // SAFETY: We are single-threaded at this point
64- env:: remove_var ( KRUN_CONFIG ) ;
65- }
66- // SAFETY: We are single-threaded at this point
67- env:: remove_var ( "KRUN_WORKDIR" ) ;
68- let options = serde_json:: from_slice :: < GuestConfiguration > ( & config_buf) ?;
76+ let options = parse_config ( config_path) ?;
6977
7078 {
7179 const ESYNC_RLIMIT_NOFILE : u64 = 524288 ;
0 commit comments