mirror of
https://github.com/Llewellynvdm/conky.git
synced 2025-01-13 11:15:27 +00:00
This resolves #510.
This commit is contained in:
parent
a9196e3a0e
commit
623fb83379
24
src/exec.cc
24
src/exec.cc
@ -27,7 +27,6 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "exec.h"
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
@ -37,6 +36,7 @@
|
|||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include "conky.h"
|
#include "conky.h"
|
||||||
#include "core.h"
|
#include "core.h"
|
||||||
|
#include "exec.h"
|
||||||
#include "logging.h"
|
#include "logging.h"
|
||||||
#include "specials.h"
|
#include "specials.h"
|
||||||
#include "text_object.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
|
// 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
|
// create a pipe and close the ends if mode is something illegal
|
||||||
if (strcmp(mode, "r") == 0) {
|
if (strcmp(mode, "r") == 0) {
|
||||||
if (pipe(ends) != 0) {
|
if (pipe(ends) != 0) { return nullptr; }
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
parentend = ends[0];
|
parentend = ends[0];
|
||||||
childend = ends[1];
|
childend = ends[1];
|
||||||
} else if (strcmp(mode, "w") == 0) {
|
} else if (strcmp(mode, "w") == 0) {
|
||||||
if (pipe(ends) != 0) {
|
if (pipe(ends) != 0) { return nullptr; }
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
parentend = ends[1];
|
parentend = ends[1];
|
||||||
childend = ends[0];
|
childend = ends[0];
|
||||||
} else {
|
} else {
|
||||||
@ -93,9 +89,7 @@ static FILE *pid_popen(const char *command, const char *mode, pid_t *child) {
|
|||||||
close(parentend);
|
close(parentend);
|
||||||
|
|
||||||
// by dupping childend, the returned fd will have close-on-exec turned off
|
// by dupping childend, the returned fd will have close-on-exec turned off
|
||||||
if (fcntl(childend, F_DUPFD_CLOEXEC) == -1) {
|
if (fcntl(childend, F_DUPFD, 0) == -1) { perror("fcntl()"); }
|
||||||
perror("dup()");
|
|
||||||
}
|
|
||||||
close(childend);
|
close(childend);
|
||||||
|
|
||||||
execl("/bin/sh", "sh", "-c", command, (char *)nullptr);
|
execl("/bin/sh", "sh", "-c", command, (char *)nullptr);
|
||||||
@ -134,9 +128,7 @@ void exec_cb::work() {
|
|||||||
buf.append(b, length);
|
buf.append(b, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*buf.rbegin() == '\n') {
|
if (*buf.rbegin() == '\n') { buf.resize(buf.size() - 1); }
|
||||||
buf.resize(buf.size() - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> l(result_mutex);
|
std::lock_guard<std::mutex> l(result_mutex);
|
||||||
result = buf;
|
result = buf;
|
||||||
@ -324,7 +316,7 @@ double execbarval(struct text_object *obj) {
|
|||||||
if (obj->exec_handle != nullptr) {
|
if (obj->exec_handle != nullptr) {
|
||||||
return get_barnum((*obj->exec_handle)->get_result_copy().c_str());
|
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<struct execi_data *>(obj->data.opaque);
|
auto *ed = static_cast<struct execi_data *>(obj->data.opaque);
|
||||||
|
|
||||||
/* if ed is nullptr, there is nothing to do */
|
/* if ed is nullptr, there is nothing to do */
|
||||||
if (ed == nullptr) {
|
if (ed == nullptr) { return; }
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
delete obj->exec_handle;
|
delete obj->exec_handle;
|
||||||
obj->exec_handle = nullptr;
|
obj->exec_handle = nullptr;
|
||||||
|
Loading…
Reference in New Issue
Block a user