From e4311382d9d13683b16123625a5d27b866099921 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Mon, 18 Mar 2019 13:44:37 +0100 Subject: [PATCH] tools: daemon: rename some structs Reloadable resources are now 'Reloadable' instead of 'ReexecContinue'. The struct handling the reload is a 'Reloader', not a 'ReexecStore'. Signed-off-by: Wolfgang Bumiller --- src/bin/proxmox-backup-api.rs | 8 ++++---- src/bin/proxmox-backup-proxy.rs | 8 ++++---- src/tools/daemon.rs | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/bin/proxmox-backup-api.rs b/src/bin/proxmox-backup-api.rs index eec71fe2..67da7615 100644 --- a/src/bin/proxmox-backup-api.rs +++ b/src/bin/proxmox-backup-api.rs @@ -4,7 +4,7 @@ extern crate proxmox_backup; use proxmox_backup::api_schema::router::*; use proxmox_backup::api_schema::config::*; use proxmox_backup::server::rest::*; -use proxmox_backup::tools::daemon::ReexecStore; +use proxmox_backup::tools::daemon::Reloader; use proxmox_backup::auth_helpers::*; use proxmox_backup::config; @@ -28,7 +28,7 @@ fn main() { fn run() -> Result<(), Error> { // This manages data for reloads: - let mut reexecer = ReexecStore::new(); + let mut reloader = Reloader::new(); if let Err(err) = syslog::init( syslog::Facility::LOG_DAEMON, @@ -60,7 +60,7 @@ fn run() -> Result<(), Error> { // http server future: - let listener: tokio::net::TcpListener = reexecer.restore( + let listener: tokio::net::TcpListener = reloader.restore( "PROXMOX_BACKUP_LISTEN_FD", || { let addr = ([127,0,0,1], 82).into(); @@ -76,7 +76,7 @@ fn run() -> Result<(), Error> { let signal_handler = proxmox_backup::tools::daemon::default_signalfd_stream( - reexecer, + reloader, || { unsafe { QUIT_MAIN = true; } Ok(()) diff --git a/src/bin/proxmox-backup-proxy.rs b/src/bin/proxmox-backup-proxy.rs index 07e793a9..cb906d8e 100644 --- a/src/bin/proxmox-backup-proxy.rs +++ b/src/bin/proxmox-backup-proxy.rs @@ -1,6 +1,6 @@ use proxmox_backup::configdir; use proxmox_backup::tools; -use proxmox_backup::tools::daemon::ReexecStore; +use proxmox_backup::tools::daemon::Reloader; use proxmox_backup::api_schema::router::*; use proxmox_backup::api_schema::config::*; use proxmox_backup::server::rest::*; @@ -64,11 +64,11 @@ fn run() -> Result<(), Error> { }; // This manages data for reloads: - let mut reexecer = ReexecStore::new(); + let mut reloader = Reloader::new(); // http server future: - let listener: tokio::net::TcpListener = reexecer.restore( + let listener: tokio::net::TcpListener = reloader.restore( "PROXMOX_BACKUP_LISTEN_FD", || { let addr = ([0,0,0,0,0,0,0,0], 8007).into(); @@ -108,7 +108,7 @@ fn run() -> Result<(), Error> { // signalfd future: let signal_handler = proxmox_backup::tools::daemon::default_signalfd_stream( - reexecer, + reloader, || { unsafe { QUIT_MAIN = true; } Ok(()) diff --git a/src/tools/daemon.rs b/src/tools/daemon.rs index b0e60d91..f51dab1c 100644 --- a/src/tools/daemon.rs +++ b/src/tools/daemon.rs @@ -6,6 +6,7 @@ use std::os::unix::ffi::OsStrExt; use std::panic::UnwindSafe; use failure::*; +use nix::sys::signalfd::siginfo; use tokio::prelude::*; use crate::tools::fd_change_cloexec; @@ -16,14 +17,14 @@ pub type BoxedStoreFunc = Box Result + UnwindSafe + S /// Helper trait to "store" something in the environment to be re-used after re-executing the /// service on a reload. -pub trait ReexecContinue: Sized { +pub trait Reloadable: Sized { fn restore(var: &str) -> Result; fn get_store_func(&self) -> BoxedStoreFunc; } /// Manages things to be stored and reloaded upon reexec. /// Anything which should be restorable should be instantiated via this struct's `restore` method, -pub struct ReexecStore { +pub struct Reloader { pre_exec: Vec, } @@ -34,7 +35,7 @@ struct PreExecEntry { store_fn: BoxedStoreFunc, } -impl ReexecStore { +impl Reloader { pub fn new() -> Self { Self { pre_exec: Vec::new(), @@ -47,7 +48,7 @@ impl ReexecStore { /// Values created via this method will be remembered for later re-execution. pub fn restore(&mut self, name: &'static str, or_create: F) -> Result where - T: ReexecContinue, + T: Reloadable, F: FnOnce() -> Result, { let res = match std::env::var(name) { @@ -120,12 +121,12 @@ impl ReexecStore { } /// Provide a default signal handler for daemons (daemon & proxy). -/// When the first `SIGHUP` is received, the `reexec_store`'s `fork_restart` method will be +/// When the first `SIGHUP` is received, the `reloader`'s `fork_restart` method will be /// triggered. Any further `SIGHUP` is "passed through". pub fn default_signalfd_stream( - reexec_store: ReexecStore, + reloader: Reloader, before_reload: F, -) -> Result, Error> +) -> Result, Error> where F: FnOnce() -> Result<(), Error>, { @@ -137,7 +138,7 @@ where sigprocmask(SigmaskHow::SIG_BLOCK, Some(&sigs), None)?; let sigfdstream = SignalFd::new(&sigs)?; - let mut reexec_store = Some(reexec_store); + let mut reloader = Some(reloader); let mut before_reload = Some(before_reload); Ok(sigfdstream @@ -148,12 +149,12 @@ where if si.ssi_signo == Signal::SIGHUP as u32 { // The firs time this happens we will try to start a new process which should take // over. - if let Some(reexec_store) = reexec_store.take() { + if let Some(reloader) = reloader.take() { if let Err(e) = (before_reload.take().unwrap())() { return Some(Err(e)); } - match reexec_store.fork_restart() { + match reloader.fork_restart() { Ok(_) => return None, Err(e) => return Some(Err(e)), } @@ -172,7 +173,7 @@ where } // For now all we need to do is store and reuse a tcp listening socket: -impl ReexecContinue for tokio::net::TcpListener { +impl Reloadable for tokio::net::TcpListener { // NOTE: The socket must not be closed when the store-function is called: // FIXME: We could become "independent" of the TcpListener and its reference to the file // descriptor by `dup()`ing it (and check if the listener still exists via kcmp()?)