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<()> { ...@@ -58,12 +58,12 @@ pub fn status(profile_path: &Path) -> Result<()> {
.parse::<i32>() .parse::<i32>()
.expect("invalid pid"); .expect("invalid pid");
match nix::sys::wait::waitpid(Some(Pid::from_raw(pid)), Some(WaitPidFlag::WNOHANG)) { match nix::sys::signal::kill(Pid::from_raw(pid), Some(Signal::SIGUSR1)) {
Ok(WaitStatus::StillAlive) => { Ok(()) => {
println!("Duniter is running using PID {}.", pid); println!("Duniter is running using PID {}.", pid);
Ok(()) Ok(())
} }
Ok(_) | Err(Error::Sys(Errno::ESRCH)) => { Err(Error::Sys(Errno::ESRCH)) => {
println!("Duniter is not running."); println!("Duniter is not running.");
std::process::exit(EXIT_CODE_DUNITER_NOT_RUNNING); std::process::exit(EXIT_CODE_DUNITER_NOT_RUNNING);
} }
...@@ -96,12 +96,18 @@ pub fn stop(profile_path: &Path) -> Result<Vec<String>> { ...@@ -96,12 +96,18 @@ pub fn stop(profile_path: &Path) -> Result<Vec<String>> {
Err(e) => Err(e.into()), Err(e) => Err(e.into()),
Ok(()) => { Ok(()) => {
println!("Stopping Duniter daemon …"); println!("Stopping Duniter daemon …");
match nix::sys::wait::waitpid(Some(Pid::from_raw(pid)), Some(WaitPidFlag::WSTOPPED)) { loop {
Ok(_) | Err(Error::Sys(Errno::ECHILD)) => { match nix::sys::signal::kill(Pid::from_raw(pid), Some(Signal::SIGUSR1)) {
println!("Duniter daemon stopped."); Ok(()) => {
Ok(duniter_args) std::thread::sleep(std::time::Duration::from_secs(1));
continue;
}
Err(Error::Sys(Errno::ESRCH)) => {
println!("Duniter daemon stopped.");
return Ok(duniter_args);
}
Err(e) => return Err(e.into()),
} }
Err(e) => Err(e.into()),
} }
} }
} }
......
...@@ -32,12 +32,7 @@ mod sync; ...@@ -32,12 +32,7 @@ mod sync;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use daemonize_me::Daemon; use daemonize_me::Daemon;
use logwatcher::{LogWatcher, LogWatcherAction}; use logwatcher::{LogWatcher, LogWatcherAction};
use nix::{ use nix::{errno::Errno, sys::signal::Signal, unistd::Pid, Error};
errno::Errno,
sys::{signal::Signal, wait::WaitPidFlag, wait::WaitStatus},
unistd::Pid,
Error,
};
use std::{ use std::{
fs::File, io::prelude::*, path::Path, path::PathBuf, process::Command, process::Output, fs::File, io::prelude::*, path::Path, path::PathBuf, process::Command, process::Output,
process::Stdio, 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