X-Git-Url: https://vcs.maemo.org/git/?a=blobdiff_plain;f=src%2Fcore.c;h=90ed09bc1c4e6b67a3ca688ff7ee886caa4f3756;hb=8564ff6610cf5ed060e6dd206ad9878e96d98130;hp=ffc24b3c717fd0ee54a8f4f8d7392184ffcb3ce1;hpb=dd36fc4caa0cca014a369217638a1e2a9c47287a;p=monky diff --git a/src/core.c b/src/core.c index ffc24b3..90ed09b 100644 --- a/src/core.c +++ b/src/core.c @@ -10,7 +10,7 @@ * Please see COPYING for details * * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen - * Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al. + * Copyright (c) 2005-2010 Brenden Matthews, Philip Kovacs, et. al. * (see AUTHORS) * All rights reserved. * @@ -36,7 +36,10 @@ #include "colours.h" #include "combine.h" #include "diskio.h" +#include "entropy.h" #include "exec.h" +#include "i8k.h" +#include "proc.h" #ifdef X11 #include "fonts.h" #endif @@ -74,9 +77,6 @@ #include "openbsd.h" #endif -/* OS specific prototypes to be implemented by linux.c & Co. */ -void update_entropy(void); - #include #include @@ -153,60 +153,68 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->data.l = get_x11_color(s); } else #endif /* X11 */ -#ifdef __OpenBSD__ - OBJ(freq, 0) -#else +#ifndef __OpenBSD__ OBJ(acpitemp, 0) obj->data.i = open_acpi_temperature(arg); END OBJ(acpiacadapter, 0) - END OBJ(freq, 0) + if(arg) { +#ifdef __linux__ + if(strpbrk(arg, "/.") != NULL) { + /* + * a bit of paranoia. screen out funky paths + * i hope no device will have a '.' in its name + */ + NORM_ERR("acpiacadapter: arg must not contain '/' or '.'"); + } else + obj->data.opaque = strdup(arg); +#else + NORM_ERR("acpiacadapter: arg is only used on linux"); +#endif + } #endif /* !__OpenBSD__ */ + END OBJ(freq, 0) get_cpu_count(); if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("freq: Invalid CPU number or you don't have that many CPUs! " "Displaying the clock for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; END OBJ(freq_g, 0) get_cpu_count(); if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("freq_g: Invalid CPU number or you don't have that many " "CPUs! Displaying the clock for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; END OBJ_ARG(read_tcp, 0, "read_tcp: Needs \"(host) port\" as argument(s)") parse_read_tcp_arg(obj, arg, free_at_crash); #if defined(__linux__) END OBJ(voltage_mv, 0) get_cpu_count(); if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("voltage_mv: Invalid CPU number or you don't have that many " "CPUs! Displaying voltage for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; END OBJ(voltage_v, 0) get_cpu_count(); if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0 - || (unsigned int) atoi(&arg[0]) > info.cpu_count) { - obj->data.cpu_index = 1; + || atoi(&arg[0]) > info.cpu_count) { + obj->data.i = 1; /* NORM_ERR("voltage_v: Invalid CPU number or you don't have that many " "CPUs! Displaying voltage for CPU 1."); */ } else { - obj->data.cpu_index = atoi(&arg[0]); + obj->data.i = atoi(&arg[0]); } - obj->a = 1; #ifdef HAVE_IWLIB END OBJ(wireless_essid, &update_net_stats) @@ -269,10 +277,9 @@ 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]; - SIZE_DEFAULTS(bar); - obj->b = 6; - if (arg) { - arg = scan_bar(arg, &obj->a, &obj->b); + + arg = scan_bar(obj, arg); + if (arg && strlen(arg)>0) { sscanf(arg, "%63s", bat); } else { strcpy(bat, "BAT0"); @@ -295,7 +302,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(i8k_buttons_status, &update_i8k) #if defined(IBM) END OBJ(ibm_fan, 0) - END OBJ(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument") + END OBJ_ARG(ibm_temps, &get_ibm_acpi_temps, "ibm_temps: needs an argument") parse_ibm_temps_arg(obj, arg); END OBJ(ibm_volume, 0) END OBJ(ibm_brightness, 0) @@ -321,30 +328,15 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* __linux__ */ #if (defined(__FreeBSD__) || defined(__linux__)) END OBJ_IF_ARG(if_up, 0, "if_up needs an argument") - obj->data.ifblock.s = strndup(arg, text_buffer_size); + parse_if_up_arg(obj, arg); #endif #if defined(__OpenBSD__) END OBJ_ARG(obsd_sensors_temp, 0, "obsd_sensors_temp: needs an argument") - if (!isdigit(arg[0]) || atoi(&arg[0]) < 0 - || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) { - obj->data.sensor = 0; - NORM_ERR("Invalid temperature sensor number!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); END OBJ_ARG(obsd_sensors_fan, 0, "obsd_sensors_fan: needs 2 arguments (device and sensor number)") - if (!isdigit(arg[0]) || atoi(&arg[0]) < 0 - || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) { - obj->data.sensor = 0; - NORM_ERR("Invalid fan sensor number!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); END OBJ_ARG(obsd_sensors_volt, 0, "obsd_sensors_volt: needs 2 arguments (device and sensor number)") - if (!isdigit(arg[0]) || atoi(&arg[0]) < 0 - || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) { - obj->data.sensor = 0; - NORM_ERR("Invalid voltage sensor number!"); - } else - obj->data.sensor = atoi(&arg[0]); + parse_obsd_sensor(obj, arg); END OBJ(obsd_vendor, 0) END OBJ(obsd_product, 0) #endif /* __OpenBSD__ */ @@ -352,80 +344,45 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(cached, &update_meminfo) #define SCAN_CPU(__arg, __var) { \ int __offset = 0; \ - if (__arg && sscanf(__arg, " cpu%u %n", &__var, &__offset) > 0) \ + if (__arg && sscanf(__arg, " cpu%d %n", &__var, &__offset) > 0) \ __arg += __offset; \ else \ __var = 0; \ } END OBJ(cpu, &update_cpu_usage) - SCAN_CPU(arg, obj->data.cpu_index); - DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index); -#ifdef X11 + SCAN_CPU(arg, obj->data.i); + DBGP2("Adding $cpu for CPU %d", obj->data.i); END OBJ(cpugauge, &update_cpu_usage) - SIZE_DEFAULTS(gauge); - SCAN_CPU(arg, obj->data.cpu_index); - scan_gauge(arg, &obj->a, &obj->b); - DBGP2("Adding $cpugauge for CPU %d", obj->data.cpu_index); -#endif /* X11 */ + SCAN_CPU(arg, obj->data.i); + scan_gauge(obj, arg); + DBGP2("Adding $cpugauge for CPU %d", obj->data.i); END OBJ(cpubar, &update_cpu_usage) - SIZE_DEFAULTS(bar); - SCAN_CPU(arg, obj->data.cpu_index); - scan_bar(arg, &obj->a, &obj->b); - DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index); + SCAN_CPU(arg, obj->data.i); + scan_bar(obj, arg); + DBGP2("Adding $cpubar for CPU %d", obj->data.i); #ifdef X11 END OBJ(cpugraph, &update_cpu_usage) char *buf = 0; - SIZE_DEFAULTS(graph); - SCAN_CPU(arg, obj->data.cpu_index); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); - DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index); + SCAN_CPU(arg, obj->data.i); + buf = scan_graph(obj, arg, 100); + DBGP2("Adding $cpugraph for CPU %d", obj->data.i); if (buf) free(buf); END OBJ(loadgraph, &update_load_average) - char *buf = 0; - SIZE_DEFAULTS(graph); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); - if (buf) { - int a = 1, r = 3; - if (arg) { - r = sscanf(arg, "%d", &a); - } - obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0; - free(buf); - } + scan_loadgraph_arg(obj, arg); #endif /* X11 */ END OBJ(diskio, &update_diskio) - obj->data.diskio = prepare_diskio_stat(dev_name(arg)); + parse_diskio_arg(obj, dev_name(arg)); END OBJ(diskio_read, &update_diskio) - obj->data.diskio = prepare_diskio_stat(dev_name(arg)); + parse_diskio_arg(obj, dev_name(arg)); END OBJ(diskio_write, &update_diskio) - obj->data.diskio = prepare_diskio_stat(dev_name(arg)); + parse_diskio_arg(obj, dev_name(arg)); #ifdef X11 END OBJ(diskiograph, &update_diskio) - char *buf = 0; - SIZE_DEFAULTS(graph); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); - - obj->data.diskio = prepare_diskio_stat(dev_name(buf)); - if (buf) free(buf); + parse_diskiograph_arg(obj, dev_name(arg)); END OBJ(diskiograph_read, &update_diskio) - char *buf = 0; - SIZE_DEFAULTS(graph); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); - - obj->data.diskio = prepare_diskio_stat(dev_name(buf)); - if (buf) free(buf); + parse_diskiograph_arg(obj, dev_name(arg)); END OBJ(diskiograph_write, &update_diskio) - char *buf = 0; - SIZE_DEFAULTS(graph); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); - - obj->data.diskio = prepare_diskio_stat(dev_name(buf)); - if (buf) free(buf); + parse_diskiograph_arg(obj, dev_name(arg)); #endif /* X11 */ END OBJ(color, 0) #ifdef X11 @@ -493,8 +450,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->data.s = scan_font(arg); #endif /* X11 */ END OBJ(conky_version, 0) + obj->type = OBJ_text; + obj->data.s = strdup(VERSION); END OBJ(conky_build_date, 0) + obj->type = OBJ_text; + obj->data.s = strdup(BUILD_DATE); END OBJ(conky_build_arch, 0) + obj->type = OBJ_text; + obj->data.s = strdup(BUILD_ARCH); END OBJ(downspeed, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash); END OBJ(downspeedf, &update_net_stats) @@ -518,27 +481,21 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(execp, 0) scan_exec_arg(obj, arg); END OBJ(execbar, 0) - SIZE_DEFAULTS(bar); scan_exec_arg(obj, arg); -#ifdef X11 END OBJ(execgauge, 0) - SIZE_DEFAULTS(gauge); scan_exec_arg(obj, arg); +#ifdef X11 END OBJ(execgraph, 0) - SIZE_DEFAULTS(graph); - scan_exec_arg(obj, arg); + scan_execgraph_arg(obj, arg); #endif /* X11 */ END OBJ_ARG(execibar, 0, "execibar needs arguments") - SIZE_DEFAULTS(bar); scan_execi_arg(obj, arg); #ifdef X11 END OBJ_ARG(execigraph, 0, "execigraph needs arguments") - SIZE_DEFAULTS(graph); - scan_execi_arg(obj, arg); + scan_execgraph_arg(obj, arg); +#endif /* X11 */ END OBJ_ARG(execigauge, 0, "execigauge needs arguments") - SIZE_DEFAULTS(gauge); scan_execi_arg(obj, arg); -#endif /* X11 */ END OBJ_ARG(execi, 0, "execi needs arguments") scan_execi_arg(obj, arg); END OBJ_ARG(execpi, 0, "execpi needs arguments") @@ -573,20 +530,10 @@ struct text_object *construct_text_object(const char *s, const char *arg, long obj->data.i = arg ? atoi(arg) : 1; END OBJ_ARG(goto, 0, "goto needs arguments") obj->data.i = atoi(arg); +#ifdef X11 END OBJ(tab, 0) - int a = 10, b = 0; - - if (arg) { - if (sscanf(arg, "%d %d", &a, &b) != 2) { - sscanf(arg, "%d", &b); - } - } - if (a <= 0) { - a = 1; - } - obj->data.pair.a = a; - obj->data.pair.b = b; - + scan_tab(obj, arg); +#endif /* X11 */ #ifdef __linux__ END OBJ_ARG(i2c, 0, "i2c needs arguments") parse_i2c_sensor(obj, arg); @@ -594,8 +541,6 @@ 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); -#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 @@ -608,7 +553,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long } } else OBJ(addr, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash); -#if defined(__linux__) END OBJ(addrs, &update_net_stats) parse_net_stat_arg(obj, arg, free_at_crash); #endif /* __linux__ */ @@ -621,55 +565,27 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ_ARG(words, 0, "words needs a argument") obj->data.s = strndup(arg, text_buffer_size); END OBJ(loadavg, &update_load_average) - int a = 1, b = 2, c = 3, r = 3; - - if (arg) { - r = sscanf(arg, "%d %d %d", &a, &b, &c); - if (r >= 3 && (c < 1 || c > 3)) { - r--; - } - if (r >= 2 && (b < 1 || b > 3)) { - r--, b = c; - } - if (r >= 1 && (a < 1 || a > 3)) { - r--, a = b, b = c; - } - } - obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0; - obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0; - obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0; + scan_loadavg_arg(obj, arg); END OBJ_IF_ARG(if_empty, 0, "if_empty needs an argument") - obj->data.ifblock.s = strndup(arg, text_buffer_size); obj->sub = malloc(sizeof(struct text_object)); - extract_variable_text_internal(obj->sub, obj->data.ifblock.s); + extract_variable_text_internal(obj->sub, arg); END OBJ_IF_ARG(if_match, 0, "if_match needs arguments") - obj->data.ifblock.s = strndup(arg, text_buffer_size); obj->sub = malloc(sizeof(struct text_object)); - extract_variable_text_internal(obj->sub, obj->data.ifblock.s); + extract_variable_text_internal(obj->sub, arg); END OBJ_IF_ARG(if_existing, 0, "if_existing needs an argument or two") - char buf1[256], buf2[256]; - int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2); - - if (r == 1) { - obj->data.ifblock.s = strndup(buf1, text_buffer_size); - obj->data.ifblock.str = NULL; - } else { - obj->data.ifblock.s = strndup(buf1, text_buffer_size); - obj->data.ifblock.str = strndup(buf2, text_buffer_size); - } - DBGP("if_existing: '%s' '%s'", obj->data.ifblock.s, obj->data.ifblock.str); + obj->data.s = strndup(arg, text_buffer_size); END OBJ_IF_ARG(if_mounted, 0, "if_mounted needs an argument") - obj->data.ifblock.s = strndup(arg, text_buffer_size); + obj->data.s = strndup(arg, text_buffer_size); #ifdef __linux__ END OBJ_IF_ARG(if_running, &update_top, "if_running needs an argument") top_running = 1; - obj->data.ifblock.s = strndup(arg, text_buffer_size); + obj->data.s = strndup(arg, text_buffer_size); #else END OBJ_IF_ARG(if_running, 0, "if_running needs an argument") - char buf[256]; + char buf[text_buffer_size]; - snprintf(buf, 256, "pidof %s >/dev/null", arg); - obj->data.ifblock.s = strndup(buf, text_buffer_size); + snprintf(buf, text_buffer_size, "pidof %s >/dev/null", arg); + obj->data.s = strndup(buf, text_buffer_size); #endif END OBJ(kernel, 0) END OBJ(machine, 0) @@ -698,30 +614,20 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(trashed_mails, 0) parse_local_mail_args(obj, arg); END OBJ(mboxscan, 0) - obj->data.mboxscan.args = (char *) malloc(text_buffer_size); - obj->data.mboxscan.output = (char *) malloc(text_buffer_size); - /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */ - obj->data.mboxscan.output[0] = 1; - strncpy(obj->data.mboxscan.args, arg, text_buffer_size); + parse_mboxscan_arg(obj, arg); END OBJ(mem, &update_meminfo) END OBJ(memeasyfree, &update_meminfo) END OBJ(memfree, &update_meminfo) END OBJ(memmax, &update_meminfo) END OBJ(memperc, &update_meminfo) -#ifdef X11 END OBJ(memgauge, &update_meminfo) - SIZE_DEFAULTS(gauge); - scan_gauge(arg, &obj->data.pair.a, &obj->data.pair.b); -#endif /* X11*/ + scan_gauge(obj, arg); END OBJ(membar, &update_meminfo) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); + scan_bar(obj, arg); #ifdef X11 END OBJ(memgraph, &update_meminfo) char *buf = 0; - SIZE_DEFAULTS(graph); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); + buf = scan_graph(obj, arg, 100); if (buf) free(buf); #endif /* X11*/ @@ -731,14 +637,12 @@ struct text_object *construct_text_object(const char *s, const char *arg, long parse_mixer_arg(obj, arg); END OBJ(mixerr, 0) parse_mixer_arg(obj, arg); -#ifdef X11 END OBJ(mixerbar, 0) scan_mixer_bar(obj, arg); END OBJ(mixerlbar, 0) scan_mixer_bar(obj, arg); END OBJ(mixerrbar, 0) scan_mixer_bar(obj, arg); -#endif END OBJ_IF(if_mixer_mute, 0) parse_mixer_arg(obj, arg); #ifdef X11 @@ -748,9 +652,148 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(desktop_number, &update_x11info) END OBJ(desktop_name, &update_x11info) #endif + END OBJ_ARG(format_time, 0, "format_time needs a pid as argument") + 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") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_cmdline, 0, "pid_cmdline needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_cwd, 0, "pid_cwd needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_environ, 0, "pid_environ needs arguments") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_environ_list, 0, "pid_environ_list needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_exe, 0, "pid_exe needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_nice, 0, "pid_nice needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_openfiles, 0, "pid_openfiles needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_parent, 0, "pid_parent needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_priority, 0, "pid_priority needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_state, 0, "pid_state needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_state_short, 0, "pid_state_short needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_stderr, 0, "pid_stderr needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_stdin, 0, "pid_stdin needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_stdout, 0, "pid_stdout needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_threads, 0, "pid_threads needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_thread_list, 0, "pid_thread_list needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_time_kernelmode, 0, "pid_time_kernelmode needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_time_usermode, 0, "pid_time_usermode needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_time, 0, "pid_time needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_uid, 0, "pid_uid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_euid, 0, "pid_euid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_suid, 0, "pid_suid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_fsuid, 0, "pid_fsuid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_gid, 0, "pid_gid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_egid, 0, "pid_egid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_sgid, 0, "pid_sgid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_fsgid, 0, "pid_fsgid needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(gid_name, 0, "gid_name needs a gid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(uid_name, 0, "uid_name needs a uid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_read, 0, "pid_read needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmpeak, 0, "pid_vmpeak needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmsize, 0, "pid_vmsize needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmlck, 0, "pid_vmlck needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmhwm, 0, "pid_vmhwm needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmrss, 0, "pid_vmrss needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmdata, 0, "pid_vmdata needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmstk, 0, "pid_vmstk needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmexe, 0, "pid_vmexe needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmlib, 0, "pid_vmlib needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_vmpte, 0, "pid_vmpte needs a pid as argument") + obj->sub = malloc(sizeof(struct text_object)); + extract_variable_text_internal(obj->sub, arg); + END OBJ_ARG(pid_write, 0, "pid_write needs a pid as argument") + 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; + END OBJ(threads, &update_threads) + END OBJ(running_threads, &update_stat) +#else END OBJ(running_processes, &update_running_processes) +#endif /* __linux__ */ END OBJ(shadecolor, 0) #ifdef X11 obj->data.l = arg ? get_x11_color(arg) : default_bg_color; @@ -761,26 +804,14 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif /* X11 */ END OBJ(stippled_hr, 0) #ifdef X11 - int a = get_stippled_borders(), b = 1; - - if (arg) { - if (sscanf(arg, "%d %d", &a, &b) != 2) { - sscanf(arg, "%d", &b); - } - } - if (a <= 0) { - a = 1; - } - obj->data.pair.a = a; - obj->data.pair.b = b; + scan_stippled_hr(obj, arg); #endif /* X11 */ END OBJ(swap, &update_meminfo) END OBJ(swapfree, &update_meminfo) END OBJ(swapmax, &update_meminfo) END OBJ(swapperc, &update_meminfo) END OBJ(swapbar, &update_meminfo) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); + scan_bar(obj, arg); END OBJ(sysname, 0) END OBJ(time, 0) scan_time(obj, arg); @@ -800,9 +831,9 @@ struct text_object *construct_text_object(const char *s, const char *arg, long parse_net_stat_arg(obj, arg, free_at_crash); END OBJ(updates, 0) END OBJ_IF(if_updatenr, 0) - obj->data.ifblock.i = arg ? atoi(arg) : 0; - if(obj->data.ifblock.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument"); - set_updatereset(obj->data.ifblock.i > get_updatereset() ? obj->data.ifblock.i : get_updatereset()); + obj->data.i = arg ? atoi(arg) : 0; + if(obj->data.i == 0) CRIT_ERR(obj, free_at_crash, "if_updatenr needs a number above 0 as argument"); + set_updatereset(obj->data.i > get_updatereset() ? obj->data.i : get_updatereset()); END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0; END OBJ(alignc, 0) @@ -817,18 +848,16 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #endif END OBJ(uptime_short, &update_uptime) END OBJ(uptime, &update_uptime) +#if defined(__linux__) END OBJ(user_names, &update_users) END OBJ(user_times, &update_users) + END OBJ_ARG(user_time, 0, "user time needs a console name as argument") + obj->data.s = strndup(arg, text_buffer_size); END OBJ(user_terms, &update_users) END OBJ(user_number, &update_users) -#if defined(__linux__) END OBJ(gw_iface, &update_gateway_info) END OBJ(gw_ip, &update_gateway_info) #endif /* !__linux__ */ -#ifndef __OpenBSD__ - END OBJ(adt746xcpu, 0) - END OBJ(adt746xfan, 0) -#endif /* !__OpenBSD__ */ #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \ || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__)) END OBJ(apm_adapter, 0) @@ -847,25 +876,20 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ_ARG(smapi, 0, "smapi needs an argument") obj->data.s = strndup(arg, text_buffer_size); END OBJ_IF_ARG(if_smapi_bat_installed, 0, "if_smapi_bat_installed needs an argument") - obj->data.ifblock.s = strndup(arg, text_buffer_size); + obj->data.s = strndup(arg, text_buffer_size); END OBJ_ARG(smapi_bat_perc, 0, "smapi_bat_perc needs an argument") obj->data.s = strndup(arg, text_buffer_size); END OBJ_ARG(smapi_bat_temp, 0, "smapi_bat_temp needs an argument") obj->data.s = strndup(arg, text_buffer_size); END OBJ_ARG(smapi_bat_power, 0, "smapi_bat_power needs an argument") obj->data.s = strndup(arg, text_buffer_size); -#ifdef X11 END OBJ_ARG(smapi_bat_bar, 0, "smapi_bat_bar needs an argument") int cnt; - SIZE_DEFAULTS(bar); if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) { NORM_ERR("first argument to smapi_bat_bar must be an integer value"); obj->data.i = -1; - } else { - obj->b = 4; - arg = scan_bar(arg + cnt, &obj->a, &obj->b); - } -#endif /* X11 */ + } else + arg = scan_bar(obj, arg + cnt); #endif /* IBM */ #ifdef MPD #define mpd_set_maxlen(name) \ @@ -904,8 +928,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(mpd_bitrate, &update_mpd) init_mpd(); END OBJ(mpd_status, &update_mpd) init_mpd(); END OBJ(mpd_bar, &update_mpd) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); + scan_bar(obj, arg); init_mpd(); END OBJ(mpd_smart, &update_mpd) mpd_set_maxlen(mpd_smart); @@ -943,11 +966,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(xmms2_size, &update_xmms2) END OBJ(xmms2_status, &update_xmms2) END OBJ(xmms2_percent, &update_xmms2) -#ifdef X11 END OBJ(xmms2_bar, &update_xmms2) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b); -#endif /* X11 */ + scan_bar(obj, arg); END OBJ(xmms2_smart, &update_xmms2) END OBJ(xmms2_playlist, &update_xmms2) END OBJ(xmms2_timesplayed, &update_xmms2) @@ -973,11 +993,8 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(audacious_playlist_length, &update_audacious) END OBJ(audacious_playlist_position, &update_audacious) END OBJ(audacious_main_volume, &update_audacious) -#ifdef X11 END OBJ(audacious_bar, &update_audacious) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->a, &obj->b); -#endif /* X11 */ + scan_bar(obj, arg); #endif #ifdef BMPX END OBJ(bmpx_title, &update_bmpx) @@ -1019,8 +1036,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ_ARG(lua_parse, 0, "lua_parse needs arguments: [function parameters]") obj->data.s = strndup(arg, text_buffer_size); END OBJ_ARG(lua_bar, 0, "lua_bar needs arguments: , [function parameters]") - SIZE_DEFAULTS(bar); - arg = scan_bar(arg, &obj->a, &obj->b); + arg = scan_bar(obj, arg); if(arg) { obj->data.s = strndup(arg, text_buffer_size); } else { @@ -1029,23 +1045,20 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #ifdef X11 END OBJ_ARG(lua_graph, 0, "lua_graph needs arguments: [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]") char *buf = 0; - SIZE_DEFAULTS(graph); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); + buf = scan_graph(obj, arg, 0); if (buf) { obj->data.s = buf; } else { CRIT_ERR(obj, free_at_crash, "lua_graph needs arguments: [height],[width] [gradient colour 1] [gradient colour 2] [scale] [-t] [-l]"); } +#endif /* X11 */ END OBJ_ARG(lua_gauge, 0, "lua_gauge needs arguments: , [function parameters]") - SIZE_DEFAULTS(gauge); - arg = scan_gauge(arg, &obj->a, &obj->b); + arg = scan_gauge(obj, arg); if (arg) { obj->data.s = strndup(arg, text_buffer_size); } else { CRIT_ERR(obj, free_at_crash, "lua_gauge needs arguments: , [function parameters]"); } -#endif /* X11 */ #endif /* HAVE_LUA */ #ifdef HDDTEMP END OBJ(hddtemp, &update_hddtemp) @@ -1060,8 +1073,7 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(entropy_perc, &update_entropy) END OBJ(entropy_poolsize, &update_entropy) END OBJ(entropy_bar, &update_entropy) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->a, &obj->b); + scan_bar(obj, arg); END OBJ_ARG(include, 0, "include needs a argument") struct conftree *leaf = conftree_add(currentconffile, arg); if(leaf) { @@ -1111,30 +1123,26 @@ struct text_object *construct_text_object(const char *s, const char *arg, long END OBJ(apcupsd_linev, &update_apcupsd) END OBJ(apcupsd_load, &update_apcupsd) END OBJ(apcupsd_loadbar, &update_apcupsd) - SIZE_DEFAULTS(bar); - scan_bar(arg, &obj->a, &obj->b); + scan_bar(obj, arg); #ifdef X11 END OBJ(apcupsd_loadgraph, &update_apcupsd) char* buf = 0; - SIZE_DEFAULTS(graph); - buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, - &obj->e, &obj->char_a, &obj->char_b); + buf = scan_graph(obj, arg, 0); if (buf) free(buf); - END OBJ(apcupsd_loadgauge, &update_apcupsd) - SIZE_DEFAULTS(gauge); - scan_gauge(arg, &obj->a, &obj->b); #endif /* X11 */ + END OBJ(apcupsd_loadgauge, &update_apcupsd) + scan_gauge(obj, arg); END OBJ(apcupsd_charge, &update_apcupsd) END OBJ(apcupsd_timeleft, &update_apcupsd) END OBJ(apcupsd_temp, &update_apcupsd) END OBJ(apcupsd_lastxfer, &update_apcupsd) #endif /* APCUPSD */ END { - char buf[256]; + char buf[text_buffer_size]; NORM_ERR("unknown variable %s", s); obj->type = OBJ_text; - snprintf(buf, 256, "${%s}", s); + snprintf(buf, text_buffer_size, "${%s}", s); obj->data.s = strndup(buf, text_buffer_size); } #undef OBJ @@ -1145,7 +1153,6 @@ struct text_object *construct_text_object(const char *s, const char *arg, long #undef __OBJ_IF #undef __OBJ_ARG #undef END -#undef SIZE_DEFAULTS return obj; } @@ -1205,9 +1212,9 @@ int extract_variable_text_internal(struct text_object *retval, const char *const s = orig_p = p; if (strcmp(p, const_p)) { - DBGP("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p); + DBGP2("replaced all templates in text: input is\n'%s'\noutput is\n'%s'", const_p, p); } else { - DBGP("no templates to replace"); + DBGP2("no templates to replace"); } memset(retval, 0, sizeof(struct text_object)); @@ -1229,7 +1236,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const s = p; if (*p != '$') { - char buf[256]; + char buf[text_buffer_size]; const char *var; /* variable is either $foo or ${foo} */ @@ -1259,7 +1266,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const } /* copy variable to buffer */ - len = (p - s > 255) ? 255 : (p - s); + len = ((unsigned int) (p - s) > text_buffer_size - 1) ? text_buffer_size - 1 : (unsigned int) (p - s); strncpy(buf, s, len); buf[len] = '\0'; @@ -1320,7 +1327,7 @@ int extract_variable_text_internal(struct text_object *retval, const char *const strfold(p, 1); } else if (*p == '#') { char c; - if (remove_comment(p, &c) && p > orig_p && c == '\n') { + if (remove_comment(p, &c) && p >= orig_p && c == '\n') { /* if remove_comment removed a newline, we need to 'back up' with p */ p--; } @@ -1360,6 +1367,9 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_acpitemp: close(data.i); break; + case OBJ_acpiacadapter: + free(data.opaque); + break; #endif /* !__OpenBSD__ */ #ifdef __linux__ case OBJ_i2c: @@ -1368,6 +1378,62 @@ void free_text_objects(struct text_object *root, int internal) free_sysfs_sensor(obj); break; #endif /* __linux__ */ + case OBJ_cmdline_to_pid: + free(data.s); + break; + case OBJ_format_time: + case OBJ_pid_environ: + case OBJ_pid_chroot: + case OBJ_pid_cmdline: + case OBJ_pid_cwd: + case OBJ_pid_environ_list: + case OBJ_pid_exe: + case OBJ_pid_nice: + case OBJ_pid_openfiles: + case OBJ_pid_parent: + case OBJ_pid_priority: + case OBJ_pid_state: + case OBJ_pid_state_short: + case OBJ_pid_stderr: + case OBJ_pid_stdin: + case OBJ_pid_stdout: + case OBJ_pid_threads: + case OBJ_pid_thread_list: + case OBJ_pid_time_kernelmode: + case OBJ_pid_time_usermode: + case OBJ_pid_time: + case OBJ_pid_uid: + case OBJ_pid_euid: + case OBJ_pid_suid: + case OBJ_pid_fsuid: + case OBJ_pid_gid: + case OBJ_pid_egid: + case OBJ_pid_sgid: + case OBJ_pid_fsgid: + case OBJ_pid_read: + case OBJ_pid_vmpeak: + case OBJ_pid_vmsize: + case OBJ_pid_vmlck: + case OBJ_pid_vmhwm: + case OBJ_pid_vmrss: + case OBJ_pid_vmdata: + case OBJ_pid_vmstk: + case OBJ_pid_vmexe: + case OBJ_pid_vmlib: + case OBJ_pid_vmpte: + case OBJ_pid_write: + case OBJ_gid_name: + if(obj->sub) { + free_text_objects(obj->sub, 1); + free(obj->sub); + } + break; + case OBJ_uid_name: + if(obj->sub) { + free_text_objects(obj->sub, 1); + free(obj->sub); + } + break; case OBJ_read_tcp: free_read_tcp(obj); break; @@ -1379,8 +1445,7 @@ void free_text_objects(struct text_object *root, int internal) free_tztime(obj); break; case OBJ_mboxscan: - free(data.mboxscan.args); - free(data.mboxscan.output); + free_mboxscan(obj); break; case OBJ_mails: case OBJ_new_mails: @@ -1394,7 +1459,7 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_unreplied_mails: case OBJ_draft_mails: case OBJ_trashed_mails: - free(data.local_mail.mbox); + free_local_mails(obj); break; case OBJ_imap_unseen: case OBJ_imap_messages: @@ -1406,12 +1471,11 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_if_match: free_text_objects(obj->sub, 1); free(obj->sub); - /* fall through */ + break; case OBJ_if_existing: case OBJ_if_mounted: case OBJ_if_running: - free(data.ifblock.s); - free(data.ifblock.str); + free(data.s); break; case OBJ_head: case OBJ_tail: @@ -1421,10 +1485,12 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_font: case OBJ_image: case OBJ_eval: + free(data.s); + break; case OBJ_exec: case OBJ_execbar: -#ifdef X11 case OBJ_execgauge: +#ifdef X11 case OBJ_execgraph: #endif case OBJ_execp: @@ -1440,8 +1506,6 @@ void free_text_objects(struct text_object *root, int internal) free(data.s); break; case OBJ_if_gw: - free(data.ifblock.s); - free(data.ifblock.str); case OBJ_gw_iface: case OBJ_gw_ip: free_gateway_info(); @@ -1453,8 +1517,7 @@ void free_text_objects(struct text_object *root, int internal) #endif #if (defined(__FreeBSD__) || defined(__linux__)) case OBJ_if_up: - free(data.ifblock.s); - free(data.ifblock.str); + free_if_up(obj); break; #endif #ifdef XMMS2 @@ -1567,8 +1630,8 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_lua_bar: #ifdef X11 case OBJ_lua_graph: - case OBJ_lua_gauge: #endif /* X11 */ + case OBJ_lua_gauge: free(data.s); break; #endif /* HAVE_LUA */ @@ -1591,25 +1654,23 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_texeci: #ifdef X11 case OBJ_execigraph: - case OBJ_execigauge: #endif /* X11 */ + case OBJ_execigauge: free_execi(obj); break; case OBJ_nameserver: free_dns_data(); break; +#ifdef __linux__ case OBJ_top: case OBJ_top_mem: case OBJ_top_time: #ifdef IOSTATS case OBJ_top_io: #endif - if (info.first_process && !internal) { - free_all_processes(); - info.first_process = NULL; - } - if (data.top.s) free(data.top.s); + free_top(obj, internal); break; +#endif /* __linux__ */ #ifdef HDDTEMP case OBJ_hddtemp: if (data.s) { @@ -1642,6 +1703,15 @@ void free_text_objects(struct text_object *root, int internal) info.users.times = 0; } break; + case OBJ_user_time: + if (info.users.ctime) { + free(info.users.ctime); + info.users.ctime = 0; + } + if (data.s) { + free(data.s); + } + break; #ifdef IBM case OBJ_smapi: case OBJ_smapi_bat_perc: @@ -1650,8 +1720,7 @@ void free_text_objects(struct text_object *root, int internal) free(data.s); break; case OBJ_if_smapi_bat_installed: - free(data.ifblock.s); - free(data.ifblock.str); + free(data.s); break; #endif /* IBM */ #ifdef NVIDIA @@ -1721,8 +1790,8 @@ void free_text_objects(struct text_object *root, int internal) case OBJ_apcupsd_loadbar: #ifdef X11 case OBJ_apcupsd_loadgraph: - case OBJ_apcupsd_loadgauge: #endif /* X11 */ + case OBJ_apcupsd_loadgauge: case OBJ_apcupsd_charge: case OBJ_apcupsd_timeleft: case OBJ_apcupsd_temp: @@ -1749,6 +1818,8 @@ void free_text_objects(struct text_object *root, int internal) break; #endif /* X11 */ } + if(obj->special_data) + free(obj->special_data); free(obj); } #undef data