diff --git a/ChangeLog b/ChangeLog index 6375f559..da36cdda 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +2009-06-20 + * Use the internal process list for if_running on Linux + 2009-06-14 * Fix XMMS2 related crash (sf.net #2806111 and #2805310, thanks Lassi) diff --git a/src/conky.c b/src/conky.c index af8db824..614a039c 100644 --- a/src/conky.c +++ b/src/conky.c @@ -2100,12 +2100,18 @@ static struct text_object *construct_text_object(const char *s, } else { obj->data.ifblock.s = strndup(arg, text_buffer_size); } +#ifdef __linux__ + END OBJ_IF(if_running, INFO_TOP) + if (arg) { + obj->data.ifblock.s = strndup(arg, text_buffer_size); +#else END OBJ_IF(if_running, 0) if (arg) { char buf[256]; snprintf(buf, 256, "pidof %s >/dev/null", arg); obj->data.ifblock.s = strndup(buf, text_buffer_size); +#endif } else { ERR("if_running needs an argument"); obj->data.ifblock.s = 0; @@ -4796,7 +4802,11 @@ static void generate_text_internal(char *p, int p_max_size, } } OBJ(if_running) { +#ifdef __linux__ + if (!get_process_by_name(obj->data.ifblock.s)) { +#else if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) { +#endif DO_JUMP; } } diff --git a/src/top.c b/src/top.c index 6d92fafc..640658fe 100644 --- a/src/top.c +++ b/src/top.c @@ -52,6 +52,18 @@ void free_all_processes(void) first_process = NULL; } +struct process *get_process_by_name(const char *name) +{ + struct process *p = first_process; + + while (p) { + if (!strcmp(p->name, name)) + return p; + p = p->next; + } + return 0; +} + static struct process *find_process(pid_t pid) { struct process *p = first_process; diff --git a/src/top.h b/src/top.h index 7d616170..c17faaab 100644 --- a/src/top.h +++ b/src/top.h @@ -136,4 +136,7 @@ void process_find_top(struct process **, struct process **, struct process ** #endif ); +/* lookup a program by it's name */ +struct process *get_process_by_name(const char *); + #endif /* _top_h_ */