feat: add --no-daemonize flag that disables daemonizing eww (fixes #288)

This commit is contained in:
elkowar 2021-10-16 14:15:34 +02:00
parent d708902c03
commit c50bfb7184
No known key found for this signature in database
GPG key ID: E321AD71B1D1F27F
3 changed files with 17 additions and 10 deletions

View file

@ -65,7 +65,7 @@ fn main() {
}
// a running daemon is necessary for this command
opts::Action::WithServer(action) if action.can_start_daemon() => {
opts::Action::WithServer(action) if action.can_start_daemon() && !opts.no_daemonize => {
if opts.restart {
let _ = handle_server_command(&paths, &ActionWithServer::KillServer, 1);
std::thread::sleep(std::time::Duration::from_millis(200));
@ -83,7 +83,7 @@ fn main() {
let (command, response_recv) = action.into_daemon_command();
// start the daemon and give it the command
let fork_result = server::initialize_server(paths.clone(), Some(command))?;
let fork_result = server::initialize_server(paths.clone(), Some(command), true)?;
let is_parent = fork_result == ForkResult::Parent;
if let (Some(recv), true) = (response_recv, is_parent) {
listen_for_daemon_response(recv);
@ -115,8 +115,8 @@ fn main() {
if !opts.show_logs {
println!("Run `{} logs` to see any errors while editing your configuration.", eww_binary_name);
}
let fork_result = server::initialize_server(paths.clone(), None)?;
fork_result == ForkResult::Parent
let fork_result = server::initialize_server(paths.clone(), None, !opts.no_daemonize)?;
opts.no_daemonize || fork_result == ForkResult::Parent
}
};
if would_show_logs && opts.show_logs {

View file

@ -18,6 +18,7 @@ pub struct Opt {
pub restart: bool,
pub config_path: Option<std::path::PathBuf>,
pub action: Action,
pub no_daemonize: bool,
}
#[derive(StructOpt, Debug, Serialize, Deserialize, PartialEq)]
@ -34,6 +35,10 @@ struct RawOpt {
#[structopt(long = "logs", global = true)]
show_logs: bool,
/// Avoid daemonizing eww.
#[structopt(long = "no-daemonize", global = true)]
no_daemonize: bool,
/// Restart the daemon completely before running the command
#[structopt(long = "restart", global = true)]
restart: bool,
@ -163,8 +168,8 @@ impl Opt {
impl From<RawOpt> for Opt {
fn from(other: RawOpt) -> Self {
let RawOpt { action, log_debug, show_logs, config, restart } = other;
Opt { action, log_debug, show_logs, config_path: config, restart }
let RawOpt { log_debug, config, show_logs, no_daemonize, restart, action } = other;
Opt { log_debug, show_logs, restart, config_path: config, action, no_daemonize }
}
}

View file

@ -14,7 +14,7 @@ use std::{
};
use tokio::sync::mpsc::*;
pub fn initialize_server(paths: EwwPaths, action: Option<DaemonCommand>) -> Result<ForkResult> {
pub fn initialize_server(paths: EwwPaths, action: Option<DaemonCommand>, should_daemonize: bool) -> Result<ForkResult> {
let (ui_send, mut ui_recv) = tokio::sync::mpsc::unbounded_channel();
std::env::set_current_dir(&paths.get_config_dir())
@ -32,10 +32,12 @@ pub fn initialize_server(paths: EwwPaths, action: Option<DaemonCommand>) -> Resu
}
};
let fork_result = do_detach(&paths.get_log_file())?;
if should_daemonize {
let fork_result = do_detach(&paths.get_log_file())?;
if fork_result == ForkResult::Parent {
return Ok(ForkResult::Parent);
if fork_result == ForkResult::Parent {
return Ok(ForkResult::Parent);
}
}
println!(