Add support for changing cwd of server, which starts at / by default when launched over ssh

pull/38/head
Chip Senkbeil 3 years ago
parent 3a2749fd7f
commit 676a89427b
No known key found for this signature in database
GPG Key ID: 35EF1F8EC72A4131

@ -339,10 +339,14 @@ pub struct ListenSubcommand {
#[structopt(short = "6", long)]
pub use_ipv6: bool,
/// Maximum capacity for concurrent message handling by the server
/// Maximum capacity for concurrent message handled by the server
#[structopt(long, default_value = "1000")]
pub max_msg_capacity: u16,
/// Changes the current working directory (cwd) to the specified directory
#[structopt(long)]
pub current_dir: Option<PathBuf>,
/// Set the port(s) that the server will attempt to bind to
///
/// This can be in the form of PORT1 or PORT1:PORTN to provide a range of ports.

@ -88,6 +88,12 @@ async fn run_async(cmd: ListenSubcommand, _opt: CommonOpt, is_forked: bool) -> R
let addr = cmd.host.to_ip_addr(cmd.use_ipv6)?;
let socket_addrs = cmd.port.make_socket_addrs(addr);
// If specified, change the current working directory of this program
if let Some(path) = cmd.current_dir.as_ref() {
debug!("Setting current directory to {:?}", path);
std::env::set_current_dir(path)?;
}
debug!("Binding to {} in range {}", addr, cmd.port);
let listener = TcpListener::bind(socket_addrs.as_slice()).await?;

Loading…
Cancel
Save