2018-08-08 21:54:58 +00:00
|
|
|
#include <csignal>
|
2020-07-21 02:36:48 +00:00
|
|
|
#include <list>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
2019-05-18 23:44:45 +00:00
|
|
|
#include <spdlog/spdlog.h>
|
2019-04-17 12:19:04 +00:00
|
|
|
#include "client.hpp"
|
2018-08-08 21:54:58 +00:00
|
|
|
|
2020-07-21 02:36:48 +00:00
|
|
|
sig_atomic_t is_inserting_pid = false;
|
|
|
|
std::list<pid_t> reap;
|
|
|
|
|
|
|
|
static void handler(int sig) {
|
|
|
|
int saved_errno = errno;
|
|
|
|
if (!is_inserting_pid) {
|
|
|
|
for (auto it = reap.begin(); it != reap.end(); ++it) {
|
|
|
|
if (waitpid(*it, nullptr, WNOHANG) == *it) {
|
|
|
|
it = reap.erase(it);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errno = saved_errno;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline void installSigChldHandler(void) {
|
|
|
|
struct sigaction sa;
|
|
|
|
sigemptyset(&sa.sa_mask);
|
|
|
|
sa.sa_handler = handler;
|
|
|
|
sigaction(SIGCHLD, &sa, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-04-17 12:19:04 +00:00
|
|
|
int main(int argc, char* argv[]) {
|
2018-08-08 21:54:58 +00:00
|
|
|
try {
|
2019-04-18 15:43:16 +00:00
|
|
|
auto client = waybar::Client::inst();
|
2019-04-17 12:19:04 +00:00
|
|
|
std::signal(SIGUSR1, [](int /*signal*/) {
|
2019-04-18 15:43:16 +00:00
|
|
|
for (auto& bar : waybar::Client::inst()->bars) {
|
2018-11-23 15:04:29 +00:00
|
|
|
bar->toggle();
|
2018-08-08 21:54:58 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-03-18 17:46:44 +00:00
|
|
|
for (int sig = SIGRTMIN + 1; sig <= SIGRTMAX; ++sig) {
|
2019-04-18 15:43:16 +00:00
|
|
|
std::signal(sig, [](int sig) {
|
|
|
|
for (auto& bar : waybar::Client::inst()->bars) {
|
2019-03-18 17:46:44 +00:00
|
|
|
bar->handleSignal(sig);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-07-21 02:36:48 +00:00
|
|
|
installSigChldHandler();
|
2019-03-18 17:46:44 +00:00
|
|
|
|
2019-04-18 15:43:16 +00:00
|
|
|
auto ret = client->main(argc, argv);
|
|
|
|
delete client;
|
|
|
|
return ret;
|
2018-08-08 21:54:58 +00:00
|
|
|
} catch (const std::exception& e) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::error("{}", e.what());
|
2018-08-08 21:54:58 +00:00
|
|
|
return 1;
|
|
|
|
} catch (const Glib::Exception& e) {
|
2019-05-18 23:44:45 +00:00
|
|
|
spdlog::error("{}", static_cast<std::string>(e.what()));
|
2018-08-08 21:54:58 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|