mirror of
https://github.com/polybar/polybar.git
synced 2026-03-31 04:27:46 +00:00
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: #770 Ref: #1680
This commit is contained in:
committed by
Patrick Ziegler
parent
0416093edc
commit
52eee95bf8
34
tests/unit_tests/utils/process.cpp
Normal file
34
tests/unit_tests/utils/process.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
#include "utils/process.hpp"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include "common/test.hpp"
|
||||
|
||||
using namespace polybar;
|
||||
using namespace process_util;
|
||||
|
||||
TEST(ForkDetached, is_detached) {
|
||||
pid_t pid = fork_detached([] { exec_sh("sleep 0.1"); });
|
||||
int status;
|
||||
|
||||
pid_t res = process_util::wait_for_completion_nohang(pid, &status);
|
||||
|
||||
ASSERT_NE(res, -1);
|
||||
|
||||
EXPECT_FALSE(WIFEXITED(status));
|
||||
}
|
||||
|
||||
TEST(ForkDetached, exit_code) {
|
||||
pid_t pid = fork_detached([] { exec_sh("exit 42"); });
|
||||
int status = 0;
|
||||
pid_t res = waitpid(pid, &status, 0);
|
||||
|
||||
EXPECT_EQ(res, pid);
|
||||
|
||||
EXPECT_EQ(WEXITSTATUS(status), 42);
|
||||
}
|
||||
Reference in New Issue
Block a user