@@ -204,7 +204,12 @@ fn setup(
204
204
205
205
use_host_entropy ( ) . context ( "use host entropy" ) ?;
206
206
207
- for setup in & options. setup_script {
207
+ Ok ( ( ) )
208
+ }
209
+
210
+ fn run_setup_scripts ( scripts : & [ String ] ) -> anyhow:: Result < Vec < ( String , String ) > > {
211
+ let mut new_env = Vec :: new ( ) ;
212
+ for setup in scripts {
208
213
log:: info!( "Running provided setup script {}" , setup) ;
209
214
210
215
let result = Command :: new ( "/bin/sh" )
@@ -226,17 +231,18 @@ fn setup(
226
231
. and_then ( |line| line. split_once ( '=' ) )
227
232
{
228
233
log:: info!( "setting env var {}={}" , key, value) ;
229
- std :: env :: set_var ( key, value) ;
234
+ new_env . push ( ( key. into ( ) , value. into ( ) ) ) ;
230
235
}
231
236
}
232
237
}
233
- Ok ( ( ) )
238
+ Ok ( new_env )
234
239
}
235
240
236
- fn run ( options : & Options ) -> anyhow:: Result < ( ) > {
241
+ fn run ( options : & Options , env : impl IntoIterator < Item = ( String , String ) > ) -> anyhow:: Result < ( ) > {
237
242
let mut command = Command :: new ( UNDERHILL_PATH ) ;
238
243
command. arg ( "--pid" ) . arg ( "/run/underhill.pid" ) ;
239
244
command. args ( & options. underhill_args ) ;
245
+ command. envs ( env) ;
240
246
241
247
// Update the file descriptor limit for the main process, since large VMs
242
248
// require lots of fds. There is no downside to a larger value except that
@@ -423,7 +429,6 @@ fn timestamp() -> u64 {
423
429
424
430
fn do_main ( ) -> anyhow:: Result < ( ) > {
425
431
let boot_time = timestamp ( ) ;
426
- std:: env:: set_var ( "KERNEL_BOOT_TIME" , boot_time. to_string ( ) ) ;
427
432
428
433
init_logging ( ) ;
429
434
@@ -550,6 +555,8 @@ fn do_main() -> anyhow::Result<()> {
550
555
] ;
551
556
552
557
setup ( & stat_files, & options, writes, & filesystems) ?;
558
+ let mut new_env = run_setup_scripts ( & options. setup_script ) ?;
559
+ new_env. push ( ( "KERNEL_BOOT_TIME" . into ( ) , boot_time. to_string ( ) ) ) ;
553
560
554
561
if matches ! (
555
562
std:: env:: var( "OPENHCL_NVME_VFIO" ) . as_deref( ) ,
@@ -574,7 +581,7 @@ fn do_main() -> anyhow::Result<()> {
574
581
}
575
582
} ) ;
576
583
577
- run ( & options)
584
+ run ( & options, new_env )
578
585
}
579
586
580
587
pub fn main ( ) -> ! {
0 commit comments