Remove --daemon in favor of opposite parameter --foreground

pull/96/head
Chip Senkbeil 3 years ago
parent e01a322866
commit 6d0e54bfa1
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

8
Cargo.lock generated

@ -427,7 +427,7 @@ dependencies = [
[[package]] [[package]]
name = "distant" name = "distant"
version = "0.15.0-alpha.17" version = "0.15.0-alpha.18"
dependencies = [ dependencies = [
"assert_cmd", "assert_cmd",
"assert_fs", "assert_fs",
@ -451,7 +451,7 @@ dependencies = [
[[package]] [[package]]
name = "distant-core" name = "distant-core"
version = "0.15.0-alpha.17" version = "0.15.0-alpha.18"
dependencies = [ dependencies = [
"assert_fs", "assert_fs",
"bytes", "bytes",
@ -476,7 +476,7 @@ dependencies = [
[[package]] [[package]]
name = "distant-lua" name = "distant-lua"
version = "0.15.0-alpha.17" version = "0.15.0-alpha.18"
dependencies = [ dependencies = [
"distant-core", "distant-core",
"distant-ssh2", "distant-ssh2",
@ -510,7 +510,7 @@ dependencies = [
[[package]] [[package]]
name = "distant-ssh2" name = "distant-ssh2"
version = "0.15.0-alpha.17" version = "0.15.0-alpha.18"
dependencies = [ dependencies = [
"assert_cmd", "assert_cmd",
"assert_fs", "assert_fs",

@ -370,7 +370,7 @@ impl Ssh2Session {
let mut session = self.into_ssh_client_session().await?; let mut session = self.into_ssh_client_session().await?;
// Build arguments for distant // Build arguments for distant
let mut args = vec![String::from("listen"), String::from("--daemon")]; let mut args = vec![String::from("listen")];
args.extend( args.extend(
shell_words::split(&opts.args) shell_words::split(&opts.args)
.map_err(|x| io::Error::new(io::ErrorKind::InvalidInput, x))?, .map_err(|x| io::Error::new(io::ErrorKind::InvalidInput, x))?,

@ -474,10 +474,9 @@ pub struct LaunchSubcommand {
#[structopt(long)] #[structopt(long)]
pub shutdown_after: Option<f32>, pub shutdown_after: Option<f32>,
/// Runs in background via daemon-mode (does nothing on windows); only applies /// When session is socket, runs in foreground instead of spawning a background process
/// when session is socket #[structopt(long)]
#[structopt(short, long)] pub foreground: bool,
pub daemon: bool,
/// Represents the format that results should be returned when session is "keep", /// Represents the format that results should be returned when session is "keep",
/// causing the launcher to enter an interactive loop to handle input and output /// causing the launcher to enter an interactive loop to handle input and output
@ -553,9 +552,9 @@ impl LaunchSubcommand {
/// Represents subcommand to operate in listen mode for incoming requests /// Represents subcommand to operate in listen mode for incoming requests
#[derive(Clone, Debug, StructOpt)] #[derive(Clone, Debug, StructOpt)]
pub struct ListenSubcommand { pub struct ListenSubcommand {
/// Runs in background via daemon-mode (does nothing on windows) /// Runs in foreground instead of spawning a background process
#[structopt(short, long)] #[structopt(long)]
pub daemon: bool, pub foreground: bool,
/// Control the IP address that the distant binds to /// Control the IP address that the distant binds to
/// ///

@ -38,7 +38,7 @@ pub fn run(cmd: LaunchSubcommand, opt: CommonOpt) -> Result<(), Error> {
let rt = Runtime::new()?; let rt = Runtime::new()?;
let session_output = cmd.session; let session_output = cmd.session;
let format = cmd.format; let format = cmd.format;
let is_daemon = cmd.daemon; let is_daemon = !cmd.foreground;
let session_file = cmd.session_data.session_file.clone(); let session_file = cmd.session_data.session_file.clone();
let session_socket = cmd.session_data.session_socket.clone(); let session_socket = cmd.session_data.session_socket.clone();
@ -190,7 +190,7 @@ async fn socket_loop(
/// Returns the session associated with the server /// Returns the session associated with the server
async fn spawn_remote_server(cmd: LaunchSubcommand, _opt: CommonOpt) -> Result<SessionInfo, Error> { async fn spawn_remote_server(cmd: LaunchSubcommand, _opt: CommonOpt) -> Result<SessionInfo, Error> {
let distant_command = format!( let distant_command = format!(
"{} listen --daemon --host {} {}", "{} listen --host {} {}",
cmd.distant, cmd.distant,
cmd.bind_server, cmd.bind_server,
cmd.extra_server_args.unwrap_or_default(), cmd.extra_server_args.unwrap_or_default(),

@ -32,11 +32,11 @@ impl ExitCodeError for Error {
} }
pub fn run(cmd: ListenSubcommand, opt: CommonOpt) -> Result<(), Error> { pub fn run(cmd: ListenSubcommand, opt: CommonOpt) -> Result<(), Error> {
if cmd.daemon { if cmd.foreground {
run_daemon(cmd, opt)?;
} else {
let rt = tokio::runtime::Runtime::new()?; let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async { run_async(cmd, opt, false).await })?; rt.block_on(async { run_async(cmd, opt, false).await })?;
} else {
run_daemon(cmd, opt)?;
} }
Ok(()) Ok(())
@ -44,10 +44,17 @@ pub fn run(cmd: ListenSubcommand, opt: CommonOpt) -> Result<(), Error> {
#[cfg(windows)] #[cfg(windows)]
fn run_daemon(_cmd: ListenSubcommand, _opt: CommonOpt) -> Result<(), Error> { fn run_daemon(_cmd: ListenSubcommand, _opt: CommonOpt) -> Result<(), Error> {
use std::process::{Command, Stdio}; use std::{
let mut args = std::env::args_os().filter(|arg| arg != "--daemon"); ffi::OsString,
iter,
process::{Command, Stdio},
};
let mut args = std::env::args_os();
let program = args.next().ok_or(Error::Fork)?; let program = args.next().ok_or(Error::Fork)?;
// Ensure that forked server runs in foreground, otherwise we would fork bomb ourselves
let args = args.chain(iter::once(OsString::from("--foreground")));
let child = Command::new(program) let child = Command::new(program)
.args(args) .args(args)
.stdin(Stdio::null()) .stdin(Stdio::null())

Loading…
Cancel
Save