Skip to content

Commit 3c86c5e

Browse files
authored
cuprated: disable STDIN if not terminal (#415)
* check terminal * await ctrl_c * add exit msg * rm
1 parent f60aa82 commit 3c86c5e

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

binaries/cuprated/src/main.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::{mem, sync::Arc};
2020

2121
use tokio::sync::mpsc;
2222
use tower::{Service, ServiceExt};
23-
use tracing::level_filters::LevelFilter;
23+
use tracing::{info, level_filters::LevelFilter};
2424
use tracing_subscriber::{layer::SubscriberExt, reload::Handle, util::SubscriberInitExt, Registry};
2525

2626
use cuprate_consensus_context::{
@@ -141,13 +141,19 @@ fn main() {
141141
.await;
142142

143143
// Start the command listener.
144-
let (command_tx, command_rx) = mpsc::channel(1);
145-
std::thread::spawn(|| commands::command_listener(command_tx));
144+
if std::io::IsTerminal::is_terminal(&std::io::stdin()) {
145+
let (command_tx, command_rx) = mpsc::channel(1);
146+
std::thread::spawn(|| commands::command_listener(command_tx));
146147

147-
// Wait on the io_loop, spawned on a separate task as this improves performance.
148-
tokio::spawn(commands::io_loop(command_rx, context_svc))
149-
.await
150-
.unwrap();
148+
// Wait on the io_loop, spawned on a separate task as this improves performance.
149+
tokio::spawn(commands::io_loop(command_rx, context_svc))
150+
.await
151+
.unwrap();
152+
} else {
153+
// If no STDIN, await OS exit signal.
154+
info!("Terminal/TTY not detected, disabling STDIN commands");
155+
tokio::signal::ctrl_c().await.unwrap();
156+
}
151157
});
152158
}
153159

0 commit comments

Comments
 (0)