diff --git a/include/util/command.hpp b/include/util/command.hpp index 4b9decaa..58c59a96 100644 --- a/include/util/command.hpp +++ b/include/util/command.hpp @@ -109,7 +109,7 @@ inline FILE* open(const std::string& cmd, int& pid, const std::string& output_na ::close(fd[0]); dup2(fd[1], 1); setpgid(child_pid, child_pid); - if (output_name != "") { + if (!output_name.empty()) { setenv("WAYBAR_OUTPUT_NAME", output_name.c_str(), 1); } execlp("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0); @@ -138,7 +138,7 @@ inline struct res execNoRead(const std::string& cmd) { return {WEXITSTATUS(stat), ""}; } -inline int32_t forkExec(const std::string& cmd) { +inline int32_t forkExec(const std::string& cmd, const std::string& output_name) { if (cmd == "") return -1; pid_t pid = fork(); @@ -157,6 +157,9 @@ inline int32_t forkExec(const std::string& cmd) { err = pthread_sigmask(SIG_UNBLOCK, &mask, nullptr); if (err != 0) spdlog::error("pthread_sigmask in forkExec failed: {}", strerror(err)); setpgid(pid, pid); + if (!output_name.empty()) { + setenv("WAYBAR_OUTPUT_NAME", output_name.c_str(), 1); + } execl("/bin/sh", "sh", "-c", cmd.c_str(), (char*)0); exit(0); } else { @@ -169,4 +172,8 @@ inline int32_t forkExec(const std::string& cmd) { return pid; } +inline int32_t forkExec(const std::string& cmd) { + return forkExec(cmd, ""); +} + } // namespace waybar::util::command diff --git a/src/ALabel.cpp b/src/ALabel.cpp index 4e6d3349..d251d896 100644 --- a/src/ALabel.cpp +++ b/src/ALabel.cpp @@ -190,7 +190,7 @@ bool waybar::ALabel::handleToggle(GdkEventButton* const& e) { } void ALabel::handleGtkMenuEvent(GtkMenuItem* /*menuitem*/, gpointer data) { - waybar::util::command::res res = waybar::util::command::exec((char*)data, "GtkMenu"); + waybar::util::command::forkExec((char*)data, "GtkMenu"); } std::string ALabel::getState(uint8_t value, bool lesser) {