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

@ -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))?,

@ -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
@ -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
///

@ -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();
@ -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(),

@ -32,11 +32,11 @@ 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(())
@ -44,10 +44,17 @@ pub fn run(cmd: ListenSubcommand, opt: CommonOpt) -> Result<(), Error> {
#[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())

Loading…
Cancel
Save