From 623fb833790725abc6965fa2893f07c9d49dca57 Mon Sep 17 00:00:00 2001 From: Brenden Matthews Date: Thu, 24 May 2018 20:24:09 -0400 Subject: [PATCH] Fix for $exec regression introduced by 4b92556f. (#514) This resolves #510. --- src/exec.cc | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/exec.cc b/src/exec.cc index 3eeb13b3..40c97c91 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -27,7 +27,6 @@ * */ -#include "exec.h" #include #include #include @@ -37,6 +36,7 @@ #include #include "conky.h" #include "core.h" +#include "exec.h" #include "logging.h" #include "specials.h" #include "text_object.h" @@ -59,15 +59,11 @@ static FILE *pid_popen(const char *command, const char *mode, pid_t *child) { // by running pipe after the strcmp's we make sure that we don't have to // create a pipe and close the ends if mode is something illegal if (strcmp(mode, "r") == 0) { - if (pipe(ends) != 0) { - return nullptr; - } + if (pipe(ends) != 0) { return nullptr; } parentend = ends[0]; childend = ends[1]; } else if (strcmp(mode, "w") == 0) { - if (pipe(ends) != 0) { - return nullptr; - } + if (pipe(ends) != 0) { return nullptr; } parentend = ends[1]; childend = ends[0]; } else { @@ -93,9 +89,7 @@ static FILE *pid_popen(const char *command, const char *mode, pid_t *child) { close(parentend); // by dupping childend, the returned fd will have close-on-exec turned off - if (fcntl(childend, F_DUPFD_CLOEXEC) == -1) { - perror("dup()"); - } + if (fcntl(childend, F_DUPFD, 0) == -1) { perror("fcntl()"); } close(childend); execl("/bin/sh", "sh", "-c", command, (char *)nullptr); @@ -134,9 +128,7 @@ void exec_cb::work() { buf.append(b, length); } - if (*buf.rbegin() == '\n') { - buf.resize(buf.size() - 1); - } + if (*buf.rbegin() == '\n') { buf.resize(buf.size() - 1); } std::lock_guard l(result_mutex); result = buf; @@ -324,7 +316,7 @@ double execbarval(struct text_object *obj) { if (obj->exec_handle != nullptr) { return get_barnum((*obj->exec_handle)->get_result_copy().c_str()); } - return 0.0; + return 0.0; } /** @@ -347,9 +339,7 @@ void free_execi(struct text_object *obj) { auto *ed = static_cast(obj->data.opaque); /* if ed is nullptr, there is nothing to do */ - if (ed == nullptr) { - return; - } + if (ed == nullptr) { return; } delete obj->exec_handle; obj->exec_handle = nullptr;