feat: execNoRead

pull/676/head
Alex 2020-05-24 18:27:10 +02:00
parent 6ca4e14b29
commit 9b9d13ab0d
2 changed files with 21 additions and 10 deletions

View File

@ -34,6 +34,8 @@ inline int close(FILE* fp, pid_t pid) {
fclose(fp); fclose(fp);
do { do {
waitpid(pid, &stat, WCONTINUED | WUNTRACED);
if (WIFEXITED(stat)) { if (WIFEXITED(stat)) {
spdlog::debug("%s exited with code %d", WEXITSTATUS(stat)); spdlog::debug("%s exited with code %d", WEXITSTATUS(stat));
} else if (WIFSIGNALED(stat)) { } else if (WIFSIGNALED(stat)) {
@ -83,6 +85,14 @@ inline struct res exec(std::string cmd) {
return {WEXITSTATUS(stat), output}; return {WEXITSTATUS(stat), output};
} }
inline struct res execNoRead(std::string cmd) {
int pid;
auto fp = command::open(cmd, pid);
if (!fp) return {-1, ""};
auto stat = command::close(fp, pid);
return {WEXITSTATUS(stat), ""};
}
inline int32_t forkExec(std::string cmd) { inline int32_t forkExec(std::string cmd) {
if (cmd == "") return -1; if (cmd == "") return -1;

View File

@ -4,14 +4,13 @@
waybar::modules::Custom::Custom(const std::string& name, const std::string& id, waybar::modules::Custom::Custom(const std::string& name, const std::string& id,
const Json::Value& config) const Json::Value& config)
: ALabel(config, "custom-" + name, id, "{}"), name_(name), fp_(nullptr), pid_(-1) { : ALabel(config, "custom-" + name, id, "{}"), name_(name), fp_(nullptr), pid_(-1) {
if (config_["exec"].isString()) { if (interval_.count() > 0) {
if (interval_.count() > 0) { delayWorker();
delayWorker(); } else if (config_["exec"].isString()) {
} else { continuousWorker();
continuousWorker(); } else {
} dp.emit();
} }
dp.emit();
} }
waybar::modules::Custom::~Custom() { waybar::modules::Custom::~Custom() {
@ -25,14 +24,16 @@ void waybar::modules::Custom::delayWorker() {
thread_ = [this] { thread_ = [this] {
bool can_update = true; bool can_update = true;
if (config_["exec-if"].isString()) { if (config_["exec-if"].isString()) {
auto res = util::command::exec(config_["exec-if"].asString()); output_ = util::command::execNoRead(config_["exec-if"].asString());
if (res.exit_code != 0) { if (output_.exit_code != 0) {
can_update = false; can_update = false;
event_box_.hide(); event_box_.hide();
} }
} }
if (can_update) { if (can_update) {
output_ = util::command::exec(config_["exec"].asString()); if (config_["exec"].isString()) {
output_ = util::command::exec(config_["exec"].asString());
}
dp.emit(); dp.emit();
} }
thread_.sleep_for(interval_); thread_.sleep_for(interval_);