controller: Detach shell commands from polybar

Shell commands triggered from action tags used to block polybar until
they finished.

Since we are not actually interested in the output of the commands, it
makes sense to run them completely detached from polybar and have
polybar not block when executing these commands.

Now the spawned child processes no longer get killed when polybar
exits. This is fine because polybar is not responsible for these
processes since they were explicitly started by the user through click
commands.

Ref: 
Ref: 
This commit is contained in:
patrick96 2020-11-25 12:16:06 +01:00 committed by Patrick Ziegler
parent 0416093edc
commit 52eee95bf8
7 changed files with 86 additions and 38 deletions
src/components

View file

@ -15,9 +15,9 @@
#include "modules/meta/event_handler.hpp"
#include "modules/meta/factory.hpp"
#include "utils/actions.hpp"
#include "utils/command.hpp"
#include "utils/factory.hpp"
#include "utils/inotify.hpp"
#include "utils/process.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
#include "x11/connection.hpp"
@ -561,12 +561,8 @@ void controller::process_inputdata() {
try {
// Run input as command if it's not an input for a module
m_log.info("Forwarding command to shell... (input: %s)", cmd);
m_log.info("Executing shell command: %s", cmd);
auto shell_cmd = command_util::make_command<output_policy::IGNORED>(move(cmd));
shell_cmd->exec();
shell_cmd.reset();
process_util::fork_detached([cmd] { process_util::exec_sh(cmd.c_str()); });
process_update(true);
} catch (const application_error& err) {
m_log.err("controller: Error while forwarding input to shell -> %s", err.what());