Use the internal process list for if_running on Linux
authorPhil Sutter <phil@nwl.cc>
Fri, 19 Jun 2009 23:40:40 +0000 (01:40 +0200)
committerPhil Sutter <phil@nwl.cc>
Fri, 19 Jun 2009 23:46:59 +0000 (01:46 +0200)
ChangeLog
src/conky.c
src/top.c
src/top.h

index 6375f55..da36cdd 100644 (file)
--- 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)
 
index af8db82..614a039 100644 (file)
@@ -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;
                                }
                        }
index 6d92faf..640658f 100644 (file)
--- 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;
index 7d61617..c17faaa 100644 (file)
--- 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_ */