mirror of
https://github.com/DNSCrypt/encrypted-dns-server.git
synced 2024-04-20 13:03:46 +02:00
Revert "Remove daemonization, it's always been broken"
This reverts commit 4f22725931
.
This commit is contained in:
parent
4f22725931
commit
78eb2719ab
|
@ -17,6 +17,7 @@ byteorder = "1.4.2"
|
|||
clap = { version = "2.33.3", default-features = false, features = ["wrap_help"] }
|
||||
clockpro-cache = "0.1.10"
|
||||
coarsetime = "0.1.18"
|
||||
daemonize-simple = "0.1.5"
|
||||
derivative = "2.2.0"
|
||||
dnsstamps = "0.1.6"
|
||||
env_logger = { version = "0.8.3", default-features = false, features = ["humantime"] }
|
||||
|
|
|
@ -90,6 +90,16 @@ cache_ttl_error = 600
|
|||
client_ttl_holdon = 60
|
||||
|
||||
|
||||
## Run as a background process
|
||||
|
||||
daemonize = false
|
||||
|
||||
|
||||
## Log file, when running as a background process
|
||||
|
||||
# log_file = "/tmp/encrypted-dns.log"
|
||||
|
||||
|
||||
## PID file
|
||||
|
||||
# pid_file = "/tmp/encrypted-dns.pid"
|
||||
|
|
|
@ -78,6 +78,7 @@ pub struct Config {
|
|||
pub filtering: FilteringConfig,
|
||||
pub dnscrypt: DNSCryptConfig,
|
||||
pub tls: TLSConfig,
|
||||
pub daemonize: bool,
|
||||
pub pid_file: Option<PathBuf>,
|
||||
pub log_file: Option<PathBuf>,
|
||||
pub my_ip: Option<String>,
|
||||
|
|
20
src/main.rs
20
src/main.rs
|
@ -466,6 +466,9 @@ fn bind_listeners(
|
|||
}
|
||||
|
||||
fn privdrop(config: &Config) -> Result<(), Error> {
|
||||
if config.daemonize && config.metrics.is_some() {
|
||||
bail!("Metrics are incompatible with daemonization - set 'daemonize = false' in the configuration file if you need metrics.");
|
||||
}
|
||||
let mut pd = PrivDrop::default();
|
||||
if let Some(user) = &config.user {
|
||||
pd = pd.user(user);
|
||||
|
@ -474,12 +477,27 @@ fn privdrop(config: &Config) -> Result<(), Error> {
|
|||
pd = pd.group(group);
|
||||
}
|
||||
if let Some(chroot) = &config.chroot {
|
||||
pd = pd.chroot(chroot);
|
||||
if !config.daemonize {
|
||||
pd = pd.chroot(chroot);
|
||||
}
|
||||
}
|
||||
if config.user.is_some() || config.group.is_some() || config.chroot.is_some() {
|
||||
info!("Dropping privileges");
|
||||
pd.apply()?;
|
||||
}
|
||||
if config.daemonize {
|
||||
let mut daemon = daemonize_simple::Daemonize::default();
|
||||
daemon.stdout_file = config.log_file.clone();
|
||||
daemon.stderr_file = config.log_file.clone();
|
||||
daemon.pid_file = config.pid_file.clone();
|
||||
if let Some(chroot) = &config.chroot {
|
||||
daemon.chdir = Some(chroot.into());
|
||||
daemon.chroot = true;
|
||||
}
|
||||
daemon
|
||||
.doit()
|
||||
.map_err(|e| anyhow!("Unable to daemonize: [{}]", e))?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue