#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <pthread.h>
#include <string.h>
#include <limits.h>
#if HAVE_DIRENT_H
#define MAIL_FILE "$MAIL"
#define MAX_IF_BLOCK_DEPTH 5
+/* #define SIGNAL_BLOCKING */
+#undef SIGNAL_BLOCKING
+
#ifdef X11
/* alignments */
static void set_font();
-
int addfont(const char *data_in)
{
if (font_count > MAX_FONTS) {
/* border */
static int draw_borders;
+static int draw_graph_borders;
static int stippled_borders;
static int draw_shades, draw_outline;
#ifdef OWN_WINDOW
static int own_window = 0;
static int background_colour = 0;
+static char wm_class_name[256];
/* fixed size/pos is set if wm/user changes them */
static int fixed_size = 0, fixed_pos = 0;
#endif
/* pad percentages to decimals? */
static int pad_percents = 0;
+#ifdef TCP_PORT_MONITOR
+tcp_port_monitor_collection_args_t tcp_port_monitor_collection_args;
+tcp_port_monitor_args_t tcp_port_monitor_args;
+#endif
+
/* Text that is shown */
static char original_text[] =
"$nodename - $sysname $kernel on $machine\n"
int check_mount(char *s)
{
+#if defined(__linux__)
int ret = 0;
FILE *mtab = fopen("/etc/mtab", "r");
if (mtab) {
ERR("Could not open mtab");
}
return ret;
+#elif defined(__FreeBSD__)
+ struct statfs *mntbuf;
+ int i, mntsize;
+
+ mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
+ for (i = mntsize - 1; i >= 0; i--)
+ if (strcmp(mntbuf[i].f_mntonname, s) == 0)
+ return 1;
+
+ return 0;
+#endif
}
#ifdef X11
-static inline int calc_text_width(const char *s, unsigned int l)
+static inline int calc_text_width(const char *s, int l)
{
#ifdef XFT
if (use_xft) {
static int special_index; /* used when drawing */
#endif /* X11 */
-#define MAX_GRAPH_DEPTH 256 /* why 256? who knows. */
+#define MAX_GRAPH_DEPTH 256 /* why 256? cause an array of more then 256 doubles seems excessive, and who needs that kind of precision anyway? */
static struct special_t *new_special(char *buf, int t)
{
buf[0] = SPECIAL_CHAR;
buf[1] = '\0';
- if (t == GRAPH && specials[special_count].graph == NULL) {
- if (specials[special_count].width > 0
- && specials[special_count].width < MAX_GRAPH_DEPTH)
- specials[special_count].graph_width = specials[special_count].width - 3; // subtract 3 for the box
- else
- specials[special_count].graph_width =
- MAX_GRAPH_DEPTH;
- specials[special_count].graph =
- calloc(specials[special_count].graph_width,
- sizeof(double));
- specials[special_count].graph_scale = 100;
- }
specials[special_count].type = t;
return &specials[special_count++];
}
}
}
+short colour_depth = 0;
+void set_up_gradient();
+
+/* precalculated: 31/255, and 63/255 */
+#define CONST_8_TO_5_BITS 0.12156862745098
+#define CONST_8_TO_6_BITS 0.247058823529412
+
+/* adjust color values depending on color depth*/
+static unsigned int adjust_colors(unsigned int color)
+{
+ double r, g, b;
+ if (colour_depth == 0) {
+ set_up_gradient();
+ }
+ if (colour_depth == 16) {
+ r = (color & 0xff0000) >> 16;
+ g = (color & 0xff00) >> 8;
+ b = color & 0xff;
+ color = (int)(r * CONST_8_TO_5_BITS) << 11;
+ color |= (int)(g * CONST_8_TO_6_BITS) << 5;
+ color |= (int)(b * CONST_8_TO_5_BITS);
+ }
+ return color;
+}
+
static void new_graph(char *buf, int w, int h, unsigned int first_colour, unsigned int second_colour, double i, int scale, int append)
{
struct special_t *s = new_special(buf, GRAPH);
s->width = w;
+ if (s->graph == NULL) {
+ if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
+ s->graph_width = s->width - 3; // subtract 3 for the box
+ } else {
+ s->graph_width = MAX_GRAPH_DEPTH - 3;
+ }
+ s->graph = malloc(s->graph_width * sizeof(double));
+ memset(s->graph, 0, s->graph_width * sizeof(double));
+ s->graph_scale = 100;
+ }
s->height = h;
- s->first_colour = first_colour;
- s->last_colour = second_colour;
+ s->first_colour = adjust_colors(first_colour);
+ s->last_colour = adjust_colors(second_colour);
if (scale != 0) {
s->scaled = 0;
} else {
s->scaled = 1;
}
- if (s->width) {
+ /*if (s->width) {
s->graph_width = s->width - 3; // subtract 3 for rectangle around
- }
+ }*/
if (s->scaled) {
s->graph_scale = 1;
} else {
/* converts from bytes to human readable format (k, M, G, T) */
static void human_readable(long long a, char *buf, int size)
{
- //Strange conditional due to possible overflows
+ // Strange conditional due to possible overflows
if(a / 1024 / 1024 / 1024.0 > 1024.0){
- snprintf(buf, size, "%.2fT", (a / 1024 / 1024) / 1024 / 1024.0);
+ snprintf(buf, size, "%.2fT", (a / 1024 / 1024 / 1024) / 1024.0);
}
else if (a >= 1024 * 1024 * 1024) {
snprintf(buf, size, "%.2fG", (a / 1024 / 1024) / 1024.0);
OBJ_endif,
OBJ_exec,
OBJ_execi,
+ OBJ_texeci,
OBJ_execbar,
OBJ_execgraph,
OBJ_execibar,
OBJ_alignr,
OBJ_alignc,
OBJ_i2c,
+#if defined(__linux__)
+ OBJ_i8k_version,
+ OBJ_i8k_bios,
+ OBJ_i8k_serial,
+ OBJ_i8k_cpu_temp,
+ OBJ_i8k_cpu_tempf,
+ OBJ_i8k_left_fan_status,
+ OBJ_i8k_right_fan_status,
+ OBJ_i8k_left_fan_rpm,
+ OBJ_i8k_right_fan_rpm,
+ OBJ_i8k_ac_status,
+ OBJ_i8k_buttons_status,
+#endif /* __linux__ */
OBJ_if_existing,
OBJ_if_mounted,
OBJ_if_running,
OBJ_top,
OBJ_top_mem,
OBJ_tail,
+ OBJ_head,
OBJ_kernel,
OBJ_loadavg,
OBJ_machine,
OBJ_upspeedgraph,
OBJ_uptime,
OBJ_uptime_short,
+#if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
+ OBJ_apm_adapter,
+ OBJ_apm_battery_time,
+ OBJ_apm_battery_life,
+#endif /* __FreeBSD__ */
#ifdef SETI
OBJ_seti_prog,
OBJ_seti_progbar,
OBJ_mpd_title,
OBJ_mpd_artist,
OBJ_mpd_album,
+ OBJ_mpd_random,
+ OBJ_mpd_repeat,
OBJ_mpd_vol,
OBJ_mpd_bitrate,
OBJ_mpd_status,
OBJ_mpd_bar,
OBJ_mpd_elapsed,
OBJ_mpd_length,
+ OBJ_mpd_track,
OBJ_mpd_percent,
#endif
+#ifdef AUDACIOUS
+ OBJ_audacious_status,
+ OBJ_audacious_song,
+ OBJ_audacious_song_length,
+ OBJ_audacious_song_length_seconds,
+ OBJ_audacious_song_length_frames,
+ OBJ_audacious_song_output_length,
+ OBJ_audacious_song_output_length_seconds,
+ OBJ_audacious_song_output_length_frames,
+ OBJ_audacious_song_bitrate,
+ OBJ_audacious_song_frequency,
+ OBJ_audacious_song_channels,
+ OBJ_audacious_bar,
+#endif
+#ifdef BMPX
+ OBJ_bmpx_title,
+ OBJ_bmpx_artist,
+ OBJ_bmpx_album,
+ OBJ_bmpx_track,
+ OBJ_bmpx_uri,
+ OBJ_bmpx_bitrate,
+#endif
+#ifdef INFOPIPE
+ OBJ_infopipe_protocol,
+ OBJ_infopipe_version,
+ OBJ_infopipe_status,
+ OBJ_infopipe_playlist_tunes,
+ OBJ_infopipe_playlist_currtune,
+ OBJ_infopipe_usec_position,
+ OBJ_infopipe_position,
+ OBJ_infopipe_usec_time,
+ OBJ_infopipe_time,
+ OBJ_infopipe_bitrate,
+ OBJ_infopipe_frequency,
+ OBJ_infopipe_channels,
+ OBJ_infopipe_title,
+ OBJ_infopipe_file,
+ OBJ_infopipe_bar,
+#endif
+#ifdef TCP_PORT_MONITOR
+ OBJ_tcp_portmon,
+#endif
};
struct text_object {
struct net_stat *net;
struct fs_stat *fs;
unsigned char loadavg[3];
- unsigned int diskio;
-
+ //unsigned int diskio;
+ unsigned int cpu_index;
struct {
struct fs_stat *fs;
int w, h;
struct {
int a, b;
} pair; /* 2 */
+#ifdef TCP_PORT_MONITOR
+ struct {
+ in_port_t port_range_begin; /* starting port to monitor */
+ in_port_t port_range_end; /* ending port to monitor */
+ int item; /* enum value from libtcp-portmon.h, e.g. COUNT, REMOTEIP, etc. */
+ int connection_index; /* 0 to n-1 connections. */
+ } tcp_port_monitor;
+#endif
} data;
};
+struct text_object_list {
+ unsigned int text_object_count;
+ struct text_object *text_objects;
+};
+
static unsigned int text_object_count;
static struct text_object *text_objects;
+static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur);
+
+pthread_mutex_t mutex1 = PTHREAD_MUTEX_INITIALIZER;
+
+void *threaded_exec( struct text_object *obj ) {
+ char *p2 = obj->data.execi.buffer;
+ FILE *fp = popen(obj->data.execi.cmd,"r");
+ pthread_mutex_lock( &mutex1 );
+ int n2 = fread(p2, 1, TEXT_BUFFER_SIZE, fp);
+ (void) pclose(fp);
+ p2[n2] = '\0';
+ if (n2 && p2[n2 - 1] == '\n')
+ p2[n2 - 1] = '\0';
+
+ while (*p2) {
+ if (*p2 == '\001')
+ *p2 = ' ';
+ p2++;
+ }
+ pthread_mutex_unlock( &mutex1 );
+ return NULL;
+}
-/* new_text_object() allocates a new zeroed text_object */
-static struct text_object *new_text_object()
+static struct text_object *new_text_object_internal()
{
- text_object_count++;
- text_objects = (struct text_object *) realloc(text_objects,
- sizeof(struct
- text_object) *
- text_object_count);
- memset(&text_objects[text_object_count - 1], 0,
- sizeof(struct text_object));
-
- return &text_objects[text_object_count - 1];
+ struct text_object *obj = malloc(sizeof(struct text_object));
+ memset(obj, 0, sizeof(struct text_object));
+ return obj;
}
-static void free_text_objects()
+#ifdef MLDONKEY
+void ml_cleanup()
+{
+ if (mlconfig.mldonkey_hostname) {
+ free(mlconfig.mldonkey_hostname);
+ mlconfig.mldonkey_hostname = NULL;
+ }
+}
+#endif
+
+static void free_text_objects(unsigned int count, struct text_object *objs)
{
unsigned int i;
- for (i = 0; i < text_object_count; i++) {
- switch (text_objects[i].type) {
+ for (i = 0; i < count; i++) {
+ switch (objs[i].type) {
case OBJ_acpitemp:
- close(text_objects[i].data.i);
+ close(objs[i].data.i);
break;
case OBJ_acpitempf:
- close(text_objects[i].data.i);
+ close(objs[i].data.i);
break;
case OBJ_i2c:
- close(text_objects[i].data.i2c.fd);
+ close(objs[i].data.i2c.fd);
break;
case OBJ_time:
+ free(objs[i].data.s);
+ break;
case OBJ_utime:
case OBJ_if_existing:
case OBJ_if_mounted:
case OBJ_if_running:
- free(text_objects[i].data.ifblock.s);
+ free(objs[i].data.ifblock.s);
+ break;
+ case OBJ_tail:
+ free(objs[i].data.tail.logfile);
+ free(objs[i].data.tail.buffer);
+ break;
+ case OBJ_text: case OBJ_font:
+ free(objs[i].data.s);
break;
- case OBJ_text:
case OBJ_exec:
- free(text_objects[i].data.s);
+ free(objs[i].data.s);
break;
case OBJ_execbar:
- free(text_objects[i].data.s);
+ free(objs[i].data.s);
break;
case OBJ_execgraph:
- free(text_objects[i].data.s);
+ free(objs[i].data.s);
break;
/* case OBJ_execibar:
- free(text_objects[i].data.s);
+ free(objs[i].data.s);
break;
case OBJ_execigraph:
- free(text_objects[i].data.s);
+ free(objs[i].data.s);
break;*/
#ifdef MPD
case OBJ_mpd_title:
case OBJ_mpd_artist:
case OBJ_mpd_album:
+ case OBJ_mpd_random:
+ case OBJ_mpd_repeat:
+ case OBJ_mpd_track:
case OBJ_mpd_status:
case OBJ_mpd_host:
#endif
+#ifdef BMPX
+ case OBJ_bmpx_title:
+ case OBJ_bmpx_artist:
+ case OBJ_bmpx_album:
+ case OBJ_bmpx_track:
+ case OBJ_bmpx_uri:
+ case OBJ_bmpx_bitrate:
+#endif
case OBJ_pre_exec:
case OBJ_battery:
- free(text_objects[i].data.s);
+ free(objs[i].data.s);
break;
case OBJ_execi:
- free(text_objects[i].data.execi.cmd);
- free(text_objects[i].data.execi.buffer);
+ free(objs[i].data.execi.cmd);
+ free(objs[i].data.execi.buffer);
+ break;
+ case OBJ_texeci:
+ free(objs[i].data.execi.cmd);
+ free(objs[i].data.execi.buffer);
+ break;
+ case OBJ_top:
+ if (info.first_process) {
+ free_all_processes();
+ info.first_process = NULL;
+ }
+ break;
+ case OBJ_top_mem:
+ if (info.first_process) {
+ free_all_processes();
+ info.first_process = NULL;
+ }
break;
}
}
-
- free(text_objects);
- text_objects = NULL;
- text_object_count = 0;
+ free(objs);
+ //text_objects = NULL;
+ //text_object_count = 0;
}
void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
}
}
+
/* construct_text_object() creates a new text_object */
-static void construct_text_object(const char *s, const char *arg)
+static struct text_object *construct_text_object(const char *s, const char *arg)
{
- struct text_object *obj = new_text_object();
+ //struct text_object *obj = new_text_object();
+ struct text_object *obj = new_text_object_internal();
#define OBJ(a, n) if (strcmp(s, #a) == 0) { obj->type = OBJ_##a; need_mask |= (1 << n); {
#define END ; } } else
else
strcpy(bat, "BAT0");
obj->data.s = strdup(bat);
+#if defined(__linux__)
+ END OBJ(i8k_version, INFO_I8K)
+ END OBJ(i8k_bios, INFO_I8K)
+ END OBJ(i8k_serial, INFO_I8K)
+ END OBJ(i8k_cpu_temp, INFO_I8K)
+ END OBJ(i8k_cpu_tempf, INFO_I8K)
+ END OBJ(i8k_left_fan_status, INFO_I8K)
+ END OBJ(i8k_right_fan_status, INFO_I8K)
+ END OBJ(i8k_left_fan_rpm, INFO_I8K)
+ END OBJ(i8k_right_fan_rpm, INFO_I8K)
+ END OBJ(i8k_ac_status, INFO_I8K)
+ END OBJ(i8k_buttons_status, INFO_I8K)
+#endif /* __linux__ */
END OBJ(buffers, INFO_BUFFERS)
END OBJ(cached, INFO_BUFFERS)
END OBJ(cpu, INFO_CPU)
+ if (arg) {
+ if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+ obj->data.cpu_index = atoi(&arg[3]);
+ arg += 4;
+ } else {obj->data.cpu_index = 0; }
+ } else {
+ obj->data.cpu_index = 0;
+ }
END OBJ(cpubar, INFO_CPU)
- (void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
+ if (arg) {
+ if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+ obj->data.cpu_index = atoi(&arg[3]);
+ arg += 4;
+ }
+ else {obj->data.cpu_index = 0;}
+ (void) scan_bar(arg, &obj->a, &obj->b);
+ } else {
+ (void) scan_bar(arg, &obj->a, &obj->b);
+ obj->data.cpu_index = 0;
+ }
END OBJ(cpugraph, INFO_CPU)
- (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+ if (arg) {
+ if (strncmp(arg, "cpu", 3) == 0 && isdigit(arg[3])) {
+ obj->data.cpu_index = atoi(&arg[3]);
+ arg += 4;
+ }
+ (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+ } else {
+ (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
+ obj->data.cpu_index = 0;
+ }
END OBJ(diskio, INFO_DISKIO)
END OBJ(diskiograph, INFO_DISKIO) (void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
END OBJ(color, 0)
obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
#endif /* X11 */
END
- OBJ(font, 0)
+ OBJ(font, 0)
obj->data.s = scan_font(arg);
- END
- OBJ(downspeed, INFO_NET) obj->data.net = get_net_stat(arg);
- END OBJ(downspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
+ END
+ OBJ(downspeed, INFO_NET)
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("downspeed needs argument");
+ }
+ END OBJ(downspeedf, INFO_NET)
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("downspeedf needs argument");
+ }
END OBJ(downspeedgraph, INFO_NET)
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
char buf[64];
obj->type = OBJ_text;
snprintf(buf, 256, "${%s}", s);
obj->data.s = strdup(buf);
- } else {
- obj->data.execi.cmd = strdup(arg + n);
- }
+ } else {
+ obj->data.execi.cmd = strdup(arg + n);
+ }
END OBJ(execi, 0) unsigned int n;
if (!arg
obj->data.execi.buffer =
(char *) calloc(1, TEXT_BUFFER_SIZE);
}
+ END OBJ(texeci, 0) unsigned int n;
+
+ if (!arg
+ || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
+ char buf[256];
+ ERR("${texeci <interval> command}");
+ obj->type = OBJ_text;
+ snprintf(buf, 256, "${%s}", s);
+ obj->data.s = strdup(buf);
+ } else {
+ obj->data.execi.cmd = strdup(arg + n);
+ obj->data.execi.buffer =
+ (char *) calloc(1, TEXT_BUFFER_SIZE);
+ }
END OBJ(pre_exec, 0) obj->type = OBJ_text;
if (arg) {
FILE *fp = popen(arg, "r");
if (!arg) {
ERR("i2c needs arguments");
obj->type = OBJ_text;
- obj->data.s = strdup("${i2c}");
- return;
+ //obj->data.s = strdup("${i2c}");
+ return NULL;
}
if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
obj->data.i2c.fd =
open_i2c_sensor(0, buf2, n, &obj->data.i2c.arg,
obj->data.i2c.devtype);
- strcpy(obj->data.i2c.type, buf2);
+ strncpy(obj->data.i2c.type, buf2, 63);
} else {
obj->data.i2c.fd =
open_i2c_sensor(buf1, buf2, n, &obj->data.i2c.arg,
obj->data.i2c.devtype);
- strcpy(obj->data.i2c.type, buf2);
+ strncpy(obj->data.i2c.type, buf2, 63);
}
END OBJ(top, INFO_TOP)
if (!arg) {
ERR("top needs arguments");
obj->type = OBJ_text;
- obj->data.s = strdup("${top}");
- return;
+ //obj->data.s = strdup("${top}");
+ return NULL;
}
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
if (strcmp(buf, "name") == 0) {
obj->data.top.type = TOP_MEM;
} else {
ERR("invalid arg for top");
- return;
+ return NULL;
}
if (n < 1 || n > 10) {
CRIT_ERR("invalid arg for top");
- return;
+ return NULL;
} else {
obj->data.top.num = n - 1;
top_cpu = 1;
}
} else {
ERR("invalid args given for top");
- return;
+ return NULL;
}
END OBJ(top_mem, INFO_TOP)
char buf[64];
ERR("top_mem needs arguments");
obj->type = OBJ_text;
obj->data.s = strdup("${top_mem}");
- return;
+ return NULL;
}
if (sscanf(arg, "%63s %i", buf, &n) == 2) {
if (strcmp(buf, "name") == 0) {
obj->data.top.type = TOP_MEM;
} else {
ERR("invalid arg for top");
- return;
+ return NULL;
}
if (n < 1 || n > 10) {
CRIT_ERR("invalid arg for top");
- return;
+ return NULL;
} else {
obj->data.top.num = n - 1;
top_mem = 1;
}
} else {
ERR("invalid args given for top");
- return;
+ return NULL;
}
- END OBJ(addr, INFO_NET) obj->data.net = get_net_stat(arg);
- END OBJ(linkstatus, INFO_WIFI) obj->data.net = get_net_stat(arg);
+ END OBJ(addr, INFO_NET)
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("addr needs argument");
+ }
+ END OBJ(linkstatus, INFO_WIFI)
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("linkstatus needs argument");
+ }
END OBJ(tail, 0)
char buf[64];
int n1, n2;
ERR("tail needs arguments");
obj->type = OBJ_text;
obj->data.s = strdup("${tail}");
- return;
+ return NULL;
}
if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
if (n1 < 1 || n1 > 30) {
CRIT_ERR("invalid arg for tail, number of lines must be between 1 and 30");
- return;
+ return NULL;
} else {
- FILE *fp;
- fp = fopen(buf, "rt");
- if (fp != NULL) {
+ FILE *fp = NULL;
+ fp = fopen(buf, "r");
+ if (fp) {
obj->data.tail.logfile =
malloc(TEXT_BUFFER_SIZE);
strcpy(obj->data.tail.logfile, buf);
if (n1 < 1 || n1 > 30) {
CRIT_ERR
("invalid arg for tail, number of lines must be between 1 and 30");
- return;
+ return NULL;
} else if (n2 < 1 || n2 < update_interval) {
CRIT_ERR
("invalid arg for tail, interval must be greater than 0 and Conky's interval");
- return;
+ return NULL;
} else {
FILE *fp;
- fp = fopen(buf, "rt");
+ fp = fopen(buf, "r");
if (fp != NULL) {
obj->data.tail.logfile =
malloc(TEXT_BUFFER_SIZE);
else {
ERR("invalid args given for tail");
- return;
+ return NULL;
+ }
+ obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
+ END OBJ(head, 0)
+ char buf[64];
+ int n1, n2;
+ if (!arg) {
+ ERR("head needs arguments");
+ obj->type = OBJ_text;
+ obj->data.s = strdup("${head}");
+ return NULL;
+ }
+ if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
+ if (n1 < 1 || n1 > 30) {
+ CRIT_ERR("invalid arg for head, number of lines must be between 1 and 30");
+ return NULL;
+ } else {
+ FILE *fp;
+ fp = fopen(buf, "r");
+ if (fp != NULL) {
+ obj->data.tail.logfile =
+ malloc(TEXT_BUFFER_SIZE);
+ strcpy(obj->data.tail.logfile, buf);
+ obj->data.tail.wantedlines = n1 - 1;
+ obj->data.tail.interval =
+ update_interval * 2;
+ fclose(fp);
+ } else {
+ //fclose (fp);
+ CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
+ }
+ }
+ } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
+ if (n1 < 1 || n1 > 30) {
+ CRIT_ERR
+ ("invalid arg for head, number of lines must be between 1 and 30");
+ return NULL;
+ } else if (n2 < 1 || n2 < update_interval) {
+ CRIT_ERR
+ ("invalid arg for head, interval must be greater than 0 and Conky's interval");
+ return NULL;
+ } else {
+ FILE *fp;
+ fp = fopen(buf, "r");
+ if (fp != NULL) {
+ obj->data.tail.logfile =
+ malloc(TEXT_BUFFER_SIZE);
+ strcpy(obj->data.tail.logfile, buf);
+ obj->data.tail.wantedlines = n1 - 1;
+ obj->data.tail.interval = n2;
+ fclose(fp);
+ } else {
+ //fclose (fp);
+ CRIT_ERR("head logfile does not exist, or you do not have correct permissions");
+ }
+ }
+ }
+
+ else {
+ ERR("invalid args given for head");
+ return NULL;
}
- obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 6); /* asumming all else worked */
+ obj->data.tail.buffer = malloc(TEXT_BUFFER_SIZE * 20); /* asumming all else worked */
END OBJ(loadavg, INFO_LOADAVG) int a = 1, b = 2, c = 3, r = 3;
if (arg) {
r = sscanf(arg, "%d %d %d", &a, &b, &c);
obj->data.i2c.devtype);
END OBJ(time, 0) obj->data.s = strdup(arg ? arg : "%F %T");
END OBJ(utime, 0) obj->data.s = strdup(arg ? arg : "%F %T");
- END OBJ(totaldown, INFO_NET) obj->data.net = get_net_stat(arg);
+ END OBJ(totaldown, INFO_NET)
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("totaldown needs argument");
+ }
END OBJ(totalup, INFO_NET) obj->data.net = get_net_stat(arg);
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("totalup needs argument");
+ }
END OBJ(updates, 0)
END OBJ(alignr, 0) obj->data.i = arg ? atoi(arg) : 0;
END OBJ(alignc, 0) obj->data.i = arg ? atoi(arg) : 0;
- END OBJ(upspeed, INFO_NET) obj->data.net = get_net_stat(arg);
- END OBJ(upspeedf, INFO_NET) obj->data.net = get_net_stat(arg);
+ END OBJ(upspeed, INFO_NET)
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("upspeed needs argument");
+ }
+ END OBJ(upspeedf, INFO_NET)
+ if(arg) {
+ obj->data.net = get_net_stat(arg);
+ }
+ else {
+ CRIT_ERR("upspeedf needs argument");
+ }
+
END OBJ(upspeedgraph, INFO_NET)
(void) scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d, &obj->e);
char buf[64];
}
END OBJ(uptime_short, INFO_UPTIME) END OBJ(uptime, INFO_UPTIME) END
OBJ(adt746xcpu, 0) END OBJ(adt746xfan, 0) END
+#if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
+ OBJ(apm_adapter, 0) END
+ OBJ(apm_battery_life, 0) END
+ OBJ(apm_battery_time, 0) END
+#endif /* __FreeBSD__ */
#ifdef SETI
OBJ(seti_prog, INFO_SETI) END OBJ(seti_progbar, INFO_SETI)
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
#ifdef MPD
OBJ(mpd_artist, INFO_MPD)
END OBJ(mpd_title, INFO_MPD)
+ END OBJ(mpd_random, INFO_MPD)
+ END OBJ(mpd_repeat, INFO_MPD)
END OBJ(mpd_elapsed, INFO_MPD)
END OBJ(mpd_length, INFO_MPD)
+ END OBJ(mpd_track, INFO_MPD)
END OBJ(mpd_percent, INFO_MPD)
END OBJ(mpd_album, INFO_MPD) END OBJ(mpd_vol,
INFO_MPD) END OBJ(mpd_bitrate,
INFO_MPD)
- END OBJ(mpd_status, INFO_MPD) END OBJ(mpd_bar, INFO_MPD)
+ END OBJ(mpd_status, INFO_MPD)
+ END OBJ(mpd_bar, INFO_MPD)
(void) scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
END
#endif
+#ifdef AUDACIOUS
+ OBJ(audacious_status, INFO_AUDACIOUS) END
+ OBJ(audacious_song, INFO_AUDACIOUS) END
+ OBJ(audacious_song_length, INFO_AUDACIOUS) END
+ OBJ(audacious_song_length_seconds, INFO_AUDACIOUS) END
+ OBJ(audacious_song_length_frames, INFO_AUDACIOUS) END
+ OBJ(audacious_song_output_length, INFO_AUDACIOUS) END
+ OBJ(audacious_song_output_length_seconds, INFO_AUDACIOUS) END
+ OBJ(audacious_song_output_length_frames, INFO_AUDACIOUS) END
+ OBJ(audacious_song_bitrate, INFO_AUDACIOUS) END
+ OBJ(audacious_song_frequency, INFO_AUDACIOUS) END
+ OBJ(audacious_song_channels, INFO_AUDACIOUS) END
+ OBJ(audacious_bar, INFO_AUDACIOUS)
+ (void) scan_bar(arg, &obj->a, &obj->b);
+ END
+#endif
+#ifdef BMPX
+ OBJ(bmpx_title, INFO_BMPX)
+ memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
+ END
+ OBJ(bmpx_artist, INFO_BMPX)
+ memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
+ END
+ OBJ(bmpx_album, INFO_BMPX)
+ memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
+ END
+ OBJ(bmpx_track, INFO_BMPX)
+ memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
+ END
+ OBJ(bmpx_uri, INFO_BMPX)
+ memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
+ END
+ OBJ(bmpx_bitrate, INFO_BMPX)
+ memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
+ END
+#endif
+#ifdef INFOPIPE
+ OBJ(infopipe_protocol, INFO_INFOPIPE) END
+ OBJ(infopipe_version, INFO_INFOPIPE) END
+ OBJ(infopipe_status, INFO_INFOPIPE) END
+ OBJ(infopipe_playlist_tunes, INFO_INFOPIPE) END
+ OBJ(infopipe_playlist_currtune, INFO_INFOPIPE) END
+ OBJ(infopipe_usec_position, INFO_INFOPIPE) END
+ OBJ(infopipe_position, INFO_INFOPIPE) END
+ OBJ(infopipe_usec_time, INFO_INFOPIPE) END
+ OBJ(infopipe_time, INFO_INFOPIPE) END
+ OBJ(infopipe_bitrate, INFO_INFOPIPE) END
+ OBJ(infopipe_frequency, INFO_INFOPIPE) END
+ OBJ(infopipe_channels, INFO_INFOPIPE) END
+ OBJ(infopipe_title, INFO_INFOPIPE) END
+ OBJ(infopipe_file, INFO_INFOPIPE) END
+ OBJ(infopipe_bar, INFO_INFOPIPE)
+ (void) scan_bar(arg, &obj->a, &obj->b);
+ END
+#endif
+#ifdef TCP_PORT_MONITOR
+ OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
+ int argc, port_begin, port_end, item, connection_index;
+ char itembuf[32];
+ memset(itembuf,0,sizeof(itembuf));
+ connection_index=0;
+ /* massive argument checking */
+ if (!arg) {
+ CRIT_ERR("tcp_portmon: needs arguments");
+ }
+ argc=sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf, &connection_index);
+ if ( (argc != 3) && (argc != 4) )
+ {
+ CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
+ }
+ if ( (port_begin<1) || (port_begin>65535) || (port_end<1) || (port_end>65535) )
+ {
+ CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
+ }
+ if ( port_begin > port_end )
+ {
+ CRIT_ERR("tcp_portmon: starting port must be <= ending port");
+ }
+ if ( strncmp(itembuf,"count",31) == 0 )
+ item=COUNT;
+ else if ( strncmp(itembuf,"rip",31) == 0 )
+ item=REMOTEIP;
+ else if ( strncmp(itembuf,"rhost",31) == 0 )
+ item=REMOTEHOST;
+ else if ( strncmp(itembuf,"rport",31) == 0 )
+ item=REMOTEPORT;
+ else if ( strncmp(itembuf,"lip",31) == 0 )
+ item=LOCALIP;
+ else if ( strncmp(itembuf,"lhost",31) == 0 )
+ item=LOCALHOST;
+ else if ( strncmp(itembuf,"lport",31) == 0 )
+ item=LOCALPORT;
+ else if ( strncmp(itembuf,"lservice",31) == 0 )
+ item=LOCALSERVICE;
+ else
+ {
+ CRIT_ERR("tcp_portmon: invalid item specified");
+ }
+ if ( (argc==3) && (item!=COUNT) )
+ {
+ CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" item");
+ }
+ if ( (argc==4) && (connection_index<0) )
+ {
+ CRIT_ERR("tcp_portmon: connection index must be non-negative");
+ }
+ /* ok, args looks good. save the text object data */
+ obj->data.tcp_port_monitor.port_range_begin = (in_addr_t)port_begin;
+ obj->data.tcp_port_monitor.port_range_end = (in_addr_t)port_end;
+ obj->data.tcp_port_monitor.item = item;
+ obj->data.tcp_port_monitor.connection_index = connection_index;
+
+ /* if the port monitor collection hasn't been created, we must create it */
+ if ( !info.p_tcp_port_monitor_collection )
+ {
+ info.p_tcp_port_monitor_collection =
+ create_tcp_port_monitor_collection( &tcp_port_monitor_collection_args );
+ if ( !info.p_tcp_port_monitor_collection )
+ {
+ CRIT_ERR("tcp_portmon: unable to create port monitor collection");
+ }
+ }
+
+ /* if a port monitor for this port does not exist, create one and add it to the collection */
+ if ( find_tcp_port_monitor( info.p_tcp_port_monitor_collection, port_begin, port_end ) == NULL )
+ {
+ tcp_port_monitor_t * p_monitor =
+ create_tcp_port_monitor( port_begin, port_end, &tcp_port_monitor_args );
+ if ( !p_monitor )
+ {
+ CRIT_ERR("tcp_portmon: unable to create port monitor");
+ }
+ /* add the newly created monitor to the collection */
+ if ( insert_tcp_port_monitor_into_collection( info.p_tcp_port_monitor_collection,
+ p_monitor ) != 0 )
+ {
+ CRIT_ERR("tcp_portmon: unable to add port monitor to collection");
+ }
+ }
+ END
+#endif
{
char buf[256];
ERR("unknown variable %s", s);
obj->data.s = strdup(buf);
}
#undef OBJ
+
+ return obj;
}
-/* append_text() appends text to last text_object if it's text, if it isn't
- * it creates a new text_object */
-static void append_text(const char *s)
+static struct text_object *create_plain_text(const char *s)
{
- struct text_object *obj;
-
- if (s == NULL || *s == '\0')
- return;
+ struct text_object *obj;
- obj = text_object_count ? &text_objects[text_object_count - 1] : 0;
+ if (s == NULL || *s == '\0') {
+ return NULL;
+ }
+
+ obj = new_text_object_internal();
- /* create a new text object? */
- if (!obj || obj->type != OBJ_text) {
- obj = new_text_object();
- obj->type = OBJ_text;
- obj->data.s = strdup(s);
- } else {
- /* append */
- obj->data.s = (char *) realloc(obj->data.s,
- strlen(obj->data.s) +
- strlen(s) + 1);
- strcat(obj->data.s, s);
- }
+ obj->type = OBJ_text;
+ obj->data.s = strdup(s);
+ return obj;
}
-static void extract_variable_text(const char *p)
+static struct text_object_list *extract_variable_text_internal(const char *p)
{
- const char *s = p;
-
- free_text_objects();
-
+ struct text_object_list *retval;
+ struct text_object *obj;
+ const char *s = p;
+
+ retval = malloc(sizeof(struct text_object_list));
+ memset(retval, 0, sizeof(struct text_object_list));
+ retval->text_object_count = 0;
+
while (*p) {
if (*p == '$') {
*(char *) p = '\0';
- append_text(s);
+ obj = create_plain_text(s);
+ if(obj != NULL) {
+ // allocate memory for the object
+ retval->text_objects = realloc(retval->text_objects,
+ sizeof(struct text_object) * (retval->text_object_count+1));
+ // assign the new object to the end of the list.
+ memcpy(&retval->text_objects[retval->text_object_count++],
+ obj, sizeof(struct text_object));
+ free(obj);
+ }
*(char *) p = '$';
p++;
s = p;
p++;
}
- construct_text_object(buf, arg);
+ // create new object
+ obj = construct_text_object(buf, arg);
+ if(obj != NULL) {
+ // allocate memory for the object
+ retval->text_objects = realloc(retval->text_objects,
+ sizeof(struct text_object) * (retval->text_object_count+1));
+ // assign the new object to the end of the list.
+ memcpy(&retval->text_objects[retval->text_object_count++],
+ obj, sizeof(struct text_object));
+ free(obj);
+ }
}
continue;
- } else
- append_text("$");
+ } else {
+ obj = create_plain_text("$");
+ if(obj != NULL) {
+ // allocate memory for the object
+ retval->text_objects = realloc(retval->text_objects,
+ sizeof(struct text_object) * (retval->text_object_count+1));
+ // assign the new object to the end of the list.
+ memcpy(&retval->text_objects[retval->text_object_count++],
+ obj, sizeof(struct text_object));
+ free(obj);
+ }
+ }
}
-
p++;
}
- append_text(s);
+ obj = create_plain_text(s);
+ if(obj != NULL) {
+ // allocate memory for the object
+ retval->text_objects = realloc(retval->text_objects,
+ sizeof(struct text_object) * (retval->text_object_count+1));
+ // assign the new object to the end of the list.
+ memcpy(&retval->text_objects[retval->text_object_count++],
+ obj, sizeof(struct text_object));
+ free(obj);
+ }
+
if (blockdepth) {
ERR("one or more $endif's are missing");
}
-}
-double current_update_time, last_update_time;
+ return retval;
+}
-static void generate_text()
+static void extract_variable_text(const char *p)
{
- unsigned int i, n;
- struct information *cur = &info;
- char *p;
+ struct text_object_list *list;
- special_count = 0;
+ free_text_objects(text_object_count, text_objects);
+ text_object_count = 0;
+ text_objects = NULL;
- /* update info */
+#ifdef MLDONKEY
+ ml_cleanup();
+#endif /* MLDONKEY */
+
+ list = extract_variable_text_internal(p);
+ text_objects = list->text_objects;
+ text_object_count = list->text_object_count;
- current_update_time = get_time();
+ free(list);
- update_stuff(cur);
+ return;
+}
- /* generate text */
+void parse_conky_vars(char * text, char * p, struct information *cur) {
+ struct text_object_list *object_list = extract_variable_text_internal(text);
+ generate_text_internal(p, P_MAX_SIZE, object_list->text_objects, object_list->text_object_count, cur);
+ free(object_list);
+}
- n = TEXT_BUFFER_SIZE * 4 - 2;
- p = text_buffer;
+static void generate_text_internal(char *p, int p_max_size, struct text_object *objs, unsigned int object_count, struct information *cur)
+{
+ unsigned int i;
- for (i = 0; i < text_object_count; i++) {
- struct text_object *obj = &text_objects[i];
+ for (i = 0; i < object_count; i++) {
+ struct text_object *obj = &objs[i];
#define OBJ(a) break; case OBJ_##a:
OBJ(acpitemp) {
/* does anyone have decimals in acpi temperature? */
if (!use_spacer)
- snprintf(p, n, "%d", (int)
+ snprintf(p, p_max_size, "%d", (int)
get_acpi_temperature(obj->
data.
i));
OBJ(acpitempf) {
/* does anyone have decimals in acpi temperature? */
if (!use_spacer)
- snprintf(p, n, "%d", (int)
+ snprintf(p, p_max_size, "%d", (int)
((get_acpi_temperature(obj->
data.
i)+ 40) * 9.0 / 5 - 40));
i)+ 40) * 9.0 / 5 - 40));
}
OBJ(freq) {
- snprintf(p, n, "%.0f", get_freq());
+ get_freq(p, p_max_size, "%.0f", 1); /* pk */
}
OBJ(freq_g) {
- float ghz = (float)(get_freq()/1000);
- //printf("%f\n", ghz);
- snprintf(p, n, "%'.2f", ghz);
+ get_freq(p, p_max_size, "%'.2f", 1000); /* pk */
}
OBJ(freq_dyn) {
- snprintf(p, n, "%.0f", get_freq_dynamic());
+ if (use_spacer) {
+ get_freq_dynamic(p, 6, "%.0f ", 1 ); /* pk */
+ } else {
+ get_freq_dynamic(p, p_max_size, "%.0f", 1 ); /* pk */
+ }
}
OBJ(freq_dyn_g) {
- float ghz = (float)(get_freq_dynamic()/1000);
- snprintf(p, n, "%'.2f", ghz);
+ if (use_spacer) {
+ get_freq_dynamic(p, 6, "%'.2f ", 1000); /* pk */
+ } else {
+ get_freq_dynamic(p, p_max_size, "%'.2f", 1000); /* pk */
+ }
}
OBJ(adt746xcpu) {
- snprintf(p, n, "%s", get_adt746x_cpu());
+ get_adt746x_cpu(p, p_max_size); /* pk */
}
OBJ(adt746xfan) {
- snprintf(p, n, "%s", get_adt746x_fan());
+ get_adt746x_fan(p, p_max_size); /* pk */
}
OBJ(acpifan) {
- snprintf(p, n, "%s", get_acpi_fan());
+ get_acpi_fan(p, p_max_size); /* pk */
}
OBJ(acpiacadapter) {
- snprintf(p, n, "%s",
- get_acpi_ac_adapter());
+ get_acpi_ac_adapter(p, p_max_size); /* pk */
}
OBJ(battery) {
- get_battery_stuff(p, n, obj->data.s);
+ get_battery_stuff(p, p_max_size, obj->data.s);
}
OBJ(buffers) {
- human_readable(cur->buffers * 1024, p,
- 255);
+ human_readable(cur->buffers * 1024, p, 255);
}
OBJ(cached) {
human_readable(cur->cached * 1024, p, 255);
}
OBJ(cpu) {
+ if (obj->data.cpu_index > info.cpu_count) {
+ printf("obj->data.cpu_index %i info.cpu_count %i", obj->data.cpu_index, info.cpu_count);
+ CRIT_ERR("attempting to use more CPUs then you have!");
+ }
if (!use_spacer)
- snprintf(p, n, "%*d", pad_percents,
- (int) (cur->cpu_usage *
+ snprintf(p, p_max_size, "%*d", pad_percents,
+ (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
100.0));
else
snprintf(p, 4, "%*d ",
pad_percents,
- (int) (cur->cpu_usage *
+ (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
100.0));
}
OBJ(cpubar) {
- new_bar(p, obj->data.pair.a,
- obj->data.pair.b,
- (int) (cur->cpu_usage * 255.0));
+ new_bar(p, obj->a,
+ obj->b,
+ (int) round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
}
OBJ(cpugraph) {
new_graph(p, obj->a,
obj->b, obj->c, obj->d,
- (unsigned int) (cur->cpu_usage *
+ (unsigned int) round_to_int(cur->cpu_usage[obj->data.cpu_index] *
100), 100, 1);
}
OBJ(color) {
new_fg(p, obj->data.l);
}
+#if defined(__linux__)
+ OBJ(i8k_version) {
+ snprintf(p, p_max_size, "%s", i8k.version);
+ }
+ OBJ(i8k_bios) {
+ snprintf(p, p_max_size, "%s", i8k.bios);
+ }
+ OBJ(i8k_serial) {
+ snprintf(p, p_max_size, "%s", i8k.serial);
+ }
+ OBJ(i8k_cpu_temp) {
+ snprintf(p, p_max_size, "%s", i8k.cpu_temp);
+ }
+ OBJ(i8k_cpu_tempf) {
+ int cpu_temp;
+ sscanf(i8k.cpu_temp, "%d", &cpu_temp);
+ snprintf(p, p_max_size, "%.1f", cpu_temp*(9.0/5.0)+32.0);
+ }
+ OBJ(i8k_left_fan_status) {
+ int left_fan_status;
+ sscanf(i8k.left_fan_status, "%d", &left_fan_status);
+ if(left_fan_status == 0) {
+ snprintf(p, p_max_size,"off");
+ } if(left_fan_status == 1) {
+ snprintf(p, p_max_size, "low");
+ } if(left_fan_status == 2) {
+ snprintf(p, p_max_size, "high");
+ }
+
+ }
+ OBJ(i8k_right_fan_status) {
+ int right_fan_status;
+ sscanf(i8k.right_fan_status, "%d", &right_fan_status);
+ if(right_fan_status == 0) {
+ snprintf(p, p_max_size,"off");
+ } if(right_fan_status == 1) {
+ snprintf(p, p_max_size, "low");
+ } if(right_fan_status == 2) {
+ snprintf(p, p_max_size, "high");
+ }
+ }
+ OBJ(i8k_left_fan_rpm) {
+ snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
+ }
+ OBJ(i8k_right_fan_rpm) {
+ snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
+ }
+ OBJ(i8k_ac_status) {
+ int ac_status;
+ sscanf(i8k.ac_status, "%d", &ac_status);
+ if(ac_status == -1) {
+ snprintf(p, p_max_size,"disabled (read i8k docs)");
+ } if(ac_status == 0) {
+ snprintf(p, p_max_size, "off");
+ } if(ac_status == 1) {
+ snprintf(p, p_max_size, "on");
+ }
+ }
+ OBJ(i8k_buttons_status) {
+ snprintf(p, p_max_size, "%s", i8k.buttons_status);
+
+ }
+#endif /* __linux__ */
+
#ifdef X11
OBJ(font) {
new_font(p, obj->data.s);
}
#endif /* X11 */
OBJ(diskio) {
- if (diskio_value > 1024) {
- snprintf(p, n, "%.1fM",
- (double)diskio_value/1024);
- } else if (diskio_value > 0) {
- snprintf(p, n, "%dK", diskio_value);
+ if (!use_spacer) {
+ if (diskio_value > 1024*1024) {
+ snprintf(p, p_max_size, "%.1fG",
+ (double)diskio_value/1024/1024);
+ } else if (diskio_value > 1024) {
+ snprintf(p, p_max_size, "%.1fM",
+ (double)diskio_value/1024);
+ } else if (diskio_value > 0) {
+ snprintf(p, p_max_size, "%dK", diskio_value);
+ } else {
+ snprintf(p, p_max_size, "%d", diskio_value);
+ }
} else {
- snprintf(p, n, "%d", diskio_value);
+ if (diskio_value > 1024*1024) {
+ snprintf(p, 6, "%.1fG ",
+ (double)diskio_value/1024/1024);
+ } else if (diskio_value > 1024) {
+ snprintf(p, 6, "%.1fM ",
+ (double)diskio_value/1024);
+ } else if (diskio_value > 0) {
+ snprintf(p, 6, "%dK ", diskio_value);
+ } else {
+ snprintf(p, 6, "%d ", diskio_value);
+ }
}
}
OBJ(diskiograph) {
OBJ(downspeed) {
if (!use_spacer) {
- snprintf(p, n, "%d",
+ snprintf(p, p_max_size, "%d",
(int) (obj->data.net->
recv_speed /
1024));
}
OBJ(downspeedf) {
if (!use_spacer)
- snprintf(p, n, "%.1f",
+ snprintf(p, p_max_size, "%.1f",
obj->data.net->
recv_speed / 1024.0);
else
}
#ifdef HAVE_POPEN
OBJ(addr) {
- snprintf(p, n, "%u.%u.%u.%u",
+ snprintf(p, p_max_size, "%u.%u.%u.%u",
obj->data.net->addr.
sa_data[2] & 255,
obj->data.net->addr.
}
OBJ(linkstatus) {
- snprintf(p, n, "%d",
+ snprintf(p, p_max_size, "%d",
obj->data.net->linkstatus);
}
OBJ(exec) {
- char *p2 = p;
FILE *fp = popen(obj->data.s, "r");
- int n2 = fread(p, 1, n, fp);
+ int length = fread(p, 1, p_max_size, fp);
(void) pclose(fp);
- p[n2] = '\0';
- if (n2 && p[n2 - 1] == '\n')
- p[n2 - 1] = '\0';
-
- while (*p2) {
- if (*p2 == '\001')
- *p2 = ' ';
- p2++;
- }
+ /*output[length] = '\0';
+ if (length > 0 && output[length - 1] == '\n') {
+ output[length - 1] = '\0';
+ }*/
+ p[length] = '\0';
+ if (length > 0 && p[length - 1] == '\n') {
+ p[length - 1] = '\0';
+ }
+
+ //parse_conky_vars(output, p, cur);
}
OBJ(execbar) {
char *p2 = p;
FILE *fp = popen(obj->data.s, "r");
- int n2 = fread(p, 1, n, fp);
+ int n2 = fread(p, 1, p_max_size, fp);
(void) pclose(fp);
p[n2] = '\0';
OBJ(execgraph) {
char *p2 = p;
FILE *fp = popen(obj->data.s, "r");
- int n2 = fread(p, 1, n, fp);
+ int n2 = fread(p, 1, p_max_size, fp);
(void) pclose(fp);
p[n2] = '\0';
}
OBJ(execibar) {
- if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
new_bar(p, 0, 4, (int) obj->f);
} else {
char *p2 = p;
FILE *fp = popen(obj->data.execi.cmd, "r");
- int n2 = fread(p, 1, n, fp);
+ int n2 = fread(p, 1, p_max_size, fp);
(void) pclose(fp);
p[n2] = '\0';
if (n2 && p[n2 - 1] == '\n')
}
}
OBJ(execigraph) {
- if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 0);
} else {
char *p2 = p;
FILE *fp = popen(obj->data.execi.cmd, "r");
- int n2 = fread(p, 1, n, fp);
+ int n2 = fread(p, 1, p_max_size, fp);
(void) pclose(fp);
p[n2] = '\0';
if (n2 && p[n2 - 1] == '\n')
}
OBJ(execi) {
- if (current_update_time -
- obj->data.execi.last_update <
- obj->data.execi.interval) {
- snprintf(p, n, "%s",
- obj->data.execi.buffer);
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval || obj->data.execi.interval == 0) {
+ snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
} else {
- char *p2 = obj->data.execi.buffer;
- FILE *fp =
- popen(obj->data.execi.cmd,
- "r");
- int n2 =
- fread(p2, 1, TEXT_BUFFER_SIZE,
- fp);
+ char *output = obj->data.execi.buffer;
+ FILE *fp = popen(obj->data.execi.cmd, "r");
+ //int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
+ int length = fread(output, 1, TEXT_BUFFER_SIZE, fp);
(void) pclose(fp);
-
- p2[n2] = '\0';
- if (n2 && p2[n2 - 1] == '\n')
- p2[n2 - 1] = '\0';
-
- while (*p2) {
- if (*p2 == '\001')
- *p2 = ' ';
- p2++;
+
+ output[length] = '\0';
+ if (length > 0 && output[length - 1] == '\n') {
+ output[length - 1] = '\0';
}
-
- snprintf(p, n, "%s",
- obj->data.execi.buffer);
-
- obj->data.execi.last_update =
- current_update_time;
+ obj->data.execi.last_update = current_update_time;
+ snprintf(p, p_max_size, "%s", output);
+ }
+ //parse_conky_vars(output, p, cur);
+ }
+ OBJ(texeci) {
+ static int running = 0;
+ if (current_update_time - obj->data.execi.last_update < obj->data.execi.interval) {
+ snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
+ } else {
+ static pthread_t execthread;
+ if (running) {
+ pthread_join( execthread, NULL);
+ running = 0;
+ }
+ if (!running) {
+ running = 1;
+ pthread_create( &execthread, NULL, (void*)threaded_exec, (void*) obj);
+ pthread_mutex_lock( &mutex1 );
+ obj->data.execi.last_update = current_update_time;
+ pthread_mutex_unlock( &mutex1 );
+ }
+ snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
}
+ //parse_conky_vars(obj->data.execi.buffer, p, cur);
}
#endif
OBJ(fs_bar) {
OBJ(fs_free_perc) {
if (obj->data.fs != NULL) {
if (obj->data.fs->size)
- snprintf(p, n, "%*d",
+ snprintf(p, p_max_size, "%*d",
pad_percents,
(int) ((obj->data.
fs->
obj->data.
fs->size));
else
- snprintf(p, n, "0");
+ snprintf(p, p_max_size, "0");
}
}
OBJ(fs_size) {
OBJ(fs_used) {
if (obj->data.fs != NULL)
human_readable(obj->data.fs->size -
- obj->data.fs->avail,
+ (obj->data.fs->free ? obj->data.fs->free :obj->data.fs->avail),
p, 255);
}
OBJ(fs_bar_free) {
fs->
size)));
else
- snprintf(p, n, "0");
+ snprintf(p, p_max_size, "0");
}
}
OBJ(loadavg) {
float *v = info.loadavg;
if (obj->data.loadavg[2])
- snprintf(p, n, "%.2f %.2f %.2f",
+ snprintf(p, p_max_size, "%.2f %.2f %.2f",
v[obj->data.loadavg[0] -
1],
v[obj->data.loadavg[1] -
v[obj->data.loadavg[2] -
1]);
else if (obj->data.loadavg[1])
- snprintf(p, n, "%.2f %.2f",
+ snprintf(p, p_max_size, "%.2f %.2f",
v[obj->data.loadavg[0] -
1],
v[obj->data.loadavg[1] -
1]);
else if (obj->data.loadavg[0])
- snprintf(p, n, "%.2f",
+ snprintf(p, p_max_size, "%.2f",
v[obj->data.loadavg[0] -
1]);
}
obj->data.i2c.type);
if (r >= 100.0 || r == 0)
- snprintf(p, n, "%d", (int) r);
+ snprintf(p, p_max_size, "%d", (int) r);
else
- snprintf(p, n, "%.1f", r);
+ snprintf(p, p_max_size, "%.1f", r);
}
OBJ(alignr) {
new_alignr(p, obj->data.i);
if_jumped = 0;
}
OBJ(kernel) {
- snprintf(p, n, "%s", cur->uname_s.release);
+ snprintf(p, p_max_size, "%s", cur->uname_s.release);
}
OBJ(machine) {
- snprintf(p, n, "%s", cur->uname_s.machine);
+ snprintf(p, p_max_size, "%s", cur->uname_s.machine);
}
/* memory stuff */
OBJ(memperc) {
if (cur->memmax) {
if (!use_spacer)
- snprintf(p, n, "%*d",
+ snprintf(p, p_max_size, "%*lu",
pad_percents,
(cur->mem * 100) /
(cur->memmax));
else
- snprintf(p, 4, "%*d ",
+ snprintf(p, 4, "%*lu ",
pad_percents,
(cur->mem * 100) /
(cur->memmax));
}
/* mixer stuff */
OBJ(mixer) {
- snprintf(p, n, "%d",
+ snprintf(p, p_max_size, "%d",
mixer_get_avg(obj->data.l));
}
OBJ(mixerl) {
- snprintf(p, n, "%d",
+ snprintf(p, p_max_size, "%d",
mixer_get_left(obj->data.l));
}
OBJ(mixerr) {
- snprintf(p, n, "%d",
+ snprintf(p, p_max_size, "%d",
mixer_get_right(obj->data.l));
}
OBJ(mixerbar) {
/* mail stuff */
OBJ(mails) {
- snprintf(p, n, "%d", cur->mail_count);
+ snprintf(p, p_max_size, "%d", cur->mail_count);
}
OBJ(new_mails) {
- snprintf(p, n, "%d", cur->new_mail_count);
+ snprintf(p, p_max_size, "%d", cur->new_mail_count);
}
#ifdef MLDONKEY
OBJ(ml_upload_counter) {
- snprintf(p, n, "%lld",
+ snprintf(p, p_max_size, "%lld",
mlinfo.upload_counter / 1048576);
}
OBJ(ml_download_counter) {
- snprintf(p, n, "%lld",
+ snprintf(p, p_max_size, "%lld",
mlinfo.download_counter /
1048576);
}
OBJ(ml_nshared_files) {
- snprintf(p, n, "%i", mlinfo.nshared_files);
+ snprintf(p, p_max_size, "%i", mlinfo.nshared_files);
}
OBJ(ml_shared_counter) {
- snprintf(p, n, "%lld",
+ snprintf(p, p_max_size, "%lld",
mlinfo.shared_counter / 1048576);
}
OBJ(ml_tcp_upload_rate) {
- snprintf(p, n, "%.2f",
+ snprintf(p, p_max_size, "%.2f",
(float) mlinfo.tcp_upload_rate /
1024);
}
OBJ(ml_tcp_download_rate) {
- snprintf(p, n, "%.2f",
+ snprintf(p, p_max_size, "%.2f",
(float) mlinfo.tcp_download_rate /
1024);
}
OBJ(ml_udp_upload_rate) {
- snprintf(p, n, "%.2f",
+ snprintf(p, p_max_size, "%.2f",
(float) mlinfo.udp_upload_rate /
1024);
}
OBJ(ml_udp_download_rate) {
- snprintf(p, n, "%.2f",
+ snprintf(p, p_max_size, "%.2f",
(float) mlinfo.udp_download_rate /
1024);
}
OBJ(ml_ndownloaded_files) {
- snprintf(p, n, "%i",
+ snprintf(p, p_max_size, "%i",
mlinfo.ndownloaded_files);
}
OBJ(ml_ndownloading_files) {
- snprintf(p, n, "%i",
+ snprintf(p, p_max_size, "%i",
mlinfo.ndownloading_files);
}
#endif
OBJ(nodename) {
- snprintf(p, n, "%s",
+ snprintf(p, p_max_size, "%s",
cur->uname_s.nodename);
}
OBJ(outlinecolor) {
}
OBJ(processes) {
if (!use_spacer)
- snprintf(p, n, "%d", cur->procs);
+ snprintf(p, p_max_size, "%hu", cur->procs);
else
- snprintf(p, 5, "%d ",
+ snprintf(p, 5, "%hu ",
cur->procs);
}
OBJ(running_processes) {
if (!use_spacer)
- snprintf(p, n, "%d",
+ snprintf(p, p_max_size, "%hu",
cur->run_procs);
else
- snprintf(p, 3, "%d ",
+ snprintf(p, 3, "%hu ",
cur->run_procs);
}
OBJ(text) {
- snprintf(p, n, "%s", obj->data.s);
+ snprintf(p, p_max_size, "%s", obj->data.s);
}
OBJ(shadecolor) {
new_bg(p, obj->data.l);
strncpy(p, "No swap", 255);
} else {
if (!use_spacer)
- snprintf(p, 255, "%*u",
+ snprintf(p, 255, "%*lu",
pad_percents,
(cur->swap *
100) /
cur->swapmax);
else
- snprintf(p, 4, "%*u ",
+ snprintf(p, 4, "%*lu ",
pad_percents,
(cur->swap *
100) /
(cur->swapmax) : 0);
}
OBJ(sysname) {
- snprintf(p, n, "%s", cur->uname_s.sysname);
+ snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
}
OBJ(time) {
time_t t = time(NULL);
struct tm *tm = localtime(&t);
setlocale(LC_TIME, "");
- strftime(p, n, obj->data.s, tm);
+ strftime(p, p_max_size, obj->data.s, tm);
}
OBJ(utime) {
time_t t = time(NULL);
struct tm *tm = gmtime(&t);
- strftime(p, n, obj->data.s, tm);
+ strftime(p, p_max_size, obj->data.s, tm);
}
OBJ(totaldown) {
human_readable(obj->data.net->recv, p,
255);
}
OBJ(updates) {
- snprintf(p, n, "%d", total_updates);
+ snprintf(p, p_max_size, "%d", total_updates);
}
OBJ(upspeed) {
if (!use_spacer)
- snprintf(p, n, "%d",
+ snprintf(p, p_max_size, "%d",
(int) (obj->data.net->
trans_speed /
1024));
}
OBJ(upspeedf) {
if (!use_spacer)
- snprintf(p, n, "%.1f",
+ snprintf(p, p_max_size, "%.1f",
obj->data.net->
trans_speed / 1024.0);
else
1024.0), obj->e, 1);
}
OBJ(uptime_short) {
- format_seconds_short(p, n,
+ format_seconds_short(p, p_max_size,
(int) cur->uptime);
}
OBJ(uptime) {
- format_seconds(p, n, (int) cur->uptime);
+ format_seconds(p, p_max_size, (int) cur->uptime);
}
+#if defined(__FreeBSD__) && (defined(i386) || defined(__i386__))
+ OBJ(apm_adapter) {
+ snprintf(p, p_max_size, "%s", get_apm_adapter());
+ }
+ OBJ(apm_battery_life) {
+ char *msg;
+ msg = get_apm_battery_life();
+ snprintf(p, p_max_size, "%s", msg);
+ free(msg);
+ }
+ OBJ(apm_battery_time) {
+ char *msg;
+ msg = get_apm_battery_time();
+ snprintf(p, p_max_size, "%s", msg);
+ free(msg);
+ }
+#endif /* __FreeBSD__ */
#ifdef SETI
OBJ(seti_prog) {
- snprintf(p, n, "%.2f",
+ snprintf(p, p_max_size, "%.2f",
cur->seti_prog * 100.0f);
}
OBJ(seti_progbar) {
(int) (cur->seti_prog * 255.0f));
}
OBJ(seti_credit) {
- snprintf(p, n, "%.0f", cur->seti_credit);
+ snprintf(p, p_max_size, "%.0f", cur->seti_credit);
}
#endif
#ifdef MPD
OBJ(mpd_title) {
- snprintf(p, n, "%s", cur->mpd.title);
+ snprintf(p, p_max_size, "%s", cur->mpd.title);
}
OBJ(mpd_artist) {
- snprintf(p, n, "%s", cur->mpd.artist);
+ snprintf(p, p_max_size, "%s", cur->mpd.artist);
}
OBJ(mpd_album) {
- snprintf(p, n, "%s", cur->mpd.album);
+ snprintf(p, p_max_size, "%s", cur->mpd.album);
+ }
+ OBJ(mpd_random) {
+ snprintf(p, p_max_size, "%s", cur->mpd.random);
+ }
+ OBJ(mpd_repeat) {
+ snprintf(p, p_max_size, "%s", cur->mpd.repeat);
+ }
+ OBJ(mpd_track) {
+ snprintf(p, p_max_size, "%s", cur->mpd.track);
}
OBJ(mpd_vol) {
- snprintf(p, n, "%i", cur->mpd.volume);
+ snprintf(p, p_max_size, "%i", cur->mpd.volume);
}
OBJ(mpd_bitrate) {
- snprintf(p, n, "%i", cur->mpd.bitrate);
+ snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
}
OBJ(mpd_status) {
- snprintf(p, n, "%s", cur->mpd.status);
+ snprintf(p, p_max_size, "%s", cur->mpd.status);
}
OBJ(mpd_elapsed) {
int days = 0, hours = 0, minutes =
}
seconds = tmp;
if (days > 0)
- snprintf(p, n, "%i days %i:%i:%2i",
+ snprintf(p, p_max_size, "%i days %i:%02i:%02i",
+ days, hours, minutes,
+ seconds);
+ else if (hours > 0)
+ snprintf(p, p_max_size, "%i:%02i:%02i", hours,
+ minutes, seconds);
+ else
+ snprintf(p, p_max_size, "%i:%02i", minutes,
+ seconds);
+ }
+ OBJ(mpd_length) {
+ int days = 0, hours = 0, minutes =
+ 0, seconds = 0;
+ int tmp = cur->mpd.length;
+ while (tmp >= 86400) {
+ tmp -= 86400;
+ days++;
+ }
+ while (tmp >= 3600) {
+ tmp -= 3600;
+ hours++;
+ }
+ while (tmp >= 60) {
+ tmp -= 60;
+ minutes++;
+ }
+ seconds = tmp;
+ if (days > 0)
+ snprintf(p, p_max_size,
+ "%i days %i:%02i:%02i",
days, hours, minutes,
seconds);
- else if (days > 0)
- snprintf(p, n, "%i:%i:%02i", hours,
+ else if (hours > 0)
+ snprintf(p, p_max_size, "%i:%02i:%02i", hours,
minutes, seconds);
else
- snprintf(p, n, "%i:%02i", minutes,
+ snprintf(p, p_max_size, "%i:%02i", minutes,
seconds);
}
- OBJ(mpd_length) {
- int days = 0, hours = 0, minutes =
- 0, seconds = 0;
- int tmp = cur->mpd.length;
- while (tmp >= 86400) {
- tmp -= 86400;
- days++;
- }
- while (tmp >= 3600) {
- tmp -= 3600;
- hours++;
- }
- while (tmp >= 60) {
- tmp -= 60;
- minutes++;
- }
- seconds = tmp;
- if (days > 0)
- snprintf(p, n,
- "%i days %i:%i:%02i",
- days, hours, minutes,
- seconds);
- else if (days > 0)
- snprintf(p, n, "%i:%i:%02i", hours,
- minutes, seconds);
- else
- snprintf(p, n, "%i:%02i", minutes,
- seconds);
+ OBJ(mpd_percent) {
+ snprintf(p, p_max_size, "%2.0f",
+ cur->mpd.progress * 100);
+ }
+ OBJ(mpd_bar) {
+ new_bar(p, obj->data.pair.a,
+ obj->data.pair.b,
+ (int) (cur->mpd.progress *
+ 255.0f));
+ }
+#endif
+#ifdef AUDACIOUS
+ OBJ(audacious_status) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
+ }
+ OBJ(audacious_song) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG]);
+ }
+ OBJ(audacious_song_length) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH]);
+ }
+ OBJ(audacious_song_length_seconds) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]);
+ }
+ OBJ(audacious_song_length_frames) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_LENGTH_FRAMES]);
+ }
+ OBJ(audacious_song_output_length) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH]);
+ }
+ OBJ(audacious_song_output_length_seconds) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]);
+ }
+ OBJ(audacious_song_output_length_frames) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_FRAMES]);
+ }
+ OBJ(audacious_song_bitrate) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_BITRATE]);
+ }
+ OBJ(audacious_song_frequency) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_SONG_FREQUENCY]);
+ }
+ OBJ(audacious_song_channels) {
+ snprintf(p, p_max_size, "%s", cur->audacious.items[AUDACIOUS_STATUS]);
+ }
+ OBJ(audacious_bar) {
+ double progress;
+ progress= atof(cur->audacious.items[AUDACIOUS_SONG_OUTPUT_LENGTH_SECONDS]) /
+ atof(cur->audacious.items[AUDACIOUS_SONG_LENGTH_SECONDS]);
+ new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
+
+ }
+#endif
+#ifdef BMPX
+ OBJ(bmpx_title) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.title);
+ }
+ OBJ(bmpx_artist) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.artist);
+ }
+ OBJ(bmpx_album) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.album);
+ }
+ OBJ(bmpx_uri) {
+ snprintf(p, p_max_size, "%s", cur->bmpx.uri);
+ }
+ OBJ(bmpx_track) {
+ snprintf(p, p_max_size, "%i", cur->bmpx.track);
+ }
+ OBJ(bmpx_bitrate) {
+ snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
+ }
+#endif
+#ifdef INFOPIPE
+ OBJ(infopipe_protocol) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PROTOCOL]);
+ }
+ OBJ(infopipe_version) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_VERSION]);
+ }
+ OBJ(infopipe_status) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_STATUS]);
+ }
+ OBJ(infopipe_playlist_tunes) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_TUNES]);
+ }
+ OBJ(infopipe_playlist_currtune) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_PLAYLIST_CURRTUNE]);
+ }
+ OBJ(infopipe_usec_position) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_POSITION]);
+ }
+ OBJ(infopipe_position) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_POSITION]);
+ }
+ OBJ(infopipe_usec_time) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_USEC_TIME]);
+ }
+ OBJ(infopipe_time) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TIME]);
+ }
+ OBJ(infopipe_bitrate) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_BITRATE]);
}
- OBJ(mpd_percent) {
- snprintf(p, n, "%2.0f",
- cur->mpd.progress * 100);
+ OBJ(infopipe_frequency) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FREQUENCY]);
}
- OBJ(mpd_bar) {
- new_bar(p, obj->data.pair.a,
- obj->data.pair.b,
- (int) (cur->mpd.progress *
- 255.0f));
+ OBJ(infopipe_channels) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_CHANNELS]);
+ }
+ OBJ(infopipe_title) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_TITLE]);
+ }
+ OBJ(infopipe_file) {
+ snprintf(p, p_max_size, "%s", cur->infopipe.items[INFOPIPE_FILE]);
+ }
+ OBJ(infopipe_bar) {
+ double progress;
+ progress= atof(cur->infopipe.items[INFOPIPE_USEC_POSITION]) /
+ atof(cur->infopipe.items[INFOPIPE_USEC_TIME]);
+ new_bar(p,obj->a,obj->b,(int)(progress*255.0f));
}
#endif
OBJ(top) {
}
-
- /*
- * I'm tired of everything being packed in
- * pee
- * poop
- */
-
-
OBJ(tail) {
if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
- snprintf(p, n, "%s", obj->data.tail.buffer);
+ snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
} else {
obj->data.tail.last_update = current_update_time;
FILE *fp;
int added = 0;
tailstring *head = NULL;
tailstring *headtmp = NULL;
+ tailstring *freetmp = NULL;
fp = fopen(obj->data.tail.logfile, "rt");
if (fp == NULL) {
ERR("tail logfile failed to open");
else {
obj->data.tail.readlines = 0;
- while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*4, fp) != NULL) {
+ while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL) {
if (added >= 30) {
freelasttail(head);
}
}
fclose(fp);
+ freetmp = head;
if (obj->data.tail.readlines > 0) {
for (i = 0;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
addtail(&headtmp, head->data);
head = head->next;
}
+ freetail(freetmp);
+ freetmp = headtmp;
strcpy(obj->data.tail.buffer, headtmp->data);
headtmp = headtmp->next;
for (i = 1;i < obj->data.tail.wantedlines + 1 && i < obj->data.tail.readlines; i++) {
if (headtmp) {
- strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 6 / obj->data.tail.wantedlines) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
+ strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
headtmp = headtmp->next;
}
}
if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
}
- snprintf(p, n, "%s", obj->data.tail.buffer);
+ snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
- freetail(headtmp);
- }
- else {
+ freetail(freetmp);
+ } else {
strcpy(obj->data.tail.buffer, "Logfile Empty");
- snprintf(p, n, "Logfile Empty");
- }
- freetail(head);
- }
- }
+ snprintf(p, p_max_size, "Logfile Empty");
+ } /* if readlines */
+ } /* fp == NULL */
+ } /* if cur_upd_time >= */
+
+ //parse_conky_vars(obj->data.tail.buffer, p, cur);
+
}
+ OBJ(head) {
+ if (current_update_time -obj->data.tail.last_update < obj->data.tail.interval) {
+ snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
+ } else {
+ obj->data.tail.last_update = current_update_time;
+ FILE *fp;
+ tailstring *head = NULL;
+ tailstring *headtmp = NULL;
+ tailstring *freetmp = NULL;
+ fp = fopen(obj->data.tail.logfile, "rt");
+ if (fp == NULL) {
+ ERR("head logfile failed to open");
+ } else {
+ obj->data.tail.readlines = 0;
+ while (fgets(obj->data.tail.buffer, TEXT_BUFFER_SIZE*20, fp) != NULL && obj->data.tail.readlines <= obj->data.tail.wantedlines) {
+ addtail(&head, obj->data.tail.buffer);
+ obj->data.tail.readlines++;
+ }
+ fclose(fp);
+ freetmp = head;
+ if (obj->data.tail.readlines > 0) {
+ while (head) {
+ addtail(&headtmp, head->data);
+ head = head->next;
+ }
+ freetail(freetmp);
+ freetmp = headtmp;
+ strcpy(obj->data.tail.buffer, headtmp->data);
+ headtmp = headtmp->next;
+ while (headtmp) {
+ strncat(obj->data.tail.buffer, headtmp->data, (TEXT_BUFFER_SIZE * 20) - strlen(obj->data.tail.buffer)); /* without strlen() at the end this becomes a possible */
+ headtmp = headtmp->next;
+ }
+ freetail(freetmp);
+ /* get rid of any ugly newlines at the end */
+ if (obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] == '\n') {
+ obj->data.tail.buffer[strlen(obj->data.tail.buffer)-1] = '\0';
+ }
+ snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
+ } else {
+ strcpy(obj->data.tail.buffer, "Logfile Empty");
+ snprintf(p, p_max_size, "Logfile Empty");
+ } /* if readlines > 0 */
+ } /* if fp == null */
+ } /* cur_upd_time >= */
+ //parse_conky_vars(obj->data.tail.buffer, p, cur);
+
+ }
+#ifdef TCP_PORT_MONITOR
+ OBJ(tcp_portmon)
+ {
+ /* grab a pointer to this port monitor */
+ tcp_port_monitor_t * p_monitor =
+ find_tcp_port_monitor( info.p_tcp_port_monitor_collection,
+ obj->data.tcp_port_monitor.port_range_begin,
+ obj->data.tcp_port_monitor.port_range_end );
+ if ( !p_monitor ) {
+ snprintf(p, p_max_size, "monitor not found");
+ break;
+ }
+ /* now grab the text of interest */
+ if ( peek_tcp_port_monitor( p_monitor,
+ obj->data.tcp_port_monitor.item,
+ obj->data.tcp_port_monitor.connection_index,
+ p, p_max_size ) != 0 )
+ {
+ snprintf(p, p_max_size, "monitor peek error");
+ break;
+ }
+ }
+#endif
break;
}
{
unsigned int a = strlen(p);
p += a;
- n -= a;
+ p_max_size -= a;
}
}
+}
+
+
+double current_update_time, last_update_time;
+
+static void generate_text()
+{
+ struct information *cur = &info;
+ char *p;
+
+ special_count = 0;
+
+ /* update info */
+
+ current_update_time = get_time();
+
+ update_stuff(cur);
+
+ /* add things to the buffer */
+
+ /* generate text */
+
+ p = text_buffer;
+
+ generate_text_internal(p, P_MAX_SIZE, text_objects, text_object_count, cur);
if (stuff_in_upper_case) {
char *p;
//free(p);
}
+
#ifdef X11
static void set_font()
{
#ifdef XFT
if (use_xft) {
- if (window.xftdraw != NULL)
+ if (window.xftdraw != NULL) {
XftDrawDestroy(window.xftdraw);
+ }
window.xftdraw = XftDrawCreate(display, window.drawable,
DefaultVisual(display,
screen),
#endif /* X11 */
}
+static inline int get_string_width_special(char *s)
+{
+ if (!s) {
+ return 0;
+ }
+#ifdef X11
+ char *p, *final;
+ p = strdup(s);
+ final = p;
+ int index = 1;
+ int width = 0;
+ unsigned int i;
+ while (*p) {
+ if (*p == SPECIAL_CHAR) {
+ /* shift everything over by 1 so that the special char doesn't mess up the size calculation */
+ for (i = 0; i < strlen(p); i++) {
+ *(p + i) = *(p + i + 1);
+ }
+ if (specials[special_index+index].type == GRAPH || specials[special_index+index].type == BAR) {
+ width += specials[special_index+index].width;
+ }
+ index++;
+ } else {
+ p++;
+ }
+ }
+ if (strlen(final) > 1) {
+ width += calc_text_width(final, strlen(final));
+ }
+ free(final);
+ return width;
+#else
+ return strlen(s);
+#endif /* X11 */
+}
+
int fontchange = 0;
#ifdef X11
width_of_s = get_string_width(s);
if (out_to_console) {
printf("%s\n", s);
+ fflush(stdout); /* output immediately, don't buffer */
}
/* daemon_run(s); the daemon can be called here, but we need to have a buffer in daemon_run() and we need to tell it when everything is ready to be sent */
- strcpy(tmpstring1, s);
+ memset(tmpstring1,0,TEXT_BUFFER_SIZE);
+ memset(tmpstring2,0,TEXT_BUFFER_SIZE);
+ strncpy(tmpstring1, s, TEXT_BUFFER_SIZE-1);
pos = 0;
added = 0;
char space[2];
for (i2 = 0;
i2 < (8 - (1 + pos) % 8) && added <= max;
i2++) {
- tmpstring2[pos + i2] = ' ';
+ /*
+ if ( pos + i2 > TEXT_BUFFER_SIZE-1 )
+ fprintf(stderr,"buffer overrun detected\n");
+ */
+ tmpstring2[ MIN(pos + i2, TEXT_BUFFER_SIZE-1) ] = ' '; /* guard against overrun */
added++;
}
pos += i2;
} else {
if (tmpstring1[i] != 9) {
- tmpstring2[pos] = tmpstring1[i];
+ /*
+ if ( pos > TEXT_BUFFER_SIZE-1 )
+ fprintf(stderr,"buffer overrun detected\n");
+ */
+ tmpstring2[ MIN(pos, TEXT_BUFFER_SIZE-1) ] = tmpstring1[i]; /* guard against overrun */
pos++;
}
}
}
+#ifdef X11
if (text_width == maximum_width) {
/* this means the text is probably pushing the limit, so we'll chop it */
while (cur_x + get_string_width(tmpstring2) - text_start_x > maximum_width && strlen(tmpstring2) > 0) {
tmpstring2[strlen(tmpstring2)-1] = '\0';
}
}
+#endif /* X11 */
s = tmpstring2;
#ifdef X11
#ifdef XFT
}
long redmask, greenmask, bluemask;
-short colour_depth = 0;
void set_up_gradient()
{
case BAR:
{
- if (cur_x > maximum_width - text_start_x && maximum_width > 0) {
+ if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
break;
}
int h =
specials[special_index].height;
int bar_usage =
specials[special_index].arg;
- int by =
- cur_y - (font_ascent() +
- h) / 2 - 1;
+ int by;
+
+#ifdef XFT
+ if (use_xft) {
+ by = cur_y - (font_ascent() + h) / 2 - 1;
+ } else
+#endif
+ {
+ by = cur_y - (font_ascent()/2) - 1;
+ }
+ if (h < (font_height())) {
+ by -= h / 2 - 1;
+ }
w = specials[special_index].width;
if (w == 0)
w = text_start_x +
break;
case GRAPH:
- {
- if (cur_x > maximum_width - text_start_x && maximum_width > 0) {
+ {
+ if (cur_x - text_start_x > maximum_width && maximum_width > 0) {
break;
}
int h =
int by;
#ifdef XFT
if (use_xft) {
- by = cur_y - (font_ascent() + h) / 2 + 1;
+ by = cur_y - (font_ascent() + h) / 2 - 1;
} else
#endif
{
- by = cur_y - (font_ascent()/2) + 1;
+ by = cur_y - (font_ascent()/2) - 1;
+ }
+ if (h < (font_height())) {
+ by -= h / 2 - 1;
}
w = specials[special_index].width;
if (w == 0)
w = text_start_x + text_width - cur_x - 1;
if (w < 0)
w = 0;
- XSetLineAttributes(display,
- window.gc, 1,
- LineSolid,
- CapButt,
- JoinMiter);
- XDrawRectangle(display,
- window.drawable,
- window.gc, cur_x,
- by, w, h);
+ if (draw_graph_borders) {
+ XSetLineAttributes(display, window.gc, 1, LineSolid, CapButt, JoinMiter);
+ XDrawRectangle(display,window.drawable, window.gc, cur_x, by, w, h);
+ }
XSetLineAttributes(display,
window.gc, 1,
LineSolid,
selected_font = specials[special_index].font_added;
cur_y += font_ascent();
#ifdef XFT
- if (!use_xft)
+ if (!use_xft || use_xdbe)
#endif
{
set_font();
case ALIGNR:
{
- int pos_x = text_width + gap_x - get_string_width(p) /*- border_margin*2 - 1*/;
- /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i border_margin %i border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(p), gap_x, specials[special_index].arg, border_margin, border_width);*/
+ int pos_x = text_start_x + text_width - get_string_width_special(s) /*+ border_margin*/;
+ /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i border_margin %i border_width %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width_special(s), gap_x, specials[special_index].arg, border_margin, border_width);*/
if (pos_x > specials[special_index].arg && pos_x > cur_x) {
- cur_x = pos_x - specials[special_index].arg;
+ cur_x = pos_x - specials[special_index].arg;
}
}
break;
case ALIGNC:
{
- int pos_x = (text_width)/2 - get_string_width(p)/2 - (cur_x - text_start_x);
- /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(p), gap_x, specials[special_index].arg);*/
+ int pos_x = (text_width)/2 - get_string_width_special(s)/2 - (cur_x - text_start_x);
+ /*int pos_x = text_start_x + text_width/2 - get_string_width_special(s)/2;*/
+ /*printf("pos_x %i text_start_x %i text_width %i cur_x %i get_string_width(p) %i gap_x %i specials[special_index].arg %i\n", pos_x, text_start_x, text_width, cur_x, get_string_width(s), gap_x, specials[special_index].arg);*/
if (pos_x >
specials[special_index].arg)
w = pos_x -
static void clear_text(int exposures)
{
#ifdef XDBE
- if (use_xdbe)
+ if (use_xdbe) {
return; /* The swap action is XdbeBackground, which clears */
+ } else
#endif
+ {
/* there is some extra space for borders and outlines */
XClearArea(display, window.drawable,
text_start_x - border_margin - 1,
text_width + border_margin * 2 + 2,
text_height + border_margin * 2 + 2,
exposures ? True : 0);
+ }
}
#endif /* X11 */
static void main_loop()
{
+#ifdef SIGNAL_BLOCKING
+ sigset_t newmask, oldmask;
+
+ sigemptyset(&newmask);
+ sigaddset(&newmask,SIGINT);
+ sigaddset(&newmask,SIGTERM);
+ sigaddset(&newmask,SIGUSR1);
+#endif
+
#ifdef X11
Region region = XCreateRegion();
#endif /* X11 */
info.looped = 0;
while (total_run_times == 0 || info.looped < total_run_times - 1) {
info.looped++;
+
+#ifdef SIGNAL_BLOCKING
+ /* block signals. we will inspect for pending signals later */
+ if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0)
+ CRIT_ERR("unable to sigprocmask()");
+#endif
+
#ifdef X11
XFlush(display);
}
#ifdef OWN_WINDOW
if (own_window) {
- set_transparent_background(window.window);
+ set_transparent_background(window.window);
}
#endif
}
break;
#ifdef OWN_WINDOW
- /*case ReparentNotify:
- set background to ParentRelative for all parents
+ case ReparentNotify:
+ /* set background to ParentRelative for all parents */
if (own_window) {
set_transparent_background(window.
window);
}
- break;*/
+ break;
case ConfigureNotify:
if (own_window) {
|| ev.xconfigure.y != 0)) {
fixed_pos = 1;
}*/
+ set_font();
}
break;
#endif
r.width = text_width + border_margin * 2;
r.height = text_height + border_margin * 2;
XUnionRectWithRegion(&r, region, region);
- }
+ }
#endif
XSetRegion(display, window.gc, region);
#ifdef XFT
- if (use_xft)
+ if (use_xft) {
XftDrawSetClip(window.xftdraw, region);
+ }
#endif
#endif /* X11 */
draw_stuff();
XDestroyRegion(region);
region = XCreateRegion();
}
+#endif /* X11 */
+#ifdef SIGNAL_BLOCKING
+ /* unblock signals of interest and let handler fly */
+ if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0)
+ CRIT_ERR("unable to sigprocmask()");
+#endif
+ switch(g_signal_pending) {
+ case SIGUSR1:
+ {
+ ERR("received SIGUSR1. reloading the config file.");
+ reload_config();
+ break;
+ }
+ case SIGINT:
+ case SIGTERM:
+ {
+ ERR("received SIGINT or SIGTERM to terminate. bye!");
+ clean_up();
+#ifdef X11
+ XDestroyRegion(region);
+ region = NULL;
#endif /* X11 */
-
+ return; /* return from main_loop */
+ /*break;*/
+ }
+ default:
+ {
+ /* Reaching here means someone set a signal( SIGXXXX, signal_handler )
+ * but didn't write any code to deal with it. if you don't want to
+ * handle a signal, don't set a handler on it in the first place. */
+ if (g_signal_pending)
+ ERR("ignoring signal (%d)", g_signal_pending);
+ break;
+ }
+ }
+ g_signal_pending=0;
+
}
+#ifdef X11
+ XDestroyRegion(region);
+ region = NULL;
+#endif /* X11 */
}
static void load_config_file(const char *);
-/* signal handler that reloads config file */
-static void reload_handler(int a)
+/* reload the config file */
+void reload_config(void)
{
- ERR("Conky: received signal %d, reloading config\n", a);
-
if (current_config) {
clear_fs_stats();
load_config_file(current_config);
#ifdef X11
load_fonts();
set_font();
+ XClearWindow(display, RootWindow(display, screen)); // clear the window first
+
#endif /* X11 */
+#ifdef TCP_PORT_MONITOR
+ destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
+ info.p_tcp_port_monitor_collection = NULL;
+#endif
extract_variable_text(text);
free(text);
text = NULL;
}
}
-static void clean_up()
+void clean_up(void)
{
#ifdef X11
#ifdef XDBE
- if (use_xdbe)
+ if (use_xdbe) {
XdbeDeallocateBackBufferName(display, window.back_buffer);
+ }
#endif
#ifdef OWN_WINDOW
if (own_window)
/* it is really pointless to free() memory at the end of program but ak|ra
* wants me to do this */
- free_text_objects();
+ free_text_objects(text_object_count, text_objects);
+ text_object_count = 0;
+ text_objects = NULL;
+
+#ifdef MLDONKEY
+ ml_cleanup();
+#endif /* MLDONKEY */
if (text != original_text)
free(text);
#ifdef SETI
free(seti_dir);
#endif
-}
-
-static void term_handler(int a)
-{
- a = a; /* to get rid of warning */
- clean_up();
- exit(0);
+#ifdef TCP_PORT_MONITOR
+ destroy_tcp_port_monitor_collection( info.p_tcp_port_monitor_collection );
+ info.p_tcp_port_monitor_collection = NULL;
+#endif
}
static int string_to_bool(const char *s)
default_fg_color = WhitePixel(display, screen);
default_bg_color = BlackPixel(display, screen);
default_out_color = BlackPixel(display, screen);
- draw_borders = 0;
draw_shades = 1;
+ draw_borders = 0;
+ draw_graph_borders = 1;
draw_outline = 0;
set_first_font("6x10");
gap_x = 5;
maximum_width = 0;
#ifdef OWN_WINDOW
own_window = 0;
+ strcpy(wm_class_name, "conky");
#endif
stippled_borders = 0;
border_margin = 3;
update_interval = 10.0;
stuff_in_upper_case = 0;
#ifdef MLDONKEY
- mlconfig.mldonkey_hostname = "127.0.0.1";
+ mlconfig.mldonkey_hostname = strdup("127.0.0.1");
mlconfig.mldonkey_port = 4001;
mlconfig.mldonkey_login = NULL;
mlconfig.mldonkey_password = NULL;
#endif
+
+#ifdef TCP_PORT_MONITOR
+ tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
+ tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
+#endif
}
static void load_config_file(const char *f)
FILE *fp;
set_default_configurations();
-
- fp = open_file(f, 0);
+ fp = fopen(f, "r");
if (!fp)
return;
#define CONF2(a) if (strcasecmp(name, a) == 0)
#define CONF(a) else CONF2(a)
#define CONF3(a,b) \
-else if (strcasecmp(name, a) == 0 || strcasecmp(name, a) == 0)
+else if (strcasecmp(name, a) == 0 || strcasecmp(name, b) == 0)
#ifdef X11
CONF("draw_borders") {
draw_borders = string_to_bool(value);
}
+ CONF("draw_graph_borders") {
+ draw_graph_borders = string_to_bool(value);
+ }
CONF("draw_shades") {
draw_shades = string_to_bool(value);
}
use_xft = string_to_bool(value);
}
CONF("font") {
- if (!use_xft) {
- if (value) {
- set_first_font(value);
- } else
- CONF_ERR;
- }
+ if (value) {
+ set_first_font(value);
+ } else
+ CONF_ERR;
}
CONF("xftalpha") {
if (value && font_count >= 0)
}
CONF("font") {
#endif
- if (value) {
- set_first_font(value);
- } else
- CONF_ERR;
+ if (use_xft) {
+ if (value) {
+ set_first_font(value);
+ } else
+ CONF_ERR;
+ }
}
CONF("gap_x") {
if (value)
CONF("own_window") {
own_window = string_to_bool(value);
}
+ CONF("wm_class_name") {
+ strncpy(wm_class_name, value, sizeof(wm_class_name)-1);
+ wm_class_name[sizeof(wm_class_name)-1] = 0;
+ }
CONF("own_window_transparent") {
set_transparent = string_to_bool(value);
}
fclose(fp);
return;
}
+#ifdef TCP_PORT_MONITOR
+ CONF("min_port_monitors")
+ {
+ if ( !value ||
+ (sscanf(value, "%d", &tcp_port_monitor_collection_args.min_port_monitors) != 1) ||
+ tcp_port_monitor_collection_args.min_port_monitors < 0 )
+ {
+ /* an error. use default, warn and continue. */
+ tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
+ CONF_ERR;
+ }
+ else if ( tcp_port_monitor_collection_args.min_port_monitors == 0 )
+ {
+ /* no error, just use default */
+ tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
+ }
+ /* else tcp_port_monitor_collection_args.min_port_monitors > 0 as per config */
+ }
+ CONF("min_port_monitor_connections")
+ {
+ if ( !value ||
+ (sscanf(value, "%d", &tcp_port_monitor_args.min_port_monitor_connections) != 1)
+ || tcp_port_monitor_args.min_port_monitor_connections < 0 )
+ {
+ /* an error. use default, warni and continue. */
+ tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
+ CONF_ERR;
+ }
+ else if ( tcp_port_monitor_args.min_port_monitor_connections == 0 )
+ {
+ /* no error, just use default */
+ tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
+ }
+ /* else tcp_port_monitor_args.min_port_monitor_connections > 0 as per config */
+ }
+#endif
else
ERR("%s: %d: no such configuration: '%s'", f, line, name);
int main(int argc, char **argv)
{
+ struct sigaction act, oact;
+
+ g_signal_pending=0;
+ memset(&info, 0, sizeof(info) );
+
+#ifdef TCP_PORT_MONITOR
+ tcp_port_monitor_collection_args.min_port_monitors = MIN_PORT_MONITORS_DEFAULT;
+ tcp_port_monitor_args.min_port_monitor_connections = MIN_PORT_MONITOR_CONNECTIONS_DEFAULT;
+#endif
+
/* handle command line parameters that don't change configs */
#ifdef X11
char *s;
}
if (!setlocale(LC_CTYPE, "")) {
ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
- return 1;
}
#endif /* X11 */
while (1) {
init_X11();
#endif /* X11 */
- tmpstring1 = (char *)
- malloc(TEXT_BUFFER_SIZE);
- tmpstring2 = (char *)
- malloc(TEXT_BUFFER_SIZE);
-
/* load current_config or CONFIG_FILE */
#ifdef CONFIG_FILE
#if defined OWN_WINDOW
init_window
(own_window,
+ wm_class_name,
text_width + border_margin * 2 + 1,
text_height + border_margin * 2 + 1,
- on_bottom, fixed_pos, set_transparent, background_colour);
+ on_bottom, fixed_pos, set_transparent, background_colour, info.uname_s.nodename);
#else
init_window
(own_window,
text_width + border_margin * 2 + 1,
text_height + border_margin * 2 + 1,
- on_bottom, set_transparent, background_colour);
+ on_bottom, set_transparent, background_colour, info.uname_s.nodename);
#endif
}
}
- /* set SIGUSR1, SIGINT and SIGTERM handlers */
- {
- struct
- sigaction sa;
-
- sa.sa_handler = reload_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
- if (sigaction(SIGUSR1, &sa, NULL) != 0)
- ERR("can't set signal handler for SIGUSR1: %s",
- strerror(errno));
+ /* Set signal handlers */
+ act.sa_handler = signal_handler;
+ sigemptyset(&act.sa_mask);
+ act.sa_flags = 0;
+#ifdef SA_RESTART
+ act.sa_flags |= SA_RESTART;
+#endif
- sa.sa_handler = term_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
- if (sigaction(SIGINT, &sa, NULL) != 0)
- ERR("can't set signal handler for SIGINT: %s",
- strerror(errno));
+ if ( sigaction(SIGINT,&act,&oact) < 0 ||
+ sigaction(SIGUSR1,&act,&oact) < 0 ||
+ sigaction(SIGTERM,&act,&oact) < 0 )
+ {
+ ERR("error setting signal handler: %s", strerror(errno) );
+ }
- sa.sa_handler = term_handler;
- sigemptyset(&sa.sa_mask);
- sa.sa_flags = SA_RESTART;
- if (sigaction(SIGTERM, &sa, NULL) != 0)
- ERR("can't set signal handler for SIGTERM: %s",
- strerror(errno));
+#ifdef AUDACIOUS
+ /* joinable thread for audacious activity */
+ pthread_attr_init(&info.audacious.thread_attr);
+ pthread_attr_setdetachstate(&info.audacious.thread_attr, PTHREAD_CREATE_JOINABLE);
+ /* init mutexex */
+ pthread_mutex_init(&info.audacious.item_mutex, NULL);
+ pthread_mutex_init(&info.audacious.runnable_mutex, NULL);
+ /* init runnable condition for worker thread */
+ pthread_mutex_lock(&info.audacious.runnable_mutex);
+ info.audacious.runnable=1;
+ pthread_mutex_unlock(&info.audacious.runnable_mutex);
+ if (pthread_create(&info.audacious.thread, &info.audacious.thread_attr, audacious_thread_func, NULL))
+ {
+ CRIT_ERR("unable to create audacious thread!");
+ }
+#endif
+#ifdef INFOPIPE
+ /* joinable thread for infopipe activity */
+ pthread_attr_init(&info.infopipe.thread_attr);
+ pthread_attr_setdetachstate(&info.infopipe.thread_attr, PTHREAD_CREATE_JOINABLE);
+ /* init mutexex */
+ pthread_mutex_init(&info.infopipe.item_mutex, NULL);
+ pthread_mutex_init(&info.infopipe.runnable_mutex, NULL);
+ /* init runnable condition for worker thread */
+ pthread_mutex_lock(&info.infopipe.runnable_mutex);
+ info.infopipe.runnable=1;
+ pthread_mutex_unlock(&info.infopipe.runnable_mutex);
+ if (pthread_create(&info.infopipe.thread, &info.infopipe.thread_attr, infopipe_thread_func, NULL))
+ {
+ CRIT_ERR("unable to create infopipe thread!");
}
+#endif
+
main_loop();
- free(tmpstring1);
- free(tmpstring2);
+
+#ifdef AUDACIOUS
+ /* signal audacious worker thread to terminate */
+ pthread_mutex_lock(&info.audacious.runnable_mutex);
+ info.audacious.runnable=0;
+ pthread_mutex_unlock(&info.audacious.runnable_mutex);
+ /* destroy thread attribute and wait for thread */
+ pthread_attr_destroy(&info.audacious.thread_attr);
+ if (pthread_join(info.audacious.thread, NULL))
+ {
+ ERR("error joining audacious thread");
+ }
+ /* destroy mutexes */
+ pthread_mutex_destroy(&info.audacious.item_mutex);
+ pthread_mutex_destroy(&info.audacious.runnable_mutex);
+#endif
+#ifdef INFOPIPE
+ /* signal infopipe worker thread to terminate */
+ pthread_mutex_lock(&info.infopipe.runnable_mutex);
+ info.infopipe.runnable=0;
+ pthread_mutex_unlock(&info.infopipe.runnable_mutex);
+ /* destroy thread attribute and wait for thread */
+ pthread_attr_destroy(&info.infopipe.thread_attr);
+ if (pthread_join(info.infopipe.thread, NULL))
+ {
+ ERR("error joining infopipe thread");
+ }
+ /* destroy mutexes */
+ pthread_mutex_destroy(&info.infopipe.item_mutex);
+ pthread_mutex_destroy(&info.infopipe.runnable_mutex);
+#endif
+
return 0;
}
+
+void signal_handler(int sig)
+{
+ /* signal handler is light as a feather, as it should be.
+ * we will poll g_signal_pending with each loop of conky
+ * and do any signal processing there, NOT here. pkovacs. */
+ g_signal_pending=sig;
+}