22// SPDX-License-Identifier: GPL-2.0-only
33
44use std:: net:: IpAddr ;
5- use std:: path:: Path ;
65use std:: { cell:: RefCell , env} ;
76
87extern crate rsinit;
98
10- use log:: { error , info} ;
9+ use log:: info;
1110use nix:: mount:: MsFlags ;
1211use rsinit:: cmdline:: CmdlineOptions ;
1312use rsinit:: mount:: do_mount;
@@ -24,38 +23,16 @@ fn main() -> Result<()> {
2423 // handout multiple mutable references in the callbacks.
2524 let mount_args = RefCell :: new ( MountArgs :: default ( ) ) ;
2625
27- // First option - pass callback object
2826 let callbacks = InitContextCallbacks {
29- cmdline_cb : vec ! [ ] ,
30- post_setup_cb : vec ! [ ] ,
31- post_root_mount_cb : vec ! [ Box :: new( |_| {
32- info!( "I'm lucky, I was the first callback to be added!" ) ;
33- info!(
34- "Let me show you the mounts collected so far: {:?}" ,
35- mount_args. borrow( )
36- ) ;
37- Ok ( ( ) )
27+ cmdline_cb : vec ! [ Box :: new( |key, value| {
28+ mount_args. borrow_mut( ) . parse_cmdline( key, value)
3829 } ) ] ,
30+ post_setup_cb : vec ! [ ] ,
31+ post_root_mount_cb : vec ! [ Box :: new( |ctx| mount_args. borrow( ) . do_mounts( ctx) ) ] ,
3932 } ;
4033
4134 let mut ctx = InitContext :: new ( Some ( callbacks) ) ?;
4235
43- // Second option - set callbacks via setter methods
44- ctx. add_post_setup_cb ( Box :: new ( |options| {
45- info ! (
46- "Beep, beep! Post setup callback running... I'll just print the options: {options:#?}"
47- ) ;
48- Ok ( ( ) )
49- } ) ) ;
50-
51- ctx. add_cmdline_cb ( Box :: new ( |key, value| {
52- mount_args. borrow_mut ( ) . parse_cmdline ( key, value)
53- } ) ) ;
54-
55- ctx. add_post_root_mount_cb ( Box :: new ( |ctx| mount_args. borrow ( ) . do_mounts ( ctx) ) ) ;
56-
57- setup_custom_stuff ( & mut ctx) ;
58-
5936 let cmd = env:: args ( ) . next ( ) . ok_or ( "No cmd to run as found" ) ?;
6037 println ! ( "Running {cmd}..." ) ;
6138
@@ -70,16 +47,6 @@ fn main() -> Result<()> {
7047 Ok ( ( ) )
7148}
7249
73- fn setup_custom_stuff ( init : & mut InitContext ) {
74- init. add_cmdline_cb ( Box :: new ( |key, value| {
75- if key == "custom.option" {
76- let val = ensure_value ( key, value) ?;
77- info ! ( "Custom option provided: {val}" ) ;
78- }
79- Ok ( ( ) )
80- } ) ) ;
81- }
82-
8350#[ derive( Debug , PartialEq ) ]
8451
8552struct MountOption {
0 commit comments