@@ -150,6 +150,17 @@ pub fn exec(command: ExecCommand, uiclient: &dyn UiClient) -> anyhow::Result<()>
150
150
command. protonvpn_port_forwarding
151
151
} ;
152
152
153
+ // Create netns only
154
+ let create_netns_only = if !command. create_netns_only {
155
+ vopono_config_settings
156
+ . get ( "create-netns-only" )
157
+ . map_err ( |_e| anyhow ! ( "Failed to read config file" ) )
158
+ . ok ( )
159
+ . unwrap_or ( false )
160
+ } else {
161
+ command. create_netns_only
162
+ } ;
163
+
153
164
// Assign DNS server from args or vopono config file
154
165
let base_dns = command. dns . clone ( ) . or_else ( || {
155
166
vopono_config_settings
@@ -551,15 +562,6 @@ pub fn exec(command: ExecCommand, uiclient: &dyn UiClient) -> anyhow::Result<()>
551
562
vopono_core:: util:: open_ports ( & ns, & [ pmpc. local_port ] , firewall) ?;
552
563
}
553
564
554
- let application = ApplicationWrapper :: new (
555
- & ns,
556
- & command. application ,
557
- user,
558
- group,
559
- working_directory. map ( PathBuf :: from) ,
560
- natpmpc,
561
- ) ?;
562
-
563
565
// Launch TCP proxy server on other threads if forwarding ports
564
566
// TODO: Fix when running as root
565
567
let mut proxy = Vec :: new ( ) ;
@@ -580,27 +582,46 @@ pub fn exec(command: ExecCommand, uiclient: &dyn UiClient) -> anyhow::Result<()>
580
582
}
581
583
}
582
584
583
- let pid = application. handle . id ( ) ;
584
- info ! (
585
- "Application {} launched in network namespace {} with pid {}" ,
586
- & command. application, & ns. name, pid
587
- ) ;
585
+ if !create_netns_only {
586
+ let application = ApplicationWrapper :: new (
587
+ & ns,
588
+ & command. application ,
589
+ user,
590
+ group,
591
+ working_directory. map ( PathBuf :: from) ,
592
+ natpmpc,
593
+ ) ?;
588
594
589
- if let Some ( pmpc ) = application. protonvpn_port_forwarding . as_ref ( ) {
590
- info ! ( "ProtonVPN Port Forwarding on port {}" , pmpc . local_port )
591
- }
592
- let output = application. wait_with_output ( ) ? ;
593
- io :: stdout ( ) . write_all ( output . stdout . as_slice ( ) ) ? ;
595
+ let pid = application. handle . id ( ) ;
596
+ info ! (
597
+ "Application {} launched in network namespace {} with pid {}" ,
598
+ & command . application, & ns . name , pid
599
+ ) ;
594
600
595
- // Allow daemons to leave namespace open
596
- if vopono_core:: util:: check_process_running ( pid) {
601
+ if let Some ( pmpc) = application. protonvpn_port_forwarding . as_ref ( ) {
602
+ info ! ( "ProtonVPN Port Forwarding on port {}" , pmpc. local_port)
603
+ }
604
+ let output = application. wait_with_output ( ) ?;
605
+ io:: stdout ( ) . write_all ( output. stdout . as_slice ( ) ) ?;
606
+
607
+ // Allow daemons to leave namespace open
608
+ if vopono_core:: util:: check_process_running ( pid) {
609
+ info ! (
610
+ "Process {} still running, assumed to be daemon - will leave network namespace {} alive until ctrl+C received" ,
611
+ pid, & ns. name
612
+ ) ;
613
+ stay_alive ( Some ( pid) , signals) ;
614
+ } else if command. keep_alive {
615
+ info ! (
616
+ "Keep-alive flag active - will leave network namespace {} alive until ctrl+C received" , & ns. name
617
+ ) ;
618
+ stay_alive ( None , signals) ;
619
+ }
620
+ } else {
597
621
info ! (
598
- "Process {} still running, assumed to be daemon - will leave network namespace alive until ctrl+C received" ,
599
- pid
622
+ "Created netns {} - will leave network namespace alive until ctrl+C received" ,
623
+ & ns . name
600
624
) ;
601
- stay_alive ( Some ( pid) , signals) ;
602
- } else if command. keep_alive {
603
- info ! ( "Keep-alive flag active - will leave network namespace alive until ctrl+C received" ) ;
604
625
stay_alive ( None , signals) ;
605
626
}
606
627
0 commit comments