aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index 5fadb07..7cd4d3e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -220,8 +220,8 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
.is_symlink();
if is_symlink {
- return Err(ContextualError::from(
- "The no-symlinks option cannot be used with a symlink path".to_string(),
+ return Err(ContextualError::NoSymlinksOptionWithSymlinkServePath(
+ miniserve_config.path.to_string_lossy().to_string(),
));
}
}
@@ -266,6 +266,14 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
version = crate_version!()
);
if !miniserve_config.path_explicitly_chosen {
+ // If the path to serve has NOT been explicitly chosen and if this is NOT an interactive
+ // terminal, we should refuse to start for security reasons. This would be the case when
+ // running miniserve as a service but forgetting to set the path. This could be pretty
+ // dangerous if given with an undesired context path (for instance /root or /).
+ if !atty::is(atty::Stream::Stdout) {
+ return Err(ContextualError::NoExplicitPathAndNoTerminal);
+ }
+
warn!("miniserve has been invoked without an explicit path so it will serve the current directory after a short delay.");
warn!(
"Invoke with -h|--help to see options or invoke as `miniserve .` to hide this advice."
@@ -361,7 +369,9 @@ async fn run(miniserve_config: MiniserveConfig) -> Result<(), ContextualError> {
addresses = addresses,
);
- println!("\nQuit by pressing CTRL-C");
+ if atty::is(atty::Stream::Stdout) {
+ println!("\nQuit by pressing CTRL-C");
+ }
srv.await
.map_err(|e| ContextualError::IoError("".to_owned(), e))