2021-09-27 10:59:06 +00:00
|
|
|
//! Helpers to implement restartable daemons/services.
|
2019-03-12 09:40:25 +00:00
|
|
|
|
|
|
|
use std::ffi::CString;
|
2019-09-02 13:16:21 +00:00
|
|
|
use std::future::Future;
|
2020-06-22 08:58:04 +00:00
|
|
|
use std::io::{Read, Write};
|
2020-06-22 11:06:11 +00:00
|
|
|
use std::os::raw::{c_char, c_uchar, c_int};
|
2019-04-10 13:17:11 +00:00
|
|
|
use std::os::unix::io::{AsRawFd, FromRawFd, IntoRawFd, RawFd};
|
2019-03-12 09:40:25 +00:00
|
|
|
use std::os::unix::ffi::OsStrExt;
|
|
|
|
use std::panic::UnwindSafe;
|
2020-06-22 11:06:11 +00:00
|
|
|
use std::path::PathBuf;
|
2019-03-12 09:40:25 +00:00
|
|
|
|
2020-04-17 12:11:25 +00:00
|
|
|
use anyhow::{bail, format_err, Error};
|
2020-11-04 12:09:38 +00:00
|
|
|
use futures::future::{self, Either};
|
2021-09-30 06:40:55 +00:00
|
|
|
use nix::unistd::{fork, ForkResult};
|
2019-03-18 10:50:10 +00:00
|
|
|
|
2019-07-01 08:39:13 +00:00
|
|
|
use proxmox::tools::io::{ReadExt, WriteExt};
|
2021-09-21 05:58:41 +00:00
|
|
|
use proxmox::tools::fd::Fd;
|
2019-07-01 08:39:13 +00:00
|
|
|
|
2021-09-30 10:42:28 +00:00
|
|
|
use pbs_tools::fd::fd_change_cloexec;
|
2019-03-12 09:40:25 +00:00
|
|
|
|
2020-06-22 11:06:11 +00:00
|
|
|
#[link(name = "systemd")]
|
|
|
|
extern "C" {
|
|
|
|
fn sd_journal_stream_fd(identifier: *const c_uchar, priority: c_int, level_prefix: c_int) -> c_int;
|
|
|
|
}
|
|
|
|
|
2019-03-12 09:40:25 +00:00
|
|
|
// Unfortunately FnBox is nightly-only and Box<FnOnce> is unusable, so just use Box<Fn>...
|
2021-09-29 07:40:56 +00:00
|
|
|
type BoxedStoreFunc = Box<dyn FnMut() -> Result<String, Error> + UnwindSafe + Send>;
|
2019-03-12 09:40:25 +00:00
|
|
|
|
2021-09-30 06:40:55 +00:00
|
|
|
// Helper trait to "store" something in the environment to be re-used after re-executing the
|
|
|
|
// service on a reload.
|
2021-09-30 05:37:16 +00:00
|
|
|
trait Reloadable: Sized {
|
2019-03-12 09:40:25 +00:00
|
|
|
fn restore(var: &str) -> Result<Self, Error>;
|
2019-04-10 13:17:11 +00:00
|
|
|
fn get_store_func(&self) -> Result<BoxedStoreFunc, Error>;
|
2019-03-12 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
2021-09-30 05:37:16 +00:00
|
|
|
// Manages things to be stored and reloaded upon reexec.
|
|
|
|
// Anything which should be restorable should be instantiated via this struct's `restore` method,
|
2019-10-26 09:36:01 +00:00
|
|
|
#[derive(Default)]
|
2021-09-30 05:37:16 +00:00
|
|
|
struct Reloader {
|
2019-03-12 09:40:25 +00:00
|
|
|
pre_exec: Vec<PreExecEntry>,
|
2020-06-22 11:06:11 +00:00
|
|
|
self_exe: PathBuf,
|
2019-03-12 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Currently we only need environment variables for storage, but in theory we could also add
|
|
|
|
// variants which need temporary files or pipes...
|
|
|
|
struct PreExecEntry {
|
|
|
|
name: &'static str, // Feel free to change to String if necessary...
|
|
|
|
store_fn: BoxedStoreFunc,
|
|
|
|
}
|
|
|
|
|
2019-03-18 12:44:37 +00:00
|
|
|
impl Reloader {
|
2020-06-22 08:20:51 +00:00
|
|
|
pub fn new() -> Result<Self, Error> {
|
|
|
|
Ok(Self {
|
2019-03-12 09:40:25 +00:00
|
|
|
pre_exec: Vec::new(),
|
2020-06-22 08:20:51 +00:00
|
|
|
|
2020-06-22 11:06:11 +00:00
|
|
|
// Get the path to our executable as PathBuf
|
|
|
|
self_exe: std::fs::read_link("/proc/self/exe")?,
|
2020-06-22 08:20:51 +00:00
|
|
|
})
|
2019-03-12 09:40:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Restore an object from an environment variable of the given name, or, if none exists, uses
|
|
|
|
/// the function provided in the `or_create` parameter to instantiate the new "first" instance.
|
|
|
|
///
|
|
|
|
/// Values created via this method will be remembered for later re-execution.
|
2019-09-02 13:16:21 +00:00
|
|
|
pub async fn restore<T, F, U>(&mut self, name: &'static str, or_create: F) -> Result<T, Error>
|
2019-03-12 09:40:25 +00:00
|
|
|
where
|
2019-03-18 12:44:37 +00:00
|
|
|
T: Reloadable,
|
2019-09-02 13:16:21 +00:00
|
|
|
F: FnOnce() -> U,
|
|
|
|
U: Future<Output = Result<T, Error>>,
|
2019-03-12 09:40:25 +00:00
|
|
|
{
|
|
|
|
let res = match std::env::var(name) {
|
|
|
|
Ok(varstr) => T::restore(&varstr)?,
|
2019-09-02 13:16:21 +00:00
|
|
|
Err(std::env::VarError::NotPresent) => or_create().await?,
|
2019-03-12 09:40:25 +00:00
|
|
|
Err(_) => bail!("variable {} has invalid value", name),
|
|
|
|
};
|
|
|
|
|
|
|
|
self.pre_exec.push(PreExecEntry {
|
|
|
|
name,
|
2019-04-10 13:17:11 +00:00
|
|
|
store_fn: res.get_store_func()?,
|
2019-03-12 09:40:25 +00:00
|
|
|
});
|
|
|
|
Ok(res)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn pre_exec(self) -> Result<(), Error> {
|
2019-04-10 13:17:11 +00:00
|
|
|
for mut item in self.pre_exec {
|
2019-03-12 09:40:25 +00:00
|
|
|
std::env::set_var(item.name, (item.store_fn)()?);
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn fork_restart(self) -> Result<(), Error> {
|
|
|
|
// Get our parameters as Vec<CString>
|
|
|
|
let args = std::env::args_os();
|
|
|
|
let mut new_args = Vec::with_capacity(args.len());
|
|
|
|
for arg in args {
|
|
|
|
new_args.push(CString::new(arg.as_bytes())?);
|
|
|
|
}
|
|
|
|
|
2019-04-25 11:00:02 +00:00
|
|
|
// Synchronisation pipe:
|
2020-06-22 08:58:04 +00:00
|
|
|
let (pold, pnew) = super::socketpair()?;
|
2019-04-25 11:00:02 +00:00
|
|
|
|
2019-03-12 09:40:25 +00:00
|
|
|
// Start ourselves in the background:
|
2020-10-19 10:12:33 +00:00
|
|
|
match unsafe { fork() } {
|
2019-03-12 09:40:25 +00:00
|
|
|
Ok(ForkResult::Child) => {
|
2019-04-25 11:00:02 +00:00
|
|
|
// Double fork so systemd can supervise us without nagging...
|
2020-10-19 10:12:33 +00:00
|
|
|
match unsafe { fork() } {
|
2019-04-25 11:00:02 +00:00
|
|
|
Ok(ForkResult::Child) => {
|
2020-06-22 08:58:04 +00:00
|
|
|
std::mem::drop(pold);
|
2019-04-25 11:00:02 +00:00
|
|
|
// At this point we call pre-exec helpers. We must be certain that if they fail for
|
|
|
|
// whatever reason we can still call `_exit()`, so use catch_unwind.
|
|
|
|
match std::panic::catch_unwind(move || {
|
2020-06-22 08:58:04 +00:00
|
|
|
let mut pnew = unsafe {
|
|
|
|
std::fs::File::from_raw_fd(pnew.into_raw_fd())
|
2019-04-25 11:00:02 +00:00
|
|
|
};
|
|
|
|
let pid = nix::unistd::Pid::this();
|
2020-06-22 08:58:04 +00:00
|
|
|
if let Err(e) = unsafe { pnew.write_host_value(pid.as_raw()) } {
|
2019-04-25 11:00:02 +00:00
|
|
|
log::error!("failed to send new server PID to parent: {}", e);
|
|
|
|
unsafe {
|
|
|
|
libc::_exit(-1);
|
|
|
|
}
|
|
|
|
}
|
2020-06-22 08:58:04 +00:00
|
|
|
|
|
|
|
let mut ok = [0u8];
|
|
|
|
if let Err(e) = pnew.read_exact(&mut ok) {
|
|
|
|
log::error!("parent vanished before notifying systemd: {}", e);
|
|
|
|
unsafe {
|
|
|
|
libc::_exit(-1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
assert_eq!(ok[0], 1, "reload handshake should have sent a 1 byte");
|
|
|
|
|
|
|
|
std::mem::drop(pnew);
|
2020-06-22 11:06:11 +00:00
|
|
|
|
|
|
|
// Try to reopen STDOUT/STDERR journald streams to get correct PID in logs
|
|
|
|
let ident = CString::new(self.self_exe.file_name().unwrap().as_bytes()).unwrap();
|
|
|
|
let ident = ident.as_bytes();
|
|
|
|
let fd = unsafe { sd_journal_stream_fd(ident.as_ptr(), libc::LOG_INFO, 1) };
|
|
|
|
if fd >= 0 && fd != 1 {
|
|
|
|
let fd = proxmox::tools::fd::Fd(fd); // add drop handler
|
|
|
|
nix::unistd::dup2(fd.as_raw_fd(), 1)?;
|
|
|
|
} else {
|
|
|
|
log::error!("failed to update STDOUT journal redirection ({})", fd);
|
|
|
|
}
|
|
|
|
let fd = unsafe { sd_journal_stream_fd(ident.as_ptr(), libc::LOG_ERR, 1) };
|
|
|
|
if fd >= 0 && fd != 2 {
|
|
|
|
let fd = proxmox::tools::fd::Fd(fd); // add drop handler
|
|
|
|
nix::unistd::dup2(fd.as_raw_fd(), 2)?;
|
|
|
|
} else {
|
|
|
|
log::error!("failed to update STDERR journal redirection ({})", fd);
|
|
|
|
}
|
|
|
|
|
2020-06-22 08:20:51 +00:00
|
|
|
self.do_reexec(new_args)
|
2019-04-25 11:00:02 +00:00
|
|
|
})
|
|
|
|
{
|
2021-09-29 12:34:25 +00:00
|
|
|
Ok(Ok(())) => log::error!("do_reexec returned!"),
|
|
|
|
Ok(Err(err)) => log::error!("do_reexec failed: {}", err),
|
|
|
|
Err(_) => log::error!("panic in re-exec"),
|
2019-04-25 11:00:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(ForkResult::Parent { child }) => {
|
2020-06-22 08:58:04 +00:00
|
|
|
std::mem::drop((pold, pnew));
|
2019-04-25 11:00:02 +00:00
|
|
|
log::debug!("forked off a new server (second pid: {})", child);
|
|
|
|
}
|
|
|
|
Err(e) => log::error!("fork() failed, restart delayed: {}", e),
|
2019-03-12 09:40:25 +00:00
|
|
|
}
|
|
|
|
// No matter how we managed to get here, this is the time where we bail out quickly:
|
|
|
|
unsafe {
|
|
|
|
libc::_exit(-1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(ForkResult::Parent { child }) => {
|
2019-04-25 11:00:02 +00:00
|
|
|
log::debug!("forked off a new server (first pid: {}), waiting for 2nd pid", child);
|
2020-06-22 08:58:04 +00:00
|
|
|
std::mem::drop(pnew);
|
|
|
|
let mut pold = unsafe {
|
|
|
|
std::fs::File::from_raw_fd(pold.into_raw_fd())
|
2019-04-25 11:00:02 +00:00
|
|
|
};
|
2020-06-22 08:58:04 +00:00
|
|
|
let child = nix::unistd::Pid::from_raw(match unsafe { pold.read_le_value() } {
|
2019-04-25 11:00:02 +00:00
|
|
|
Ok(v) => v,
|
|
|
|
Err(e) => {
|
|
|
|
log::error!("failed to receive pid of double-forked child process: {}", e);
|
|
|
|
// systemd will complain but won't kill the service...
|
|
|
|
return Ok(());
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-04-25 08:38:26 +00:00
|
|
|
if let Err(e) = systemd_notify(SystemdNotify::MainPid(child)) {
|
|
|
|
log::error!("failed to notify systemd about the new main pid: {}", e);
|
|
|
|
}
|
2021-10-01 13:04:58 +00:00
|
|
|
// ensure systemd got the message about the new main PID before continuing, else it
|
|
|
|
// will get confused if the new main process sends its READY signal before that
|
2021-10-01 13:27:46 +00:00
|
|
|
if let Err(e) = systemd_notify_barrier(u64::MAX) {
|
2021-09-30 07:18:58 +00:00
|
|
|
log::error!("failed to wait on systemd-processing: {}", e);
|
|
|
|
}
|
2020-06-22 08:58:04 +00:00
|
|
|
|
|
|
|
// notify child that it is now the new main process:
|
|
|
|
if let Err(e) = pold.write_all(&[1u8]) {
|
|
|
|
log::error!("child vanished during reload: {}", e);
|
|
|
|
}
|
|
|
|
|
2019-03-12 09:40:25 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
Err(e) => {
|
2019-04-25 11:00:02 +00:00
|
|
|
log::error!("fork() failed, restart delayed: {}", e);
|
2019-03-12 09:40:25 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-22 08:20:51 +00:00
|
|
|
fn do_reexec(self, args: Vec<CString>) -> Result<(), Error> {
|
2020-06-22 11:06:11 +00:00
|
|
|
let exe = CString::new(self.self_exe.as_os_str().as_bytes())?;
|
2019-03-12 09:40:25 +00:00
|
|
|
self.pre_exec()?;
|
|
|
|
nix::unistd::setsid()?;
|
2019-12-19 08:29:44 +00:00
|
|
|
let args: Vec<&std::ffi::CStr> = args.iter().map(|s| s.as_ref()).collect();
|
2019-03-12 09:40:25 +00:00
|
|
|
nix::unistd::execvp(&exe, &args)?;
|
2020-06-22 08:20:51 +00:00
|
|
|
panic!("exec misbehaved");
|
2019-03-12 09:40:25 +00:00
|
|
|
}
|
|
|
|
}
|
2019-03-18 10:50:10 +00:00
|
|
|
|
2019-03-18 10:52:04 +00:00
|
|
|
// For now all we need to do is store and reuse a tcp listening socket:
|
2019-03-18 12:44:37 +00:00
|
|
|
impl Reloadable for tokio::net::TcpListener {
|
2019-03-18 10:52:04 +00:00
|
|
|
// 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()?)
|
2019-04-10 13:17:11 +00:00
|
|
|
fn get_store_func(&self) -> Result<BoxedStoreFunc, Error> {
|
2021-09-21 05:58:41 +00:00
|
|
|
let mut fd_opt = Some(Fd(
|
2019-04-10 13:17:11 +00:00
|
|
|
nix::fcntl::fcntl(self.as_raw_fd(), nix::fcntl::FcntlArg::F_DUPFD_CLOEXEC(0))?
|
|
|
|
));
|
|
|
|
Ok(Box::new(move || {
|
|
|
|
let fd = fd_opt.take().unwrap();
|
|
|
|
fd_change_cloexec(fd.as_raw_fd(), false)?;
|
|
|
|
Ok(fd.into_raw_fd().to_string())
|
|
|
|
}))
|
2019-03-18 10:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn restore(var: &str) -> Result<Self, Error> {
|
|
|
|
let fd = var.parse::<u32>()
|
|
|
|
.map_err(|e| format_err!("invalid file descriptor: {}", e))?
|
|
|
|
as RawFd;
|
|
|
|
fd_change_cloexec(fd, true)?;
|
|
|
|
Ok(Self::from_std(
|
|
|
|
unsafe { std::net::TcpListener::from_raw_fd(fd) },
|
|
|
|
)?)
|
|
|
|
}
|
|
|
|
}
|
2019-03-18 13:13:44 +00:00
|
|
|
|
|
|
|
/// This creates a future representing a daemon which reloads itself when receiving a SIGHUP.
|
|
|
|
/// If this is started regularly, a listening socket is created. In this case, the file descriptor
|
|
|
|
/// number will be remembered in `PROXMOX_BACKUP_LISTEN_FD`.
|
|
|
|
/// If the variable already exists, its contents will instead be used to restore the listening
|
|
|
|
/// socket. The finished listening socket is then passed to the `create_service` function which
|
2021-09-29 09:21:32 +00:00
|
|
|
/// can be used to setup the TLS and the HTTP daemon. The returned future has to call
|
|
|
|
/// [systemd_notify] with [SystemdNotify::Ready] when the service is ready.
|
2019-09-02 13:16:21 +00:00
|
|
|
pub async fn create_daemon<F, S>(
|
2019-03-18 13:13:44 +00:00
|
|
|
address: std::net::SocketAddr,
|
|
|
|
create_service: F,
|
2019-09-02 13:16:21 +00:00
|
|
|
) -> Result<(), Error>
|
2019-03-18 13:13:44 +00:00
|
|
|
where
|
2021-09-29 09:21:32 +00:00
|
|
|
F: FnOnce(tokio::net::TcpListener) -> Result<S, Error>,
|
|
|
|
S: Future<Output = Result<(), Error>>,
|
2019-03-18 13:13:44 +00:00
|
|
|
{
|
2020-06-22 08:20:51 +00:00
|
|
|
let mut reloader = Reloader::new()?;
|
2019-03-18 13:13:44 +00:00
|
|
|
|
|
|
|
let listener: tokio::net::TcpListener = reloader.restore(
|
|
|
|
"PROXMOX_BACKUP_LISTEN_FD",
|
2019-09-02 13:16:21 +00:00
|
|
|
move || async move { Ok(tokio::net::TcpListener::bind(&address).await?) },
|
|
|
|
).await?;
|
2019-03-18 13:13:44 +00:00
|
|
|
|
2021-09-29 09:21:32 +00:00
|
|
|
let service = create_service(listener)?;
|
|
|
|
|
|
|
|
let service = async move {
|
|
|
|
if let Err(err) = service.await {
|
|
|
|
log::error!("server error: {}", err);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let server_future = Box::pin(service);
|
2021-09-21 05:58:41 +00:00
|
|
|
let shutdown_future = crate::shutdown_future();
|
2020-11-04 12:09:38 +00:00
|
|
|
|
|
|
|
let finish_future = match future::select(server_future, shutdown_future).await {
|
|
|
|
Either::Left((_, _)) => {
|
2021-09-29 10:46:00 +00:00
|
|
|
if !crate::shutdown_requested() {
|
|
|
|
crate::request_shutdown(); // make sure we are in shutdown mode
|
|
|
|
}
|
2020-11-04 12:09:38 +00:00
|
|
|
None
|
|
|
|
}
|
|
|
|
Either::Right((_, server_future)) => Some(server_future),
|
|
|
|
};
|
2019-03-18 13:13:44 +00:00
|
|
|
|
|
|
|
let mut reloader = Some(reloader);
|
|
|
|
|
2021-09-21 05:58:41 +00:00
|
|
|
if crate::is_reload_request() {
|
2019-09-02 13:16:21 +00:00
|
|
|
log::info!("daemon reload...");
|
|
|
|
if let Err(e) = systemd_notify(SystemdNotify::Reloading) {
|
|
|
|
log::error!("failed to notify systemd about the state change: {}", e);
|
|
|
|
}
|
2021-10-01 13:27:46 +00:00
|
|
|
if let Err(e) = systemd_notify_barrier(u64::MAX) {
|
2021-09-30 07:18:58 +00:00
|
|
|
log::error!("failed to wait on systemd-processing: {}", e);
|
|
|
|
}
|
|
|
|
|
2019-09-02 13:16:21 +00:00
|
|
|
if let Err(e) = reloader.take().unwrap().fork_restart() {
|
|
|
|
log::error!("error during reload: {}", e);
|
2019-10-26 09:36:01 +00:00
|
|
|
let _ = systemd_notify(SystemdNotify::Status("error during reload".to_string()));
|
2019-09-02 13:16:21 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
log::info!("daemon shutting down...");
|
|
|
|
}
|
2020-11-04 12:09:38 +00:00
|
|
|
|
|
|
|
if let Some(future) = finish_future {
|
|
|
|
future.await;
|
|
|
|
}
|
2020-11-11 08:27:51 +00:00
|
|
|
|
2021-09-29 12:34:25 +00:00
|
|
|
log::info!("daemon shut down.");
|
2019-09-02 13:16:21 +00:00
|
|
|
Ok(())
|
2019-03-18 13:13:44 +00:00
|
|
|
}
|
2019-04-25 08:35:01 +00:00
|
|
|
|
|
|
|
#[link(name = "systemd")]
|
|
|
|
extern "C" {
|
|
|
|
fn sd_notify(unset_environment: c_int, state: *const c_char) -> c_int;
|
2021-09-30 07:18:58 +00:00
|
|
|
fn sd_notify_barrier(unset_environment: c_int, timeout: u64) -> c_int;
|
2019-04-25 08:35:01 +00:00
|
|
|
}
|
|
|
|
|
2021-09-27 10:59:06 +00:00
|
|
|
/// Systemd sercice startup states (see: ``man sd_notify``)
|
2019-04-25 08:35:01 +00:00
|
|
|
pub enum SystemdNotify {
|
|
|
|
Ready,
|
|
|
|
Reloading,
|
|
|
|
Stopping,
|
|
|
|
Status(String),
|
|
|
|
MainPid(nix::unistd::Pid),
|
|
|
|
}
|
|
|
|
|
2021-09-27 10:59:06 +00:00
|
|
|
/// Tells systemd the startup state of the service (see: ``man sd_notify``)
|
2019-04-25 08:35:01 +00:00
|
|
|
pub fn systemd_notify(state: SystemdNotify) -> Result<(), Error> {
|
|
|
|
let message = match state {
|
2021-10-01 14:45:19 +00:00
|
|
|
SystemdNotify::Ready => {
|
|
|
|
log::info!("service is ready");
|
|
|
|
CString::new("READY=1")
|
|
|
|
},
|
2019-04-25 08:35:01 +00:00
|
|
|
SystemdNotify::Reloading => CString::new("RELOADING=1"),
|
|
|
|
SystemdNotify::Stopping => CString::new("STOPPING=1"),
|
|
|
|
SystemdNotify::Status(msg) => CString::new(format!("STATUS={}", msg)),
|
|
|
|
SystemdNotify::MainPid(pid) => CString::new(format!("MAINPID={}", pid)),
|
|
|
|
}?;
|
|
|
|
let rc = unsafe { sd_notify(0, message.as_ptr()) };
|
|
|
|
if rc < 0 {
|
2021-10-01 14:45:19 +00:00
|
|
|
bail!("systemd_notify failed: {}", std::io::Error::from_raw_os_error(-rc));
|
2019-04-25 08:35:01 +00:00
|
|
|
}
|
2021-09-29 12:34:25 +00:00
|
|
|
|
2019-04-25 08:35:01 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2021-10-01 14:44:28 +00:00
|
|
|
|
|
|
|
/// Waits until all previously sent messages with sd_notify are processed
|
|
|
|
pub fn systemd_notify_barrier(timeout: u64) -> Result<(), Error> {
|
|
|
|
let rc = unsafe { sd_notify_barrier(0, timeout) };
|
|
|
|
if rc < 0 {
|
|
|
|
bail!("systemd_notify_barrier failed: {}", std::io::Error::from_raw_os_error(-rc));
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|