Fix for segfault in top_name stuff.
[monky] / src / core.c
index ac1a7f3..e0e7218 100644 (file)
@@ -277,12 +277,13 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->data.s = strndup(bat, text_buffer_size);
        END OBJ(battery_bar, 0)
                char bat[64];
-               if (arg) {
+
+               arg = scan_bar(obj, arg);
+               if (arg && strlen(arg)>0) {
                        sscanf(arg, "%63s", bat);
                } else {
                        strcpy(bat, "BAT0");
                }
-               scan_bar(obj, bat);
                obj->data.s = strndup(bat, text_buffer_size);
 #endif /* !__OpenBSD__ */
 
@@ -540,6 +541,11 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                parse_platform_sensor(obj, arg);
        END OBJ_ARG(hwmon, 0, "hwmon needs argumanets")
                parse_hwmon_sensor(obj, arg);
+       END OBJ(addr, &update_net_stats)
+               parse_net_stat_arg(obj, arg, free_at_crash);
+       END OBJ(addrs, &update_net_stats)
+               parse_net_stat_arg(obj, arg, free_at_crash);
+#endif /* __linux__ */
        END
        /* we have four different types of top (top, top_mem, top_time and top_io). To
         * avoid having almost-same code four times, we have this special
@@ -550,12 +556,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                if (!parse_top_args(s, arg, obj)) {
                        return NULL;
                }
-       } else OBJ(addr, &update_net_stats)
-               parse_net_stat_arg(obj, arg, free_at_crash);
-       END OBJ(addrs, &update_net_stats)
-               parse_net_stat_arg(obj, arg, free_at_crash);
-#endif /* __linux__ */
-       END OBJ_ARG(tail, 0, "tail needs arguments")
+       } else
+               OBJ_ARG(tail, 0, "tail needs arguments")
                init_tailhead("tail", arg, obj, free_at_crash);
        END OBJ_ARG(head, 0, "head needs arguments")
                init_tailhead("head", arg, obj, free_at_crash);
@@ -655,6 +657,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->sub = malloc(sizeof(struct text_object));
                extract_variable_text_internal(obj->sub, arg);
        END OBJ(nodename, 0)
+       END OBJ(nodename_short, 0)
        END OBJ_ARG(cmdline_to_pid, 0, "cmdline_to_pid needs a command line as argument")
                scan_cmdline_to_pid_arg(obj, arg, free_at_crash);
        END OBJ_ARG(pid_chroot, 0, "pid_chroot needs a pid as argument")
@@ -784,9 +787,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long
                obj->sub = malloc(sizeof(struct text_object));
                extract_variable_text_internal(obj->sub, arg);
        END OBJ(processes, &update_total_processes)
-#ifdef __linux__
        END OBJ(running_processes, &update_top)
                top_running = 1;
+#ifdef __linux__
        END OBJ(threads, &update_threads)
        END OBJ(running_threads, &update_stat)
 #else