Skip to content

Commit 84dec98

Browse files
Lethe10137BobAnkh
authored andcommitted
feat(cli): allow stdout/stderr in isolated mode
1 parent 05a34ac commit 84dec98

1 file changed

Lines changed: 44 additions & 4 deletions

File tree

src/main.rs

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use rattan_core::metal::io::af_packet::AfPacketDriver;
2020
use rattan_core::radix::RattanRadix;
2121
use rattan_core::{config::RattanConfig, radix::TaskResultNotify};
2222
use serde::{Deserialize, Serialize};
23+
use tracing::warn;
2324
use tracing_subscriber::Layer;
2425
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
2526

@@ -50,6 +51,22 @@ pub struct Arguments {
5051
#[arg(long, global = true)]
5152
generate: bool,
5253

54+
/// Used in isolated mode only. If set, stdout of left is passed to output of this program.
55+
#[arg(long, global = true)]
56+
left_stdout: bool,
57+
58+
/// Used in isolated mode only. If set, stdout of rihgt is passed to output of this program.
59+
#[arg(long, global = true)]
60+
right_stdout: bool,
61+
62+
/// Used in isolated mode only. If set, stderr of left is passed to output of this program.
63+
#[arg(long, global = true)]
64+
left_stderr: bool,
65+
66+
/// Used in isolated mode only. If set, stderr of right is passed to output of this program.
67+
#[arg(long, global = true)]
68+
right_stderr: bool,
69+
5370
/// Generate config file to the specified path instead of stdout
5471
#[arg(long, requires = "generate", global = true, value_name = "File")]
5572
generate_path: Option<PathBuf>,
@@ -345,6 +362,13 @@ fn main() -> ExitCode {
345362

346363
match radix.get_mode() {
347364
StdNetEnvMode::Compatible => {
365+
if opts.left_stdout | opts.left_stderr | opts.right_stdout | opts.right_stderr {
366+
warn!(
367+
"--left-stdout, --left-stderr, --right-stdout, --right-stderr \
368+
are for isolated mode only and thus ignored."
369+
);
370+
}
371+
348372
let ip_list = radix.right_ip_list();
349373
let left_handle = radix.left_spawn(None, move || {
350374
let mut client_handle = std::process::Command::new("/usr/bin/env");
@@ -416,8 +440,16 @@ fn main() -> ExitCode {
416440
tracing::info!("Running in right NS {server_handle:?}");
417441
let mut server_handle = server_handle
418442
.stdin(Stdio::null())
419-
.stdout(Stdio::null())
420-
.stderr(Stdio::null())
443+
.stdout(if opts.right_stdout {
444+
Stdio::inherit()
445+
} else {
446+
Stdio::null()
447+
})
448+
.stderr(if opts.right_stderr {
449+
Stdio::inherit()
450+
} else {
451+
Stdio::null()
452+
})
421453
.spawn()?;
422454
let pid = server_handle.id() as i32;
423455
tracing::debug!("Right pid: {pid}");
@@ -440,8 +472,16 @@ fn main() -> ExitCode {
440472
tracing::info!("Running in left NS {client_handle:?}");
441473
let mut client_handle = client_handle
442474
.stdin(Stdio::null())
443-
.stdout(Stdio::null())
444-
.stderr(Stdio::null())
475+
.stdout(if opts.left_stdout {
476+
Stdio::inherit()
477+
} else {
478+
Stdio::null()
479+
})
480+
.stderr(if opts.left_stderr {
481+
Stdio::inherit()
482+
} else {
483+
Stdio::null()
484+
})
445485
.spawn()?;
446486
let pid = client_handle.id() as i32;
447487
tracing::debug!("Left pid: {pid}");

0 commit comments

Comments
 (0)