mirror of
https://github.com/shadowsocks/shadowsocks-rust.git
synced 2026-11-06 16:14:11 +00:00
exit with code instead of panic! when loading config and ACL errors
- fixes #566
This commit is contained in:
@@ -7,3 +7,8 @@ pub mod daemonize;
|
||||
pub mod logging;
|
||||
pub mod monitor;
|
||||
pub mod validator;
|
||||
|
||||
pub const EXIT_CODE_SERVER_EXIT_UNEXPECTLY: i32 = 1;
|
||||
pub const EXIT_CODE_SERVER_ABORTED: i32 = 2;
|
||||
pub const EXIT_CODE_LOAD_CONFIG_FAILURE: i32 = 6;
|
||||
pub const EXIT_CODE_LOAD_ACL_FAILURE: i32 = 7;
|
||||
|
||||
+13
-5
@@ -4,7 +4,7 @@
|
||||
//! or you could specify a configuration file. The format of configuration file is defined
|
||||
//! in mod `config`.
|
||||
|
||||
use std::time::Duration;
|
||||
use std::{process, time::Duration};
|
||||
|
||||
use clap::{clap_app, Arg};
|
||||
use futures::future::{self, Either};
|
||||
@@ -200,7 +200,8 @@ fn main() {
|
||||
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Local) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(err) => {
|
||||
panic!("loading config \"{}\", {}", cpath, err);
|
||||
eprintln!("loading config \"{}\", {}", cpath, err);
|
||||
process::exit(common::EXIT_CODE_LOAD_CONFIG_FAILURE);
|
||||
}
|
||||
},
|
||||
None => Config::new(ConfigType::Local),
|
||||
@@ -376,7 +377,8 @@ fn main() {
|
||||
let acl = match AccessControl::load_from_file(acl_file) {
|
||||
Ok(acl) => acl,
|
||||
Err(err) => {
|
||||
panic!("loading ACL \"{}\", {}", acl_file, err);
|
||||
eprintln!("loading ACL \"{}\", {}", acl_file, err);
|
||||
process::exit(common::EXIT_CODE_LOAD_ACL_FAILURE);
|
||||
}
|
||||
};
|
||||
config.acl = Some(acl);
|
||||
@@ -474,9 +476,15 @@ fn main() {
|
||||
|
||||
match future::select(server, abort_signal).await {
|
||||
// Server future resolved without an error. This should never happen.
|
||||
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
|
||||
Either::Left((Ok(..), ..)) => {
|
||||
eprintln!("server exited unexpectly");
|
||||
process::exit(common::EXIT_CODE_SERVER_EXIT_UNEXPECTLY);
|
||||
}
|
||||
// Server future resolved with error, which are listener errors in most cases
|
||||
Either::Left((Err(err), ..)) => panic!("aborted with {}", err),
|
||||
Either::Left((Err(err), ..)) => {
|
||||
eprintln!("server aborted with {}", err);
|
||||
process::exit(common::EXIT_CODE_SERVER_ABORTED);
|
||||
}
|
||||
// The abort signal future resolved. Means we should just exit.
|
||||
Either::Right(_) => (),
|
||||
}
|
||||
|
||||
+13
-5
@@ -7,7 +7,7 @@
|
||||
//! *It should be notice that the extented configuration file is not suitable for the server
|
||||
//! side.*
|
||||
|
||||
use std::{net::IpAddr, time::Duration};
|
||||
use std::{net::IpAddr, process, time::Duration};
|
||||
|
||||
use clap::{clap_app, Arg};
|
||||
use futures::future::{self, Either};
|
||||
@@ -140,7 +140,8 @@ fn main() {
|
||||
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Manager) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(err) => {
|
||||
panic!("loading config \"{}\", {}", cpath, err);
|
||||
eprintln!("loading config \"{}\", {}", cpath, err);
|
||||
process::exit(common::EXIT_CODE_LOAD_CONFIG_FAILURE);
|
||||
}
|
||||
},
|
||||
None => Config::new(ConfigType::Manager),
|
||||
@@ -221,7 +222,8 @@ fn main() {
|
||||
let acl = match AccessControl::load_from_file(acl_file) {
|
||||
Ok(acl) => acl,
|
||||
Err(err) => {
|
||||
panic!("loading ACL \"{}\", {}", acl_file, err);
|
||||
eprintln!("loading ACL \"{}\", {}", acl_file, err);
|
||||
process::exit(common::EXIT_CODE_LOAD_ACL_FAILURE);
|
||||
}
|
||||
};
|
||||
config.acl = Some(acl);
|
||||
@@ -308,9 +310,15 @@ fn main() {
|
||||
|
||||
match future::select(server, abort_signal).await {
|
||||
// Server future resolved without an error. This should never happen.
|
||||
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
|
||||
Either::Left((Ok(..), ..)) => {
|
||||
eprintln!("server exited unexpectly");
|
||||
process::exit(common::EXIT_CODE_SERVER_EXIT_UNEXPECTLY);
|
||||
}
|
||||
// Server future resolved with error, which are listener errors in most cases
|
||||
Either::Left((Err(err), ..)) => panic!("aborted with {}", err),
|
||||
Either::Left((Err(err), ..)) => {
|
||||
eprintln!("server aborted with {}", err);
|
||||
process::exit(common::EXIT_CODE_SERVER_ABORTED);
|
||||
}
|
||||
// The abort signal future resolved. Means we should just exit.
|
||||
Either::Right(_) => (),
|
||||
}
|
||||
|
||||
+13
-5
@@ -7,7 +7,7 @@
|
||||
//! *It should be notice that the extented configuration file is not suitable for the server
|
||||
//! side.*
|
||||
|
||||
use std::{net::IpAddr, time::Duration};
|
||||
use std::{net::IpAddr, process, time::Duration};
|
||||
|
||||
use clap::{clap_app, Arg};
|
||||
use futures::future::{self, Either};
|
||||
@@ -142,7 +142,8 @@ fn main() {
|
||||
Some(cpath) => match Config::load_from_file(cpath, ConfigType::Server) {
|
||||
Ok(cfg) => cfg,
|
||||
Err(err) => {
|
||||
panic!("loading config \"{}\", {}", cpath, err);
|
||||
eprintln!("loading config \"{}\", {}", cpath, err);
|
||||
process::exit(common::EXIT_CODE_LOAD_CONFIG_FAILURE);
|
||||
}
|
||||
},
|
||||
None => Config::new(ConfigType::Server),
|
||||
@@ -231,7 +232,8 @@ fn main() {
|
||||
let acl = match AccessControl::load_from_file(acl_file) {
|
||||
Ok(acl) => acl,
|
||||
Err(err) => {
|
||||
panic!("loading ACL \"{}\", {}", acl_file, err);
|
||||
eprintln!("loading ACL \"{}\", {}", acl_file, err);
|
||||
process::exit(common::EXIT_CODE_LOAD_ACL_FAILURE);
|
||||
}
|
||||
};
|
||||
config.acl = Some(acl);
|
||||
@@ -319,9 +321,15 @@ fn main() {
|
||||
|
||||
match future::select(server, abort_signal).await {
|
||||
// Server future resolved without an error. This should never happen.
|
||||
Either::Left((Ok(..), ..)) => panic!("server exited unexpectly"),
|
||||
Either::Left((Ok(..), ..)) => {
|
||||
eprintln!("server exited unexpectly");
|
||||
process::exit(common::EXIT_CODE_SERVER_EXIT_UNEXPECTLY);
|
||||
}
|
||||
// Server future resolved with error, which are listener errors in most cases
|
||||
Either::Left((Err(err), ..)) => panic!("aborted with {}", err),
|
||||
Either::Left((Err(err), ..)) => {
|
||||
eprintln!("server aborted with {}", err);
|
||||
process::exit(common::EXIT_CODE_SERVER_ABORTED);
|
||||
}
|
||||
// The abort signal future resolved. Means we should just exit.
|
||||
Either::Right(_) => (),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user