From 8db1e1a2a2a33062da0c544e7686d977ab971deb Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 14:00:26 +0100 Subject: [PATCH 01/21] Make sure that conky.cc compiles in FreeBSD --- src/conky.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/conky.cc b/src/conky.cc index 85b8c3c3..6a782e87 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -550,6 +550,13 @@ int percent_print(char *buf, int size, unsigned value) return spaced_print(buf, size, "%u", pad_percents, value); } +#if defined(__FreeBSD__) +unsigned long long llabs(long long num) { + if(num < 0) return -num; + else return num; +} +#endif + /* converts from bytes to human readable format (K, M, G, T) * * The algorithm always divides by 1024, as unit-conversion of byte From 7791e349001406f419b5ccc9bd8fd34c5058eab0 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 15:09:12 +0100 Subject: [PATCH 02/21] Make sure that fs.cc compiles in FreeBSD --- src/fs.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/fs.cc b/src/fs.cc index 2503c164..1ace9c36 100644 --- a/src/fs.cc +++ b/src/fs.cc @@ -51,6 +51,10 @@ #ifdef HAVE_SYS_MOUNT_H #include #endif +#if defined(__FreeBSD__) +#include "freebsd.h" +#endif + #if !defined(HAVE_STRUCT_STATFS_F_FSTYPENAME) && !defined (__OpenBSD__) && !defined(__FreeBSD__) #include From 7de3b9736ad1befa551568c9d12d0d4a118a9e47 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 15:26:44 +0100 Subject: [PATCH 03/21] Make sure that freebsd.cc compiles in FreeBSD --- src/freebsd.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/freebsd.cc b/src/freebsd.cc index 9cef5856..40956083 100644 --- a/src/freebsd.cc +++ b/src/freebsd.cc @@ -302,7 +302,7 @@ void get_cpu_count(void) info.cpu_count = 0; } - info.cpu_usage = malloc((info.cpu_count + 1) * sizeof(float)); + info.cpu_usage = (float *) malloc((info.cpu_count + 1) * sizeof(float)); if (info.cpu_usage == NULL) { CRIT_ERR(NULL, NULL, "malloc"); } @@ -331,14 +331,14 @@ void update_cpu_usage(void) if (!global_cpu) { malloc_cpu_size = (info.cpu_count + 1) * sizeof(struct cpu_info); - cpu = malloc(malloc_cpu_size); + cpu = (cpu_info *) malloc(malloc_cpu_size); memset(cpu, 0, malloc_cpu_size); global_cpu = cpu; } /* cpu[0] is overall stats, get it from separate sysctl */ cp_len = CPUSTATES * sizeof(long); - cp_time = malloc(cp_len); + cp_time = (long int *) malloc(cp_len); if (sysctlbyname("kern.cp_time", cp_time, &cp_len, NULL, 0) < 0) { fprintf(stderr, "Cannot get kern.cp_time\n"); @@ -364,7 +364,7 @@ void update_cpu_usage(void) /* per-core stats */ cp_len = CPUSTATES * sizeof(long) * info.cpu_count; - cp_time = malloc(cp_len); + cp_time = (long int *) malloc(cp_len); /* on e.g. i386 SMP we may have more values than actual cpus; this will just drop extra values */ if (sysctlbyname("kern.cp_times", cp_time, &cp_len, NULL, 0) < 0 && errno != ENOMEM) { @@ -734,7 +734,7 @@ proc_find_top(struct process **cpu, struct process **mem) } p = kvm_getprocs(kd, KERN_PROC_PROC, 0, &n_processes); - processes = malloc(n_processes * sizeof(struct process)); + processes = (process *) malloc(n_processes * sizeof(struct process)); for (i = 0; i < n_processes; i++) { if (!((p[i].ki_flag & P_SYSTEM)) && p[i].ki_comm != NULL) { @@ -751,7 +751,7 @@ proc_find_top(struct process **cpu, struct process **mem) for (i = 0; i < 10 && i < n_processes; i++) { struct process *tmp, *ttmp; - tmp = malloc(sizeof(struct process)); + tmp = (process *) malloc(sizeof(struct process)); tmp->pid = processes[i].pid; tmp->amount = processes[i].amount; tmp->name = strndup(processes[i].name, text_buffer_size); @@ -770,7 +770,7 @@ proc_find_top(struct process **cpu, struct process **mem) for (i = 0; i < 10 && i < n_processes; i++) { struct process *tmp, *ttmp; - tmp = malloc(sizeof(struct process)); + tmp = (process *) malloc(sizeof(struct process)); tmp->pid = processes[i].pid; tmp->amount = processes[i].amount; tmp->name = strndup(processes[i].name, text_buffer_size); From 4c06be139c621df411141e4061ece9e3a2322fe1 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 15:36:22 +0100 Subject: [PATCH 04/21] Make sure that bsdapm.cc compiles in FreeBSD --- src/bsdapm.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bsdapm.cc b/src/bsdapm.cc index 830ed32d..89fb60fb 100644 --- a/src/bsdapm.cc +++ b/src/bsdapm.cc @@ -33,6 +33,7 @@ #include #include #include +#include #define APMDEV "/dev/apm" #define APM_UNKNOWN 255 From da4e9349f88f9f8173dbeefe2473c88f717b786f Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 20:20:45 +0100 Subject: [PATCH 05/21] Link with kvm when building in FreeBSD --- cmake/ConkyPlatformChecks.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index 0abc8180..ed63d83d 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -43,6 +43,7 @@ endif(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") set(OS_FREEBSD true) + set(conky_libs ${conky_libs} -lkvm) endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") From 3763c263c3e3a367d250024d424fdce49affe059 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 21:22:31 +0100 Subject: [PATCH 06/21] Make sure bsdapm functions can be reached --- src/bsdapm.h | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/bsdapm.h b/src/bsdapm.h index ffbf8853..c80127bf 100644 --- a/src/bsdapm.h +++ b/src/bsdapm.h @@ -30,16 +30,8 @@ #ifndef _BSDAPM_H #define _BSDAPM_H -#ifdef __cplusplus -extern "C" { -#endif - void print_apm_adapter(struct text_object *, char *, int); void print_apm_battery_life(struct text_object *, char *, int); void print_apm_battery_time(struct text_object *, char *, int); -#ifdef __cplusplus -} -#endif - #endif /* _BSDAPM_H */ From 4793655974f8dbcf78da2983e68256c8451b408d Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 21:35:13 +0100 Subject: [PATCH 07/21] Link with devstat when building in FreeBSD --- cmake/ConkyPlatformChecks.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/ConkyPlatformChecks.cmake b/cmake/ConkyPlatformChecks.cmake index ed63d83d..6d26b971 100644 --- a/cmake/ConkyPlatformChecks.cmake +++ b/cmake/ConkyPlatformChecks.cmake @@ -43,7 +43,7 @@ endif(CMAKE_SYSTEM_NAME MATCHES "Linux") if(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") set(OS_FREEBSD true) - set(conky_libs ${conky_libs} -lkvm) + set(conky_libs ${conky_libs} -lkvm -ldevstat) endif(CMAKE_SYSTEM_NAME MATCHES "FreeBSD") if(CMAKE_SYSTEM_NAME MATCHES "OpenBSD") From 53af0f379fd4a300c3a7c4b09dae6b97c3595e8d Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Sun, 14 Feb 2010 22:58:02 +0100 Subject: [PATCH 08/21] Fix multiple definitions when building in FreeBSD --- src/conky.cc | 4 ++++ src/freebsd.cc | 2 ++ src/freebsd.h | 2 -- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 6a782e87..ebffb071 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -157,6 +157,10 @@ void *global_cpu = NULL; unsigned int max_text_width = 0; int ifup_strictness = IFUP_UP; +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +extern kvm_t *kd; +#endif + int argc_copy; char** argv_copy; diff --git a/src/freebsd.cc b/src/freebsd.cc index 40956083..e53ec7b4 100644 --- a/src/freebsd.cc +++ b/src/freebsd.cc @@ -67,6 +67,8 @@ #define FREEBSD_DEBUG #endif +kvm_t *kd; + __attribute__((gnu_inline)) inline void proc_find_top(struct process **cpu, struct process **mem); diff --git a/src/freebsd.h b/src/freebsd.h index c7ce372c..833e9e35 100644 --- a/src/freebsd.h +++ b/src/freebsd.h @@ -17,8 +17,6 @@ extern "C" { #endif -kvm_t *kd; - int get_entropy_avail(unsigned int *); int get_entropy_poolsize(unsigned int *); From a6debedc93d0926d4ae27f60a74131318bade450 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Mon, 15 Feb 2010 16:02:29 +0100 Subject: [PATCH 09/21] Fix 3 memleaks that happen when scroll receives wrong args --- src/core.cc | 4 ++-- src/scroll.cc | 10 ++++++++-- src/scroll.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/core.cc b/src/core.cc index f854edd0..c8ba4403 100644 --- a/src/core.cc +++ b/src/core.cc @@ -136,7 +136,7 @@ static struct text_object *create_plain_text(const char *s) } /* construct_text_object() creates a new text_object */ -struct text_object *construct_text_object(const char *s, const char *arg, long +struct text_object *construct_text_object(char *s, const char *arg, long line, void **ifblock_opaque, void *free_at_crash) { // struct text_object *obj = new_text_object(); @@ -1565,7 +1565,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long /* allocate a follower to reset any color changes */ obj->next = new_text_object_internal(); #endif /* BUILD_X11 */ - parse_scroll_arg(obj, arg, free_at_crash); + parse_scroll_arg(obj, arg, free_at_crash, s); obj->callbacks.print = &print_scroll; obj->callbacks.free = &free_scroll; END OBJ_ARG(combine, 0, "combine needs arguments: ") diff --git a/src/scroll.cc b/src/scroll.cc index 43a0203e..354b74ac 100644 --- a/src/scroll.cc +++ b/src/scroll.cc @@ -42,7 +42,7 @@ struct scroll_data { long resetcolor; }; -void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash) +void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash, char *free_at_crash2) { struct scroll_data *sd; int n1 = 0, n2 = 0; @@ -52,8 +52,14 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr sd->resetcolor = get_current_text_color(); sd->step = 1; - if (!arg || sscanf(arg, "%u %n", &sd->show, &n1) <= 0) + if (!arg || sscanf(arg, "%u %n", &sd->show, &n1) <= 0) { + free(sd); +#ifdef BUILD_X11 + free(obj->next); +#endif + free(free_at_crash2); CRIT_ERR(obj, free_at_crash, "scroll needs arguments: [] "); + } sscanf(arg + n1, "%u %n", &sd->step, &n2); if (*(arg + n1 + n2)) { diff --git a/src/scroll.h b/src/scroll.h index b11331b5..8d2d6777 100644 --- a/src/scroll.h +++ b/src/scroll.h @@ -30,7 +30,7 @@ #ifndef _SCROLL_H #define _SCROLL_H -void parse_scroll_arg(struct text_object *, const char *, void *); +void parse_scroll_arg(struct text_object *, const char *, void *, char *); void print_scroll(struct text_object *, char *, int); void free_scroll(struct text_object *); From 247c62c5d85f2331dce29a1cf0826208f4957745 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Tue, 16 Feb 2010 13:27:49 +0100 Subject: [PATCH 10/21] Fix another memleak in scroll --- src/scroll.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/scroll.cc b/src/scroll.cc index 354b74ac..08b3f8f8 100644 --- a/src/scroll.cc +++ b/src/scroll.cc @@ -82,6 +82,7 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr sd->start = 0; obj->sub = (struct text_object *)malloc(sizeof(struct text_object)); extract_variable_text_internal(obj->sub, sd->text); + free(sd->text); obj->data.opaque = sd; From b9a7b0e33e5c2bf2da9983d1d47f708ce705f40d Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Tue, 16 Feb 2010 15:45:32 +0100 Subject: [PATCH 11/21] Fix last memleaks in scroll This fix reverts reverts a part of commit 08122354a9b86722e7a7b218f8deeae80235dbb1 this is necessary because that commit blocks the calling of free_scroll --- src/core.cc | 1 - src/scroll.cc | 8 +++++--- src/specials.cc | 2 +- src/specials.h | 2 ++ 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/core.cc b/src/core.cc index c8ba4403..4277ad64 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1563,7 +1563,6 @@ struct text_object *construct_text_object(char *s, const char *arg, long END OBJ(scroll, 0) #ifdef BUILD_X11 /* allocate a follower to reset any color changes */ - obj->next = new_text_object_internal(); #endif /* BUILD_X11 */ parse_scroll_arg(obj, arg, free_at_crash, s); obj->callbacks.print = &print_scroll; diff --git a/src/scroll.cc b/src/scroll.cc index 08b3f8f8..505c8b47 100644 --- a/src/scroll.cc +++ b/src/scroll.cc @@ -82,14 +82,11 @@ void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_cr sd->start = 0; obj->sub = (struct text_object *)malloc(sizeof(struct text_object)); extract_variable_text_internal(obj->sub, sd->text); - free(sd->text); obj->data.opaque = sd; #ifdef BUILD_X11 /* add a color object right after scroll to reset any color changes */ - obj->next->data.l = sd->resetcolor; - obj->next->callbacks.print = &new_fg; #endif /* BUILD_X11 */ } @@ -160,6 +157,11 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size) if(buf[sd->start] == 0 || sd->start > strlen(&(buf[0]))){ sd->start = 0; } +#ifdef BUILD_X11 + //reset color when scroll is finished + if (output_methods & TO_X) + new_special(p + strlen(p), FG)->arg = sd->resetcolor; +#endif } void free_scroll(struct text_object *obj) diff --git a/src/specials.cc b/src/specials.cc index 833f9836..1252b43f 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -251,7 +251,7 @@ char *scan_graph(struct text_object *obj, const char *args, double defscale) * Printing various special text objects */ -static struct special_t *new_special(char *buf, enum special_types t) +struct special_t *new_special(char *buf, enum special_types t) { if (special_count >= max_specials) { CRIT_ERR(NULL, NULL, "too many special things in text"); diff --git a/src/specials.h b/src/specials.h index 743d157a..a3d9783f 100644 --- a/src/specials.h +++ b/src/specials.h @@ -121,4 +121,6 @@ void new_alignc(struct text_object *, char *, int); void new_goto(struct text_object *, char *, int); void new_tab(struct text_object *, char *, int); +struct special_t *new_special(char *buf, enum special_types t); + #endif /* _SPECIALS_H */ From c06e54157ffeb253f1a45d69937733fd9df9e600 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Tue, 16 Feb 2010 17:00:33 +0100 Subject: [PATCH 12/21] Fix building in ncurses --- src/conky.cc | 30 +++++++++++++++--------------- src/specials.cc | 4 ++-- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index ebffb071..ae0a00a6 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -64,7 +64,7 @@ #include #include #include -#ifdef NCURSES +#ifdef BUILD_NCURSES #include #endif #ifdef BUILD_WEATHER_XOAP @@ -1121,11 +1121,11 @@ static inline void set_foreground_color(long c) XSetForeground(display, window.gc, current_color); } #endif /* BUILD_X11 */ -#ifdef NCURSES +#ifdef BUILD_NCURSES if (output_methods & TO_NCURSES) { attron(COLOR_PAIR(c)); } -#endif /* NCURSES */ +#endif /* BUILD_NCURSES */ UNUSED(c); return; } @@ -1163,7 +1163,7 @@ static void draw_string(const char *s) if ((output_methods & APPEND_FILE) && draw_mode == FG && append_fpointer) { fprintf(append_fpointer, "%s\n", s_with_newlines); } -#ifdef NCURSES +#ifdef BUILD_NCURSES if ((output_methods & TO_NCURSES) && draw_mode == FG) { printw("%s", s_with_newlines); } @@ -1694,11 +1694,11 @@ int draw_each_line_inner(char *s, int special_index, int last_special_applied) cur_y += cur_y_add; #endif /* BUILD_X11 */ draw_string(s); -#ifdef NCURSES +#ifdef BUILD_NCURSES if (output_methods & TO_NCURSES) { printw("\n"); } -#endif /* NCURSES */ +#endif /* BUILD_NCURSES */ #ifdef BUILD_X11 if (output_methods & TO_X) cur_y += font_descent(); @@ -1717,11 +1717,11 @@ static int draw_line(char *s, int special_index) return draw_each_line_inner(s, special_index, -1); } #endif /* BUILD_X11 */ -#ifdef NCURSES +#ifdef BUILD_NCURSES if (output_methods & TO_NCURSES) { return draw_each_line_inner(s, special_index, -1); } -#endif /* NCURSES */ +#endif /* BUILD_NCURSES */ draw_string(s); UNUSED(special_index); return 0; @@ -1759,10 +1759,10 @@ static void draw_text(void) } setup_fonts(); #endif /* BUILD_X11 */ -#ifdef NCURSES +#ifdef BUILD_NCURSES init_pair(COLOR_WHITE, COLOR_WHITE, COLOR_BLACK); attron(COLOR_PAIR(COLOR_WHITE)); -#endif /* NCURSES */ +#endif /* BUILD_NCURSES */ for_each_line(text_buffer, draw_line); #if defined(BUILD_LUA) && defined(BUILD_X11) llua_draw_post_hook(); @@ -2228,7 +2228,7 @@ static void main_loop(void) if(t > 0) usleep((useconds_t)t); update_text(); draw_stuff(); -#ifdef NCURSES +#ifdef BUILD_NCURSES if(output_methods & TO_NCURSES) { refresh(); clear(); @@ -2376,7 +2376,7 @@ void clean_up(void *memtofree1, void* memtofree2) free_update_callbacks(); -#ifdef NCURSES +#ifdef BUILD_NCURSES if(output_methods & TO_NCURSES) { endwin(); } @@ -3206,7 +3206,7 @@ char load_config_file(const char *f) if(string_to_bool(value)) output_methods |= TO_STDERR; } -#ifdef NCURSES +#ifdef BUILD_NCURSES CONF("out_to_ncurses") { if(string_to_bool(value)) { initscr(); @@ -3709,7 +3709,7 @@ char load_config_file(const char *f) if (!output_methods) { CRIT_ERR(0, 0, "no output_methods have been selected; exiting"); } -#if defined(NCURSES) +#if defined(BUILD_NCURSES) #if defined(BUILD_X11) if ((output_methods & TO_X) && (output_methods & TO_NCURSES)) { NORM_ERR("out_to_x and out_to_ncurses are incompatible, turning out_to_ncurses off"); @@ -3721,7 +3721,7 @@ char load_config_file(const char *f) NORM_ERR("out_to_ncurses conflicts with out_to_console and out_to_stderr, disabling the later ones"); output_methods &= ~(TO_STDOUT | TO_STDERR); } -#endif /* NCURSES */ +#endif /* BUILD_NCURSES */ return TRUE; } diff --git a/src/specials.cc b/src/specials.cc index 1252b43f..60cc141f 100644 --- a/src/specials.cc +++ b/src/specials.cc @@ -472,10 +472,10 @@ void new_fg(struct text_object *obj, char *p, int p_max_size) if (output_methods & TO_X) new_special(p, FG)->arg = obj->data.l; #endif /* BUILD_X11 */ -#ifdef NCURSES +#ifdef BUILD_NCURSES if (output_methods & TO_NCURSES) new_special(p, FG)->arg = obj->data.l; -#endif /* NCURSES */ +#endif /* BUILD_NCURSES */ UNUSED(obj); UNUSED(p); UNUSED(p_max_size); From efb39867c7a65a4a2cb20a9907a3919c41a0cfb2 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Tue, 16 Feb 2010 19:20:48 +0100 Subject: [PATCH 13/21] Fix 3 memleaks in ncurses-related code --- src/conky.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/conky.cc b/src/conky.cc index ae0a00a6..17780e12 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -161,6 +161,10 @@ int ifup_strictness = IFUP_UP; extern kvm_t *kd; #endif +#ifdef BUILD_NCURSES +WINDOW* ncurses_screen; +#endif + int argc_copy; char** argv_copy; @@ -2379,6 +2383,7 @@ void clean_up(void *memtofree1, void* memtofree2) #ifdef BUILD_NCURSES if(output_methods & TO_NCURSES) { endwin(); + delwin(ncurses_screen); } #endif conftree_empty(currentconffile); @@ -3209,7 +3214,7 @@ char load_config_file(const char *f) #ifdef BUILD_NCURSES CONF("out_to_ncurses") { if(string_to_bool(value)) { - initscr(); + ncurses_screen = initscr(); start_color(); output_methods |= TO_NCURSES; } From 26fc643ffb91ecf664096166cc52ca7c65ae7aab Mon Sep 17 00:00:00 2001 From: Cesare Tirabassi Date: Wed, 17 Feb 2010 12:51:11 +0100 Subject: [PATCH 14/21] Fix commit 2c8ef724e65a847ec8fd81623b59c39a6d8bfea1 which fails to build when X11 is not enabled --- src/conky.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/conky.cc b/src/conky.cc index 17780e12..8634f54d 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2916,6 +2916,7 @@ static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **va return 0; } +#ifdef X11 void setalignment(int* text_alignment, unsigned int windowtype, const char* value, const char *f, int line, bool conffile) { #ifdef OWN_WINDOW if (windowtype == TYPE_DOCK) { @@ -2936,6 +2937,7 @@ void setalignment(int* text_alignment, unsigned int windowtype, const char* valu CONF_ERR; } } +#endif /* X11 */ char load_config_file(const char *f) { From 549e9740ff3dd5feec2bdf69ae05bfe24a79a118 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 17 Feb 2010 13:21:07 +0100 Subject: [PATCH 15/21] Fix previous commit which breaks building with X11 --- src/conky.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 8634f54d..6ecf68b2 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -2916,7 +2916,7 @@ static int do_config_step(int *line, FILE *fp, char *buf, char **name, char **va return 0; } -#ifdef X11 +#ifdef BUILD_X11 void setalignment(int* text_alignment, unsigned int windowtype, const char* value, const char *f, int line, bool conffile) { #ifdef OWN_WINDOW if (windowtype == TYPE_DOCK) { @@ -2937,7 +2937,7 @@ void setalignment(int* text_alignment, unsigned int windowtype, const char* valu CONF_ERR; } } -#endif /* X11 */ +#endif /* BUILD_X11 */ char load_config_file(const char *f) { From afffe49977729a0c186cf8e97656a5117cc94b45 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 17 Feb 2010 14:49:06 +0100 Subject: [PATCH 16/21] Undo efb39867c7a65a4a2cb20a9907a3919c41a0cfb2 , memleaks were falsely reported by valgrind --- src/conky.cc | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/conky.cc b/src/conky.cc index 6ecf68b2..9a12e233 100644 --- a/src/conky.cc +++ b/src/conky.cc @@ -161,10 +161,6 @@ int ifup_strictness = IFUP_UP; extern kvm_t *kd; #endif -#ifdef BUILD_NCURSES -WINDOW* ncurses_screen; -#endif - int argc_copy; char** argv_copy; @@ -2383,7 +2379,6 @@ void clean_up(void *memtofree1, void* memtofree2) #ifdef BUILD_NCURSES if(output_methods & TO_NCURSES) { endwin(); - delwin(ncurses_screen); } #endif conftree_empty(currentconffile); @@ -3216,7 +3211,7 @@ char load_config_file(const char *f) #ifdef BUILD_NCURSES CONF("out_to_ncurses") { if(string_to_bool(value)) { - ncurses_screen = initscr(); + initscr(); start_color(); output_methods |= TO_NCURSES; } From 3ceb8cb5709b8485f8d9b6b991bbd1863b306bb1 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 17 Feb 2010 17:49:03 +0100 Subject: [PATCH 17/21] Add support for scrolling in the other direction --- doc/variables.xml | 8 +++++--- src/scroll.cc | 39 ++++++++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index ba3daca1..88766447 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -3075,12 +3075,14 @@ - + - Scroll 'text' by 'step' characters showing + Scroll 'text' by 'step' characters to the left + or right (set 'direction' to 'left' or 'right') showing 'length' number of characters at the same time. The text may also contain variables. 'step' is optional and defaults - to 1 if not set. If a var creates output on multiple lines + to 1 if not set. 'direction' is optional and defaults to left + if not set. If a var creates output on multiple lines then the lines are placed behind each other separated with a '|'-sign. If you change the textcolor inside $scroll it will automatically have it's old value back at the end of diff --git a/src/scroll.cc b/src/scroll.cc index 505c8b47..2255a7b3 100644 --- a/src/scroll.cc +++ b/src/scroll.cc @@ -34,35 +34,49 @@ #include "text_object.h" #include +#define SCROLL_LEFT true +#define SCROLL_RIGHT false + struct scroll_data { char *text; unsigned int show; unsigned int step; - unsigned int start; + signed int start; long resetcolor; + bool direction; }; void parse_scroll_arg(struct text_object *obj, const char *arg, void *free_at_crash, char *free_at_crash2) { struct scroll_data *sd; int n1 = 0, n2 = 0; + char dirarg[6]; sd = (struct scroll_data *)malloc(sizeof(struct scroll_data)); memset(sd, 0, sizeof(struct scroll_data)); sd->resetcolor = get_current_text_color(); sd->step = 1; - if (!arg || sscanf(arg, "%u %n", &sd->show, &n1) <= 0) { + sd->direction = SCROLL_LEFT; + + if (arg && sscanf(arg, "%5s %n", dirarg, &n1) == 1) { + if (strcasecmp(dirarg, "right") == 0 || strcasecmp(dirarg, "r") == 0) + sd->direction = SCROLL_RIGHT; + else if ( strcasecmp(dirarg, "left") != 0 && strcasecmp(dirarg, "l") != 0) + n1 = 0; + } + + if (!arg || sscanf(arg + n1, "%u %n", &sd->show, &n2) <= 0) { free(sd); #ifdef BUILD_X11 free(obj->next); #endif free(free_at_crash2); - CRIT_ERR(obj, free_at_crash, "scroll needs arguments: [] "); + CRIT_ERR(obj, free_at_crash, "scroll needs arguments: [left|right] [] "); } + n1 += n2; - sscanf(arg + n1, "%u %n", &sd->step, &n2); - if (*(arg + n1 + n2)) { + if(sscanf(arg + n1, "%u %n", &sd->step, &n2) == 1) { n1 += n2; } else { sd->step = 1; @@ -135,7 +149,7 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size) } p[j] = 0; //count colorchanges in front of the visible part and place that many colorchanges in front of the visible part - for(j = 0; j < sd->start; j++) { + for(j = 0; j < (unsigned) sd->start; j++) { if(buf[j] == SPECIAL_CHAR) frontcolorchanges++; } pwithcolors=(char*)malloc(strlen(p) + 1 + colorchanges - visibcolorchanges); @@ -153,9 +167,16 @@ void print_scroll(struct text_object *obj, char *p, int p_max_size) strcpy(p, pwithcolors); free(pwithcolors); //scroll - sd->start += sd->step; - if(buf[sd->start] == 0 || sd->start > strlen(&(buf[0]))){ - sd->start = 0; + if(sd->direction == SCROLL_LEFT) { + sd->start += sd->step; + if(buf[sd->start] == 0 || (unsigned) sd->start > strlen(&(buf[0]))) { + sd->start = 0; + } + } else { + if(sd->start < 1) { + sd->start = strlen(&(buf[0])); + } + sd->start -= sd->step; } #ifdef BUILD_X11 //reset color when scroll is finished From d56a862467f2e7529486daa3d798a5f37bd03d31 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sun, 7 Feb 2010 10:46:00 -0500 Subject: [PATCH 18/21] Added AF_UNIX socket support. Signed-off-by: Brenden Matthews --- src/libmpdclient.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/libmpdclient.cc b/src/libmpdclient.cc index df7a16a3..92156a13 100644 --- a/src/libmpdclient.cc +++ b/src/libmpdclient.cc @@ -52,6 +52,7 @@ # include # include # include +# include # include #endif @@ -119,6 +120,38 @@ static int do_connect_fail(mpd_Connection *connection, } #endif /* !WIN32 */ +static int uds_connect(mpd_Connection *connection, const char *host, + float timeout) +{ + struct sockaddr_un addr; + + strncpy(addr.sun_path, host, sizeof(addr.sun_path)-1); + addr.sun_family = AF_UNIX; + addr.sun_path[sizeof(addr.sun_path)-1] = 0; + connection->sock = socket(AF_UNIX, SOCK_STREAM, 0); + + if (connection->sock < 0) { + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, + "problems creating socket: %s", strerror(errno)); + connection->error = MPD_ERROR_SYSTEM; + return -1; + } + + mpd_setConnectionTimeout(connection, timeout); + + /* connect stuff */ + if (do_connect_fail(connection, (struct sockaddr *)&addr, SUN_LEN(&addr))) { + snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, + "problems cconnecting socket: %s", strerror(errno)); + closesocket(connection->sock); + connection->sock = -1; + connection->error = MPD_ERROR_SYSTEM; + return -1; + } + + return 0; +} + #ifdef MPD_HAVE_GAI static int mpd_connect(mpd_Connection *connection, const char *host, int port, float timeout) @@ -129,6 +162,9 @@ static int mpd_connect(mpd_Connection *connection, const char *host, int port, struct addrinfo *res = NULL; struct addrinfo *addrinfo = NULL; + if (*host == '/') + return uds_connect(connection, host, timeout); + /* Setup hints */ hints.ai_flags = AI_ADDRCONFIG; hints.ai_family = AF_UNSPEC; @@ -200,6 +236,9 @@ static int mpd_connect(mpd_Connection *connection, const char *host, int port, int destlen; struct sockaddr_in sin; + if (*host == '/') + return uds_connect(connection, host, timeout); + #ifdef HAVE_GETHOSTBYNAME_R if (gethostbyname_r(rhost, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info snprintf(connection->errorStr, MPD_ERRORSTR_MAX_LENGTH, From 2585fabc52306b587c849822c40ad78e3bf197da Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 17 Feb 2010 19:43:16 +0100 Subject: [PATCH 19/21] Try to make $if_match better handle stranger inputs This should fix sf.net #2953283 --- src/algebra.cc | 21 ++++++++++++--------- src/algebra.h | 1 + 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/algebra.cc b/src/algebra.cc index 4ab5c790..7e306525 100644 --- a/src/algebra.cc +++ b/src/algebra.cc @@ -126,11 +126,9 @@ enum arg_type get_arg_type(const char *arg) const char *p, *e; p = arg; - e = arg + strlen(arg); + e = arg + strlen(arg)-1; - if (*(e - 1) == ' ') - e--; - while (*e && *e == ' ') + while (p != e && *e && *e == ' ') e--; while (p != e && *p == ' ') p++; @@ -140,23 +138,23 @@ enum arg_type get_arg_type(const char *arg) if (*p == '-') //allow negative values p++; - while (p != e) { + while (p <= e) { if (!isdigit(*p)) break; p++; } - if (p == e) + if (p == e+1) return ARG_LONG; if (*p == '.') { p++; - while (p != e) { + while (p <= e) { if (!isdigit(*p)) - return ARG_STRING; + return ARG_BAD; p++; } return ARG_DOUBLE; } - return ARG_STRING; + return ARG_BAD; } char *arg_to_string(const char *arg) @@ -213,6 +211,10 @@ int compare(const char *expr) type1 = get_arg_type(expr_dup); type2 = get_arg_type(expr_dup + idx + 1); + if (type1 == ARG_BAD || type2 == ARG_BAD) { + NORM_ERR("Bad arguments: '%s' and '%s'", expr_dup, (expr_dup + idx + 1)); + return -2; + } if (type1 == ARG_LONG && type2 == ARG_DOUBLE) type1 = ARG_DOUBLE; if (type1 == ARG_DOUBLE && type2 == ARG_LONG) @@ -239,6 +241,7 @@ int compare(const char *expr) case ARG_DOUBLE: return dcompare(arg_to_double(expr_dup), (enum match_type) mtype, arg_to_double(expr_dup + idx + 1)); + case ARG_BAD: /* make_gcc_happy() */; } /* not reached */ return -2; diff --git a/src/algebra.h b/src/algebra.h index e1830cf0..5f4cf248 100644 --- a/src/algebra.h +++ b/src/algebra.h @@ -44,6 +44,7 @@ enum match_type { }; enum arg_type { + ARG_BAD = 0, /* something strange */ ARG_STRING = 1, /* "asdf" */ ARG_LONG = 2, /* 123456 */ ARG_DOUBLE = 3 /* 12.456 */ From d6ea46f8cb3135bb5fd068c056c7859701da6aa7 Mon Sep 17 00:00:00 2001 From: Pavel Labath Date: Wed, 17 Feb 2010 19:55:39 +0100 Subject: [PATCH 20/21] Update docs to be consistent with changes in previous commit --- doc/variables.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/variables.xml b/doc/variables.xml index 88766447..ccc692dc 100644 --- a/doc/variables.xml +++ b/doc/variables.xml @@ -1600,8 +1600,7 @@ digits. stringArgument is enclosed in - quotation mark or the checks for double and long failed - before. + quotation marks (") Valid operands are: '>', '<', '>=', '<=', '==', '!='. From a1a73c23cb09bf1083b0b4f905413d66aeb0d2c3 Mon Sep 17 00:00:00 2001 From: Nikolas Garofil Date: Wed, 17 Feb 2010 20:26:50 +0100 Subject: [PATCH 21/21] Fix memleak in if_match --- src/algebra.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/algebra.cc b/src/algebra.cc index 7e306525..a4ae3656 100644 --- a/src/algebra.cc +++ b/src/algebra.cc @@ -195,6 +195,8 @@ int compare(const char *expr) char *expr_dup; int idx, mtype; enum arg_type type1, type2; + long lng_a, lng_b; + double dbl_a, dbl_b; idx = find_match_op(expr); mtype = get_match_type(expr); @@ -213,6 +215,7 @@ int compare(const char *expr) type2 = get_arg_type(expr_dup + idx + 1); if (type1 == ARG_BAD || type2 == ARG_BAD) { NORM_ERR("Bad arguments: '%s' and '%s'", expr_dup, (expr_dup + idx + 1)); + free(expr_dup); return -2; } if (type1 == ARG_LONG && type2 == ARG_DOUBLE) @@ -222,6 +225,7 @@ int compare(const char *expr) if (type1 != type2) { NORM_ERR("trying to compare args '%s' and '%s' of different type", expr_dup, (expr_dup + idx + 1)); + free(expr_dup); return -2; } switch (type1) { @@ -233,17 +237,23 @@ int compare(const char *expr) idx = scompare(a, (enum match_type) mtype, b); free(a); free(b); + free(expr_dup); return idx; } case ARG_LONG: - return lcompare(arg_to_long(expr_dup), (enum match_type) mtype, - arg_to_long(expr_dup + idx + 1)); + lng_a = arg_to_long(expr_dup); + lng_b = arg_to_long(expr_dup + idx + 1); + free(expr_dup); + return lcompare(lng_a, (enum match_type) mtype, lng_b); case ARG_DOUBLE: - return dcompare(arg_to_double(expr_dup), (enum match_type) mtype, - arg_to_double(expr_dup + idx + 1)); + dbl_a = arg_to_double(expr_dup); + dbl_b = arg_to_double(expr_dup + idx + 1); + free(expr_dup); + return dcompare(dbl_a, (enum match_type) mtype, dbl_b); case ARG_BAD: /* make_gcc_happy() */; } /* not reached */ + free(expr_dup); return -2; }