@@ -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
@@ -26,16 +25,32 @@ use rustix::process::{getrlimit, setrlimit, Resource};
2625
2726const KRUN_CONFIG : & str = "KRUN_CONFIG" ;
2827
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+
2944fn main ( ) -> Result < ExitCode > {
3045 env_logger:: init ( ) ;
3146
3247 let binary_path = env:: args ( ) . next ( ) . context ( "arg0" ) ?;
3348 let bb = binary_path. split ( '/' ) . next_back ( ) . context ( "arg0 split" ) ?;
3449 match bb {
35- "muvm-configure-network" => return configure_network ( ) ,
50+ "muvm-configure-network" => return configure_network ( ) . map ( | ( ) | ExitCode :: SUCCESS ) ,
3651 "muvm-pwbridge" => {
3752 bridge_loop_with_listenfd :: < PipeWireProtocolHandler > ( pipewire_sock_path) ;
38- return Ok ( ( ) ) ;
53+ return Ok ( ExitCode :: SUCCESS ) ;
3954 } ,
4055 "muvm-x11bridge" => {
4156 bridge_loop_with_listenfd :: < X11ProtocolHandler > ( || "/tmp/.X11-unix/X1" . to_owned ( ) ) ;
@@ -51,9 +66,13 @@ fn main() -> Result<ExitCode> {
5166 } ,
5267 "muvm-remote" => {
5368 let rt = tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ;
54- let mut command_args = env:: args ( ) . skip ( 1 ) ;
55- let command = command_args. next ( ) . context ( "command name" ) ?;
56- return rt. block_on ( server_main ( PathBuf :: from ( command) , command_args. collect ( ) ) ) ;
69+ let config_path =
70+ env:: var ( "MUVM_REMOTE_CONFIG" ) . context ( "expected MUVM_REMOTE_CONFIG to be set" ) ?;
71+ let options = parse_config ( config_path) ?;
72+ return rt. block_on ( server_main (
73+ options. command . command ,
74+ options. command . command_args ,
75+ ) ) ;
5776 } ,
5877 _ => { /* continue with all-in-one mode */ } ,
5978 }
@@ -66,19 +85,7 @@ fn main() -> Result<ExitCode> {
6685 let config_path = env:: args ( )
6786 . nth ( 1 )
6887 . context ( "expected configuration file path" ) ?;
69- let mut config_file = File :: open ( & config_path) ?;
70- let mut config_buf = Vec :: new ( ) ;
71- config_file. read_to_end ( & mut config_buf) ?;
72- fs:: remove_file ( config_path) . context ( "Unable to delete temporary muvm configuration file" ) ?;
73- if let Ok ( krun_config_path) = env:: var ( KRUN_CONFIG ) {
74- fs:: remove_file ( krun_config_path)
75- . context ( "Unable to delete temporary krun configuration file" ) ?;
76- // SAFETY: We are single-threaded at this point
77- env:: remove_var ( KRUN_CONFIG ) ;
78- }
79- // SAFETY: We are single-threaded at this point
80- env:: remove_var ( "KRUN_WORKDIR" ) ;
81- let options = serde_json:: from_slice :: < GuestConfiguration > ( & config_buf) ?;
88+ let options = parse_config ( config_path) ?;
8289
8390 {
8491 const ESYNC_RLIMIT_NOFILE : u64 = 524288 ;
0 commit comments