Skip to content

Commit

Permalink
Remove --daemon in favor of opposite parameter --foreground
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil committed Oct 16, 2021
1 parent e01a322 commit 6d0e54b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 19 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion distant-ssh2/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ impl Ssh2Session {
let mut session = self.into_ssh_client_session().await?;

// Build arguments for distant
let mut args = vec![String::from("listen"), String::from("--daemon")];
let mut args = vec![String::from("listen")];
args.extend(
shell_words::split(&opts.args)
.map_err(|x| io::Error::new(io::ErrorKind::InvalidInput, x))?,
Expand Down
13 changes: 6 additions & 7 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -474,10 +474,9 @@ pub struct LaunchSubcommand {
#[structopt(long)]
pub shutdown_after: Option<f32>,

/// Runs in background via daemon-mode (does nothing on windows); only applies
/// when session is socket
#[structopt(short, long)]
pub daemon: bool,
/// When session is socket, runs in foreground instead of spawning a background process
#[structopt(long)]
pub foreground: bool,

/// 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
Expand Down Expand Up @@ -553,9 +552,9 @@ impl LaunchSubcommand {
/// Represents subcommand to operate in listen mode for incoming requests
#[derive(Clone, Debug, StructOpt)]
pub struct ListenSubcommand {
/// Runs in background via daemon-mode (does nothing on windows)
#[structopt(short, long)]
pub daemon: bool,
/// Runs in foreground instead of spawning a background process
#[structopt(long)]
pub foreground: bool,

/// Control the IP address that the distant binds to
///
Expand Down
4 changes: 2 additions & 2 deletions src/subcommand/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn run(cmd: LaunchSubcommand, opt: CommonOpt) -> Result<(), Error> {
let rt = Runtime::new()?;
let session_output = cmd.session;
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_socket = cmd.session_data.session_socket.clone();
Expand Down Expand Up @@ -190,7 +190,7 @@ async fn socket_loop(
/// Returns the session associated with the server
async fn spawn_remote_server(cmd: LaunchSubcommand, _opt: CommonOpt) -> Result<SessionInfo, Error> {
let distant_command = format!(
"{} listen --daemon --host {} {}",
"{} listen --host {} {}",
cmd.distant,
cmd.bind_server,
cmd.extra_server_args.unwrap_or_default(),
Expand Down
17 changes: 12 additions & 5 deletions src/subcommand/listen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,29 @@ impl ExitCodeError for Error {
}

pub fn run(cmd: ListenSubcommand, opt: CommonOpt) -> Result<(), Error> {
if cmd.daemon {
run_daemon(cmd, opt)?;
} else {
if cmd.foreground {
let rt = tokio::runtime::Runtime::new()?;
rt.block_on(async { run_async(cmd, opt, false).await })?;
} else {
run_daemon(cmd, opt)?;
}

Ok(())
}

#[cfg(windows)]
fn run_daemon(_cmd: ListenSubcommand, _opt: CommonOpt) -> Result<(), Error> {
use std::process::{Command, Stdio};
let mut args = std::env::args_os().filter(|arg| arg != "--daemon");
use std::{
ffi::OsString,
iter,
process::{Command, Stdio},
};
let mut args = std::env::args_os();
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)
.args(args)
.stdin(Stdio::null())
Expand Down

0 comments on commit 6d0e54b

Please sign in to comment.