From 1ca69673f5b29977677b7e49571650f32e0879f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=CE=A3rebe=20-=20Romain=20GERARD?= Date: Sun, 15 Oct 2023 21:02:54 +0200 Subject: [PATCH] Disable stdio for non unix Former-commit-id: 9517420cf008ad68394c6f165c2854fa953027f8 [formerly 2f040f62537bfc2c720fac154d01da5025653d2f] [formerly 092cf2ee3cc7802316f45fd5d365d4eea26f4a70 [formerly 95539ed457c1a4370d476ae65feaf8c886bda618]] Former-commit-id: 0287c62a86569d98886dfab52f069bf23baee92b [formerly 36e646d84a645a2f57715c80ae5c481c31c721b4] Former-commit-id: 13fe8829cbd6c6af7712af0a13d52e4f21f3446c Former-commit-id: 0b9a49925044d3d5b74d1e661cd0f179db93d8b8 Former-commit-id: fe0919c17783cde0d5d9af3ca5f63c7eb24044c5 Former-commit-id: 0dcce5ab0bc07b76095d097149b8d434578ded15 [formerly 5ab64e56d05f73f5f79dab98c621cc3c34407840] Former-commit-id: ca56d5ac22971711babeb12cc1aac0889a464b1d --- Cargo.toml | 3 ++- src/main.rs | 36 ++++++++++++++++++++++-------------- src/stdio.rs | 8 -------- 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b5735b..e7ad84c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,6 @@ rustls-native-certs = { version = "0.6.3", features = [] } tokio = { version = "1.32.0", features = ["full"] } tokio-rustls = { version = "0.24.1", features = ["tls12", "dangerous_configuration", "early-data"] } tokio-stream = { version = "0.1.14", features = ["net"] } -tokio-fd = "0.3.0" futures-util = { version = "0.3.28" } tracing = { version = "0.1.37", features = ["log"] } @@ -34,6 +33,8 @@ tracing-subscriber = { version = "0.3.17", features = ["env-filter", "fmt", "loc base64 = "0.21.4" serde = { version = "1.0.188", features = ["derive"] } +[target.'cfg(target_family = "unix")'.dependencies] +tokio-fd = "0.3.0" [profile.release] diff --git a/src/main.rs b/src/main.rs index 17c5050..939fb1c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,5 @@ mod embedded_certificate; +#[cfg(target_family = "unix")] mod stdio; mod tcp; mod tls; @@ -502,20 +503,27 @@ async fn main() { }); } L4Protocol::Stdio => { - let server = stdio::run_server().await.unwrap_or_else(|err| { - panic!("Cannot start STDIO server: {}", err); - }); - tokio::spawn(async move { - if let Err(err) = run_tunnel( - server_config, - tunnel, - stream::once(async move { Ok(server) }), - ) - .await - { - error!("{:?}", err); - } - }); + #[cfg(target_family = "unix")] + { + let server = stdio::run_server().await.unwrap_or_else(|err| { + panic!("Cannot start STDIO server: {}", err); + }); + tokio::spawn(async move { + if let Err(err) = run_tunnel( + server_config, + tunnel, + stream::once(async move { Ok(server) }), + ) + .await + { + error!("{:?}", err); + } + }); + } + #[cfg(not(target_family = "unix"))] + { + panic!("stdio is not implemented for non unix platform") + } } } } diff --git a/src/stdio.rs b/src/stdio.rs index 7403ea0..26cfed9 100644 --- a/src/stdio.rs +++ b/src/stdio.rs @@ -1,11 +1,3 @@ -#![allow(unused_imports)] - -use libc::STDIN_FILENO; -use std::os::fd::{AsRawFd, FromRawFd}; -use std::pin::Pin; -use std::task::{Context, Poll}; -use tokio::fs::File; -use tokio::io::{stdout, AsyncRead, ReadBuf, Stdout}; use tokio_fd::AsyncFd; use tracing::info;