Browse Source

Prevent unnecessary creation of a PID file

When running in foreground, a PID file should be created only if
the `--pid-file` option is specified.
Rel #25
pull/31/head
Rodolphe Breard 5 years ago
parent
commit
70db8e6dd9
  1. 8
      acme_common/src/lib.rs
  2. 3
      acmed/src/main.rs
  3. 3
      tacd/src/main.rs

8
acme_common/src/lib.rs

@ -40,12 +40,12 @@ pub fn b64_encode<T: ?Sized + AsRef<[u8]>>(input: &T) -> String {
base64::encode_config(input, base64::URL_SAFE_NO_PAD) base64::encode_config(input, base64::URL_SAFE_NO_PAD)
} }
pub fn init_server(foreground: bool, pid_file: &str) {
pub fn init_server(foreground: bool, pid_file: Option<&str>, default_pid_file: &str) {
if !foreground { if !foreground {
let daemonize = Daemonize::new().pid_file(pid_file);
let daemonize = Daemonize::new().pid_file(pid_file.unwrap_or(default_pid_file));
exit_match!(daemonize.start()); exit_match!(daemonize.start());
} else {
exit_match!(write_pid_file(pid_file));
} else if let Some(f) = pid_file {
exit_match!(write_pid_file(f));
} }
} }

3
acmed/src/main.rs

@ -117,7 +117,8 @@ fn main() {
init_server( init_server(
matches.is_present("foreground"), matches.is_present("foreground"),
matches.value_of("pid-file").unwrap_or(DEFAULT_PID_FILE),
matches.value_of("pid-file"),
DEFAULT_PID_FILE,
); );
let config_file = matches.value_of("config").unwrap_or(DEFAULT_CONFIG_FILE); let config_file = matches.value_of("config").unwrap_or(DEFAULT_CONFIG_FILE);

3
tacd/src/main.rs

@ -42,7 +42,8 @@ fn get_acme_value(cnf: &ArgMatches, opt: &str, opt_file: &str) -> Result<String,
fn init(cnf: &ArgMatches) -> Result<(), Error> { fn init(cnf: &ArgMatches) -> Result<(), Error> {
acme_common::init_server( acme_common::init_server(
cnf.is_present("foreground"), cnf.is_present("foreground"),
cnf.value_of("pid-file").unwrap_or(DEFAULT_PID_FILE),
cnf.value_of("pid-file"),
DEFAULT_PID_FILE,
); );
let domain = get_acme_value(cnf, "domain", "domain-file")?; let domain = get_acme_value(cnf, "domain", "domain-file")?;
let domain = to_idna(&domain)?; let domain = to_idna(&domain)?;

Loading…
Cancel
Save