Commit 621ddd66 authored by Éloïs's avatar Éloïs
Browse files

[fix] daemon: waitpid not work for commands status and stop

parent 37d7e27b
......@@ -58,12 +58,12 @@ pub fn status(profile_path: &Path) -> Result<()> {
.parse::<i32>()
.expect("invalid pid");
match nix::sys::wait::waitpid(Some(Pid::from_raw(pid)), Some(WaitPidFlag::WNOHANG)) {
Ok(WaitStatus::StillAlive) => {
match nix::sys::signal::kill(Pid::from_raw(pid), Some(Signal::SIGUSR1)) {
Ok(()) => {
println!("Duniter is running using PID {}.", pid);
Ok(())
}
Ok(_) | Err(Error::Sys(Errno::ESRCH)) => {
Err(Error::Sys(Errno::ESRCH)) => {
println!("Duniter is not running.");
std::process::exit(EXIT_CODE_DUNITER_NOT_RUNNING);
}
......@@ -96,12 +96,18 @@ pub fn stop(profile_path: &Path) -> Result<Vec<String>> {
Err(e) => Err(e.into()),
Ok(()) => {
println!("Stopping Duniter daemon …");
match nix::sys::wait::waitpid(Some(Pid::from_raw(pid)), Some(WaitPidFlag::WSTOPPED)) {
Ok(_) | Err(Error::Sys(Errno::ECHILD)) => {
loop {
match nix::sys::signal::kill(Pid::from_raw(pid), Some(Signal::SIGUSR1)) {
Ok(()) => {
std::thread::sleep(std::time::Duration::from_secs(1));
continue;
}
Err(Error::Sys(Errno::ESRCH)) => {
println!("Duniter daemon stopped.");
Ok(duniter_args)
return Ok(duniter_args);
}
Err(e) => return Err(e.into()),
}
Err(e) => Err(e.into()),
}
}
}
......
......@@ -32,12 +32,7 @@ mod sync;
use anyhow::{anyhow, Result};
use daemonize_me::Daemon;
use logwatcher::{LogWatcher, LogWatcherAction};
use nix::{
errno::Errno,
sys::{signal::Signal, wait::WaitPidFlag, wait::WaitStatus},
unistd::Pid,
Error,
};
use nix::{errno::Errno, sys::signal::Signal, unistd::Pid, Error};
use std::{
fs::File, io::prelude::*, path::Path, path::PathBuf, process::Command, process::Output,
process::Stdio,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment