From 36ad680a9819e02c414f1d47b37f622492ee9e2d Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 10 Feb 2010 19:04:31 +0100 Subject: [PATCH 1/6] Let print_execi and print_texeci call fill_p for filling p --- src/exec.cc | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/exec.cc b/src/exec.cc index eedb5712..95562398 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -310,6 +310,14 @@ void print_execp(struct text_object *obj, char *p, int p_max_size) free(buf); } +void fill_p(struct execi_data *ed, struct text_object *obj, char *p, int p_max_size) { + if(obj->parse == true) { + struct text_object subroot; + parse_conky_vars(&subroot, ed->buffer, p, p_max_size); + free_text_objects(&subroot); + } else snprintf(p, p_max_size, "%s", ed->buffer); +} + void print_execi(struct text_object *obj, char *p, int p_max_size) { struct execi_data *ed = (struct execi_data *)obj->data.opaque; @@ -323,11 +331,7 @@ void print_execi(struct text_object *obj, char *p, int p_max_size) read_exec(ed->cmd, ed->buffer, text_buffer_size); ed->last_update = current_update_time; } - if(obj->parse == true) { - struct text_object subroot; - parse_conky_vars(&subroot, ed->buffer, p, p_max_size); - free_text_objects(&subroot); - } else snprintf(p, p_max_size, "%s", ed->buffer); + fill_p(ed, obj, p, p_max_size); } void print_texeci(struct text_object *obj, char *p, int p_max_size) @@ -348,11 +352,7 @@ void print_texeci(struct text_object *obj, char *p, int p_max_size) } } else { std::lock_guard lock(ed->p_timed_thread->mutex()); - if(obj->parse == true) { - struct text_object subroot; - parse_conky_vars(&subroot, ed->buffer, p, p_max_size); - free_text_objects(&subroot); - } else snprintf(p, p_max_size, "%s", ed->buffer); + fill_p(ed, obj, p, p_max_size); } } From c010d7cd00f6aee6e8bbbc19f715b258456d3ecd Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 10 Feb 2010 19:45:42 +0100 Subject: [PATCH 2/6] Let execp use fill_p --- src/core.cc | 3 +++ src/exec.cc | 25 +++++++++++-------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/core.cc b/src/core.cc index 5ed7719e..f63ed42c 100644 --- a/src/core.cc +++ b/src/core.cc @@ -586,6 +586,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(execp, 0) scan_exec_arg(obj, arg); obj->verbatim_output = 1; + obj->parse = true; obj->callbacks.print = &print_execp; obj->callbacks.free = &free_exec; END OBJ(execbar, 0) @@ -618,6 +619,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->callbacks.free = &free_execi; END OBJ_ARG(execi, 0, "execi needs arguments") scan_execi_arg(obj, arg); + obj->parse = false; obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ_ARG(execpi, 0, "execpi needs arguments") @@ -628,6 +630,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->callbacks.free = &free_execi; END OBJ_ARG(texeci, 0, "texeci needs arguments") scan_execi_arg(obj, arg); + obj->parse = false; obj->callbacks.print = &print_texeci; obj->callbacks.free = &free_execi; END OBJ_ARG(texecpi, 0, "texecpi needs arguments") diff --git a/src/exec.cc b/src/exec.cc index 95562398..43a9b6d8 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -295,29 +295,26 @@ void print_exec(struct text_object *obj, char *p, int p_max_size) remove_deleted_chars(p); } +void fill_p(char *buffer, struct text_object *obj, char *p, int p_max_size) { + if(obj->parse == true) { + struct text_object subroot; + parse_conky_vars(&subroot, buffer, p, p_max_size); + free_text_objects(&subroot); + } else snprintf(p, p_max_size, "%s", buffer); +} + void print_execp(struct text_object *obj, char *p, int p_max_size) { - struct text_object subroot; char *buf; buf = (char*)malloc(text_buffer_size); memset(buf, 0, text_buffer_size); read_exec(obj->data.s, buf, text_buffer_size); - parse_conky_vars(&subroot, buf, p, p_max_size); - - free_text_objects(&subroot); + fill_p(buf, obj, p, p_max_size); free(buf); } -void fill_p(struct execi_data *ed, struct text_object *obj, char *p, int p_max_size) { - if(obj->parse == true) { - struct text_object subroot; - parse_conky_vars(&subroot, ed->buffer, p, p_max_size); - free_text_objects(&subroot); - } else snprintf(p, p_max_size, "%s", ed->buffer); -} - void print_execi(struct text_object *obj, char *p, int p_max_size) { struct execi_data *ed = (struct execi_data *)obj->data.opaque; @@ -331,7 +328,7 @@ void print_execi(struct text_object *obj, char *p, int p_max_size) read_exec(ed->cmd, ed->buffer, text_buffer_size); ed->last_update = current_update_time; } - fill_p(ed, obj, p, p_max_size); + fill_p(ed->buffer, obj, p, p_max_size); } void print_texeci(struct text_object *obj, char *p, int p_max_size) @@ -352,7 +349,7 @@ void print_texeci(struct text_object *obj, char *p, int p_max_size) } } else { std::lock_guard lock(ed->p_timed_thread->mutex()); - fill_p(ed, obj, p, p_max_size); + fill_p(ed->buffer, obj, p, p_max_size); } } From aea8d3ed525896d124a71484e73ecc97c0321a92 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 10 Feb 2010 21:23:21 +0100 Subject: [PATCH 3/6] Combine print_texeci and print_execi as much as possible --- src/core.cc | 8 ++++++-- src/exec.cc | 45 ++++++++++++++++++++------------------------- src/text_object.h | 1 + 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/core.cc b/src/core.cc index f63ed42c..28888131 100644 --- a/src/core.cc +++ b/src/core.cc @@ -620,23 +620,27 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ_ARG(execi, 0, "execi needs arguments") scan_execi_arg(obj, arg); obj->parse = false; + obj->thread = false; obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ_ARG(execpi, 0, "execpi needs arguments") scan_execi_arg(obj, arg); obj->verbatim_output = 1; obj->parse = true; + obj->thread = false; obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ_ARG(texeci, 0, "texeci needs arguments") scan_execi_arg(obj, arg); obj->parse = false; - obj->callbacks.print = &print_texeci; + obj->thread = true; + obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ_ARG(texecpi, 0, "texecpi needs arguments") scan_execi_arg(obj, arg); obj->parse = true; - obj->callbacks.print = &print_texeci; + obj->thread = true; + obj->callbacks.print = &print_execi; obj->callbacks.free = &free_execi; END OBJ(pre_exec, 0) scan_pre_exec_arg(obj, arg); diff --git a/src/exec.cc b/src/exec.cc index 43a9b6d8..5073fb4a 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -318,39 +318,34 @@ void print_execp(struct text_object *obj, char *p, int p_max_size) void print_execi(struct text_object *obj, char *p, int p_max_size) { struct execi_data *ed = (struct execi_data *)obj->data.opaque; + bool fillbuffer = true; if (!ed) return; - if (time_to_update(ed)) { - if (!ed->buffer) - ed->buffer = (char*)malloc(text_buffer_size); - read_exec(ed->cmd, ed->buffer, text_buffer_size); - ed->last_update = current_update_time; - } - fill_p(ed->buffer, obj, p, p_max_size); -} - -void print_texeci(struct text_object *obj, char *p, int p_max_size) -{ - struct execi_data *ed = (struct execi_data *)obj->data.opaque; - - if (!ed) - return; - - if (!ed->p_timed_thread) { - /* - * note that we don't register this thread with the - * timed_thread list, because we destroy it manually - */ - ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false); + if(obj->thread == true) { if (!ed->p_timed_thread) { - NORM_ERR("Error creating texeci timed thread"); + /* + * note that we don't register this thread with the + * timed_thread list, because we destroy it manually + */ + ed->p_timed_thread = timed_thread::create(std::bind(threaded_exec, std::placeholders::_1, obj), ed->interval * 1000000, false); + if (!ed->p_timed_thread) { + NORM_ERR("Error creating texeci timed thread"); + } + fillbuffer = false; + } else { + std::lock_guard lock(ed->p_timed_thread->mutex()); } } else { - std::lock_guard lock(ed->p_timed_thread->mutex()); - fill_p(ed->buffer, obj, p, p_max_size); + if (time_to_update(ed)) { + if (!ed->buffer) + ed->buffer = (char*)malloc(text_buffer_size); + read_exec(ed->cmd, ed->buffer, text_buffer_size); + ed->last_update = current_update_time; + } } + if(fillbuffer) fill_p(ed->buffer, obj, p, p_max_size); } double execbarval(struct text_object *obj) diff --git a/src/text_object.h b/src/text_object.h index e45020a7..df7b6948 100644 --- a/src/text_object.h +++ b/src/text_object.h @@ -96,6 +96,7 @@ struct text_object { long line; struct obj_cb callbacks; bool parse; //if this true then data.s should still be parsed + bool thread; //if this true then data.s should be set by a seperate thread }; /* text object list helpers */ From f0ed7830419448ddfa985c4b24d49495d17ae4aa Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 10 Feb 2010 23:31:35 +0100 Subject: [PATCH 4/6] dog^H^H^Hcat should become cat in all exec-related vars --- src/exec.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/exec.cc b/src/exec.cc index 5073fb4a..31eb3a28 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -301,6 +301,7 @@ void fill_p(char *buffer, struct text_object *obj, char *p, int p_max_size) { parse_conky_vars(&subroot, buffer, p, p_max_size); free_text_objects(&subroot); } else snprintf(p, p_max_size, "%s", buffer); + remove_deleted_chars(p); } void print_execp(struct text_object *obj, char *p, int p_max_size) From 463836ebf9f47df31d22a3c2af6fc677cdb973b5 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 11 Feb 2010 01:08:25 +0100 Subject: [PATCH 5/6] Combine print_execp and print_exec as much as possible --- src/core.cc | 5 ++++- src/exec.cc | 8 +------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/core.cc b/src/core.cc index 28888131..f854edd0 100644 --- a/src/core.cc +++ b/src/core.cc @@ -581,13 +581,16 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* BUILD_IMLIB2 */ END OBJ(exec, 0) scan_exec_arg(obj, arg); + obj->parse = false; + obj->thread = false; obj->callbacks.print = &print_exec; obj->callbacks.free = &free_exec; END OBJ(execp, 0) scan_exec_arg(obj, arg); obj->verbatim_output = 1; obj->parse = true; - obj->callbacks.print = &print_execp; + obj->thread = false; + obj->callbacks.print = &print_exec; obj->callbacks.free = &free_exec; END OBJ(execbar, 0) scan_exec_arg(obj, arg); diff --git a/src/exec.cc b/src/exec.cc index 31eb3a28..46aba1c7 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -289,12 +289,6 @@ void scan_execgraph_arg(struct text_object *obj, const char *arg) } #endif /* BUILD_X11 */ -void print_exec(struct text_object *obj, char *p, int p_max_size) -{ - read_exec(obj->data.s, p, p_max_size); - remove_deleted_chars(p); -} - void fill_p(char *buffer, struct text_object *obj, char *p, int p_max_size) { if(obj->parse == true) { struct text_object subroot; @@ -304,7 +298,7 @@ void fill_p(char *buffer, struct text_object *obj, char *p, int p_max_size) { remove_deleted_chars(p); } -void print_execp(struct text_object *obj, char *p, int p_max_size) +void print_exec(struct text_object *obj, char *p, int p_max_size) { char *buf; From b206ecc93d13144fb1732adfd53a01f7af77fee8 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Thu, 11 Feb 2010 14:44:15 +0100 Subject: [PATCH 6/6] new should be combined with delete instead of free (to stop valgrind from complaining) --- src/exec.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/exec.cc b/src/exec.cc index 46aba1c7..dd297b4a 100644 --- a/src/exec.cc +++ b/src/exec.cc @@ -249,7 +249,7 @@ void scan_execi_arg(struct text_object *obj, const char *arg) if (sscanf(arg, "%f %n", &ed->interval, &n) <= 0) { NORM_ERR("${execi* command}"); - free(ed); + delete ed; return; } ed->cmd = strndup(arg + n, text_buffer_size);