From 0389f02415ad80f266702f4f41921305ae654c07 Mon Sep 17 00:00:00 2001 From: Hugo Osvaldo Barrera Date: Sun, 18 Feb 2024 19:37:57 +0100 Subject: [PATCH] Drop daemonizing logic Run in foreground, which is what service managers expect. Usages like running `exec swww` in sway's config continue to work fine. User session start-up scripts can simply run `swww &`. Fixes: https://github.com/LGFae/swww/issues/182 --- src/cli.rs | 7 ------- src/main.rs | 43 +++++++++++-------------------------------- 2 files changed, 11 insertions(+), 39 deletions(-) diff --git a/src/cli.rs b/src/cli.rs index e969a212..1c20b405 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -172,13 +172,6 @@ pub enum Swww { /// Exits if there is already a daemon running. We check that by seeing if /// $XDG_RUNTIME_DIR/swww.socket exists. Init { - ///Don't fork the daemon. This will keep it running in the current terminal. - /// - ///The only advantage of this would be seeing the logging real time. Note that for release - ///builds we only log info, warnings and errors, so you won't be seeing much (ideally). - #[clap(long)] - no_daemon: bool, - ///Don't load the cache *during initialization* (it still loads on monitor (re)connection) /// ///If want to always pass an image for `swww` to load, this option can help make the diff --git a/src/main.rs b/src/main.rs index 1d713d63..194140f8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,5 +1,9 @@ use clap::Parser; -use std::{path::PathBuf, process::Stdio, time::Duration}; +use std::{ + os::unix::{net::UnixStream, process::CommandExt}, + path::PathBuf, + time::Duration, +}; use utils::{ cache, @@ -14,10 +18,7 @@ use cli::{ResizeStrategy, Swww}; fn main() -> Result<(), String> { let swww = Swww::parse(); - if let Swww::Init { - no_daemon, format, .. - } = &swww - { + if let Swww::Init { .. } = &swww { eprintln!( "DEPRECATION WARNING: `swww init` IS DEPRECATED. Call `swww-daemon` directly instead" ); @@ -49,10 +50,7 @@ fn main() -> Result<(), String> { } } } - spawn_daemon(*no_daemon, format)?; - if *no_daemon { - return Ok(()); - } + return Err(spawn_daemon()); } if let Swww::ClearCache = &swww { @@ -282,30 +280,11 @@ fn split_cmdline_outputs(outputs: &str) -> Box<[String]> { .collect() } -fn spawn_daemon(no_daemon: bool, format: &Option) -> Result<(), String> { +/// Only returns if `exec` fails. +fn spawn_daemon() -> String { let mut cmd = std::process::Command::new("swww-daemon"); - - if let Some(format) = format { - cmd.arg("--format"); - cmd.arg(match format { - cli::PixelFormat::Xrgb => "xrgb", - cli::PixelFormat::Xbgr => "xbgr", - cli::PixelFormat::Rgb => "rgb", - cli::PixelFormat::Bgr => "bgr", - }); - } - - if no_daemon { - match cmd.status() { - Ok(_) => Ok(()), - Err(e) => Err(format!("error spawning swww-daemon: {e}")), - } - } else { - match cmd.stdout(Stdio::null()).stderr(Stdio::null()).spawn() { - Ok(_) => Ok(()), - Err(e) => Err(format!("error spawning swww-daemon: {e}")), - } - } + let err = cmd.exec(); + format!("failed to exec into swww-daemon: {err}") } fn is_daemon_running() -> Result {