@@ -2,7 +2,6 @@ use std::fs::File;
22use std:: io:: Read ;
33use std:: os:: fd:: AsFd ;
44use std:: panic:: catch_unwind;
5- use std:: path:: PathBuf ;
65use std:: process:: { Command , ExitCode } ;
76use std:: { cmp, env, fs, thread} ;
87
@@ -25,22 +24,42 @@ use rustix::process::{getrlimit, setrlimit, Resource};
2524
2625const KRUN_CONFIG : & str = "KRUN_CONFIG" ;
2726
27+ fn parse_config ( config_path : String ) -> Result < GuestConfiguration > {
28+ let mut config_file = File :: open ( & config_path) ?;
29+ let mut config_buf = Vec :: new ( ) ;
30+ config_file. read_to_end ( & mut config_buf) ?;
31+ fs:: remove_file ( config_path) . context ( "Unable to delete temporary muvm configuration file" ) ?;
32+ if let Ok ( krun_config_path) = env:: var ( KRUN_CONFIG ) {
33+ fs:: remove_file ( krun_config_path)
34+ . context ( "Unable to delete temporary krun configuration file" ) ?;
35+ // SAFETY: We are single-threaded at this point
36+ env:: remove_var ( KRUN_CONFIG ) ;
37+ }
38+ // SAFETY: We are single-threaded at this point
39+ env:: remove_var ( "KRUN_WORKDIR" ) ;
40+ Ok ( serde_json:: from_slice :: < GuestConfiguration > ( & config_buf) ?)
41+ }
42+
2843fn main ( ) -> Result < ExitCode > {
2944 env_logger:: init ( ) ;
3045
3146 let binary_path = env:: args ( ) . next ( ) . context ( "arg0" ) ?;
3247 let bb = binary_path. split ( '/' ) . next_back ( ) . context ( "arg0 split" ) ?;
3348 match bb {
34- "muvm-configure-network" => return configure_network ( ) ,
49+ "muvm-configure-network" => return configure_network ( ) . map ( | ( ) | ExitCode :: SUCCESS ) ,
3550 "muvm-pwbridge" => {
3651 bridge_loop_with_listenfd :: < PipeWireProtocolHandler > ( pipewire_sock_path) ;
37- return Ok ( ( ) ) ;
52+ return Ok ( ExitCode :: SUCCESS ) ;
3853 } ,
3954 "muvm-remote" => {
4055 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 ( ) ) ) ;
56+ let config_path =
57+ env:: var ( "MUVM_REMOTE_CONFIG" ) . context ( "expected MUVM_REMOTE_CONFIG to be set" ) ?;
58+ let options = parse_config ( config_path) ?;
59+ return rt. block_on ( server_main (
60+ options. command . command ,
61+ options. command . command_args ,
62+ ) ) ;
4463 } ,
4564 _ => { /* continue with all-in-one mode */ } ,
4665 }
@@ -53,19 +72,7 @@ fn main() -> Result<ExitCode> {
5372 let config_path = env:: args ( )
5473 . nth ( 1 )
5574 . 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) ?;
75+ let options = parse_config ( config_path) ?;
6976
7077 {
7178 const ESYNC_RLIMIT_NOFILE : u64 = 524288 ;
0 commit comments