1 /* Conky, a system monitor, based on torsmo
3 * Any original torsmo code is licensed under the BSD license
5 * All code written since the fork of torsmo is licensed under the GPL
7 * Please see COPYING for details
9 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
10 * Copyright (c) 2005-2008 Brenden Matthews, Philip Kovacs, et. al.
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
44 #include <X11/Xutil.h>
46 #include <X11/extensions/Xdamage.h>
52 #include <sys/types.h>
54 #include <netinet/in.h>
65 #include "temphelper.h"
68 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
71 #define MAIL_FILE "$MAIL"
72 #define MAX_IF_BLOCK_DEPTH 5
73 #define MAX_TAIL_LINES 100
75 //#define SIGNAL_BLOCKING
76 #undef SIGNAL_BLOCKING
79 int global_debug_level = 0;
81 static void print_version(void) __attribute__((noreturn));
83 static void print_version(void)
85 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
87 printf("\nCompiled in features:\n\n"
88 "System config file: "SYSTEM_CONFIG_FILE"\n\n"
92 " * Xdamage extension\n"
93 # endif /* HAVE_XDAMAGE */
95 " * Xdbe extension (double buffer)\n"
96 # endif /* HAVE_XDBE */
101 "\n Music detection:\n"
104 #endif /* AUDACIOUS */
117 "\n General features:\n"
124 #ifdef TCP_PORT_MONITOR
126 #endif /* TCP_PORT_MONITOR */
135 #endif /* HAVE_IWLIB */
147 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
154 static int text_start_x, text_start_y; /* text start position in window */
155 static int text_width, text_height;
173 char name[DEFAULT_TEXT_BUFFER_SIZE];
183 static int selected_font = 0;
184 static int font_count = -1;
185 struct font_list *fonts = NULL;
189 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
190 fonts[selected_font].xftfont->descent) \
191 : (fonts[selected_font].font->max_bounds.ascent + \
192 fonts[selected_font].font->max_bounds.descent))
193 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
194 : fonts[selected_font].font->max_bounds.ascent)
195 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
196 : fonts[selected_font].font->max_bounds.descent)
200 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
201 fonts[selected_font].font->max_bounds.descent)
202 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
203 #define font_descent() fonts[selected_font].font->max_bounds.descent
207 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
209 static void set_font(void);
211 int addfont(const char *data_in)
213 if (font_count > MAX_FONTS) {
214 CRIT_ERR("you don't need that many fonts, sorry.");
217 if (font_count == 0) {
221 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
225 memset(fonts, 0, sizeof(struct font_list));
227 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
228 memset(&fonts[font_count], 0, sizeof(struct font_list));
230 CRIT_ERR("realloc in addfont");
232 // must account for null terminator
233 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
234 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
236 fonts[font_count].font_alpha = 0xffff;
239 CRIT_ERR("Oops...looks like something overflowed in addfont().");
244 void set_first_font(const char *data_in)
246 if (font_count < 0) {
247 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
251 memset(fonts, 0, sizeof(struct font_list));
254 if (strlen(data_in) > 1) {
255 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
257 fonts[0].font_alpha = 0xffff;
262 void free_fonts(void)
266 for (i = 0; i <= font_count; i++) {
269 XftFontClose(display, fonts[i].xftfont);
270 fonts[i].xftfont = 0;
274 XFreeFont(display, fonts[i].font);
284 static void load_fonts(void)
288 for (i = 0; i <= font_count; i++) {
291 if (use_xft && fonts[i].xftfont) {
293 } else if (use_xft) {
294 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
295 XftFontClose(display, fonts[i].xftfont);
297 fonts[i].xftfont = XftFontOpenName(display, screen,
299 if (fonts[i].xftfont != NULL) {
303 ERR("can't load Xft font '%s'", fonts[i].name);
304 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
305 "courier-12")) != NULL) {
309 ERR("can't load Xft font '%s'", "courier-12");
311 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
312 CRIT_ERR("can't load font '%s'", "fixed");
319 /* load normal font */
320 /* if (fonts[i].font != NULL) {
321 XFreeFont(display, fonts[i].font);
324 if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
325 ERR("can't load font '%s'", fonts[i].name);
326 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
327 CRIT_ERR("can't load font '%s'", "fixed");
328 printf("loaded fixed?\n");
336 /* default config file */
337 static char *current_config;
339 /* set to 1 if you want all text to be in uppercase */
340 static unsigned int stuff_in_upper_case;
342 /* Run how many times? */
343 static unsigned long total_run_times;
346 static int fork_to_background;
348 static int cpu_avg_samples, net_avg_samples;
352 static int show_graph_scale;
353 static int show_graph_range;
355 /* Position on the screen */
356 static int text_alignment;
357 static int gap_x, gap_y;
360 static int draw_borders;
361 static int draw_graph_borders;
362 static int stippled_borders;
364 static int draw_shades, draw_outline;
366 static int border_margin, border_width;
368 static long default_fg_color, default_bg_color, default_out_color;
370 /* create own window or draw stuff to root? */
371 static int set_transparent = 0;
374 static int own_window = 0;
375 static int background_colour = 0;
377 /* fixed size/pos is set if wm/user changes them */
378 static int fixed_size = 0, fixed_pos = 0;
381 static int minimum_width, minimum_height;
382 static int maximum_width;
387 static int sensor_device;
390 static long color0, color1, color2, color3, color4, color5, color6, color7,
393 static char *template[10];
395 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
396 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
398 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
399 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
401 /* maximum size of individual text buffers, ie $exec buffer size */
402 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
405 #define CODEPAGE_LENGTH 20
407 long iconv_count = 0;
408 char iconv_converting;
409 static iconv_t **iconv_cd = 0;
411 int register_iconv(iconv_t *new_iconv)
413 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
415 CRIT_ERR("Out of memory");
417 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
418 if (!iconv_cd[iconv_count]) {
419 CRIT_ERR("Out of memory");
421 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
426 void free_iconv(void)
431 for (i = 0; i < iconv_count; i++) {
433 iconv_close(*iconv_cd[i]);
447 /* no buffers in used memory? */
450 /* pad percentages to decimals? */
451 static int pad_percents = 0;
453 #ifdef TCP_PORT_MONITOR
454 tcp_port_monitor_args_t tcp_port_monitor_args;
457 static char *global_text = 0;
458 long global_text_lines;
460 static int total_updates;
463 static int blockdepth = 0;
464 static int if_jumped = 0;
465 static int blockstart[MAX_IF_BLOCK_DEPTH];
467 int check_contains(char *f, char *s)
470 FILE *where = fopen(f, "r");
473 char buf1[256], buf2[256];
475 while (fgets(buf1, 256, where)) {
476 sscanf(buf1, "%255s", buf2);
477 if (strstr(buf2, s)) {
484 ERR("Could not open the file");
490 static inline int calc_text_width(const char *s, int l)
497 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
498 (const FcChar8 *) s, l, &gi);
500 XftTextExtents8(display, fonts[selected_font].xftfont,
501 (const FcChar8 *) s, l, &gi);
507 return XTextWidth(fonts[selected_font].font, s, l);
512 /* formatted text to render on screen, generated in generate_text(),
513 * drawn in draw_stuff() */
515 static char *text_buffer;
517 /* special stuff in text_buffer */
519 #define SPECIAL_CHAR '\x01'
548 unsigned long first_colour; // for graph gradient
549 unsigned long last_colour;
553 /* create specials array on heap instead of stack with introduction of
555 static struct special_t *specials = NULL;
557 static unsigned int special_count;
560 static unsigned int special_index; /* used when drawing */
563 /* why 256? cause an array of more then 256 doubles seems excessive,
564 * and who needs that kind of precision anyway? */
565 #define MAX_GRAPH_DEPTH 256
567 static struct special_t *new_special(char *buf, enum special_types t)
569 if (special_count >= max_specials) {
570 CRIT_ERR("too many special things in text");
573 buf[0] = SPECIAL_CHAR;
575 specials[special_count].type = t;
576 return &specials[special_count++];
579 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
583 unsigned int count = 0;
584 static char buf[BUFSZ];
585 long orig_pos = ftell(fp);
587 long buf_size = BUFSZ;
588 char *cur_found = NULL;
590 while (count < step) {
591 if (cur_found == NULL) {
592 buf_size = fread(buf, 1, buf_size, fp);
595 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
596 if (cur_found != NULL) {
597 buf_pos = cur_found - buf + 1;
606 ret = ftell(fp) - buf_size + buf_pos - 1;
608 fseek(fp, orig_pos, SEEK_SET);
613 void *memrchr(const void *buffer, char c, size_t n)
615 const unsigned char *p = buffer;
617 for (p += n; n; n--) {
626 long rev_fcharfind(FILE *fp, char val, unsigned int step)
630 unsigned int count = 0;
631 static char buf[BUFSZ];
632 long orig_pos = ftell(fp);
634 long file_pos = orig_pos;
635 long buf_size = BUFSZ;
638 while (count < step) {
640 if (file_pos > BUFSZ) {
641 fseek(fp, file_pos - BUFSZ, SEEK_SET);
644 fseek(fp, 0, SEEK_SET);
646 file_pos = ftell(fp);
647 buf_pos = fread(buf, 1, buf_size, fp);
649 cur_found = memrchr(buf, val, (size_t) buf_pos);
650 if (cur_found != NULL) {
651 buf_pos = cur_found - buf;
660 fseek(fp, orig_pos, SEEK_SET);
662 ret = file_pos + buf_pos;
667 static void new_bar(char *buf, int w, int h, int usage)
669 struct special_t *s = new_special(buf, BAR);
671 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
676 static const char *scan_bar(const char *args, int *w, int *h)
678 /* zero width means all space that is available */
681 /* bar's argument is either height or height,width */
685 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
686 sscanf(args, "%d %n", h, &n);
694 static char *scan_font(const char *args)
697 return strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
704 static void new_font(char *buf, char *args)
707 struct special_t *s = new_special(buf, FONT);
709 if (s->font_added > font_count || !s->font_added || (strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE) != EQUAL) ) {
710 int tmp = selected_font;
712 selected_font = s->font_added = addfont(args);
717 struct special_t *s = new_special(buf, FONT);
718 int tmp = selected_font;
720 selected_font = s->font_added = 0;
725 void graph_append(struct special_t *graph, double f, char showaslog)
735 if (!graph->scaled && f > graph->graph_scale) {
736 f = graph->graph_scale;
739 /* Already happens in new_graph
741 graph->graph_scale = 1;
744 graph->graph[0] = f; /* add new data */
745 /* shift all the data by 1 */
746 for (i = graph->graph_width - 1; i > 0; i--) {
747 graph->graph[i] = graph->graph[i - 1];
748 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
749 /* check if we need to update the scale */
750 graph->graph_scale = graph->graph[i];
755 short colour_depth = 0;
756 void set_up_gradient(void);
758 /* precalculated: 31/255, and 63/255 */
759 #define CONST_8_TO_5_BITS 0.12156862745098
760 #define CONST_8_TO_6_BITS 0.247058823529412
762 /* adjust color values depending on color depth */
763 static unsigned int adjust_colors(unsigned int color)
767 if (colour_depth == 0) {
770 if (colour_depth == 16) {
771 r = (color & 0xff0000) >> 16;
772 g = (color & 0xff00) >> 8;
774 color = (int) (r * CONST_8_TO_5_BITS) << 11;
775 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
776 color |= (int) (b * CONST_8_TO_5_BITS);
781 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
782 unsigned int second_colour, double i, int scale, int append, char showaslog)
784 struct special_t *s = new_special(buf, GRAPH);
787 if (s->graph == NULL) {
788 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
789 // subtract 2 for the box
790 s->graph_width = s->width /* - 2 */;
792 s->graph_width = MAX_GRAPH_DEPTH - 2;
794 s->graph = malloc(s->graph_width * sizeof(double));
795 memset(s->graph, 0, s->graph_width * sizeof(double));
796 s->graph_scale = 100;
799 s->first_colour = adjust_colors(first_colour);
800 s->last_colour = adjust_colors(second_colour);
803 s->graph_scale = scale;
811 s->graph_width = s->width - 2; // subtract 2 for rectangle around
815 s->graph_scale = log10(s->graph_scale + 1);
819 graph_append(s, i, showaslog);
823 //don't use spaces in LOGGRAPH or NORMGRAPH if you change them
824 #define LOGGRAPH "log"
825 #define NORMGRAPH "normal"
827 static char *scan_graph(const char *args, int *w, int *h,
828 unsigned int *first_colour, unsigned int *last_colour,
829 unsigned int *scale, char *showaslog)
831 const char *nographtype;
835 /* zero width means all space that is available */
842 //set showaslog and place the rest of the args in nographtype
843 if(strcasecmp(args, LOGGRAPH) == EQUAL) {
846 }else if(strcasecmp(args, NORMGRAPH) == EQUAL) {
849 }else if(strncasecmp(args, LOGGRAPH" ", strlen(LOGGRAPH) + 1 ) == EQUAL) {
851 nographtype = &args[strlen(LOGGRAPH) + 1];
852 }else if(strncasecmp(args, NORMGRAPH" ", strlen(NORMGRAPH) + 1 ) == EQUAL) {
854 nographtype = &args[strlen(NORMGRAPH) + 1];
859 //check the rest of the args
860 if (sscanf(nographtype, "%d,%d %x %x %u", h, w, first_colour, last_colour, scale) == 5) {
864 if (sscanf(nographtype, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
867 if (sscanf(nographtype, "%63s %d,%d %x %x %u", buf, h, w, first_colour, last_colour, scale) == 6) {
868 return strndup(buf, text_buffer_size);
871 if (sscanf(nographtype, "%63s %d,%d %x %x", buf, h, w, first_colour, last_colour) == 5) {
872 return strndup(buf, text_buffer_size);
877 if (sscanf(nographtype, "%x %x %u", first_colour, last_colour, scale) == 3) {
881 if (sscanf(nographtype, "%x %x", first_colour, last_colour) == 2) {
884 if (sscanf(nographtype, "%63s %x %x %u", buf, first_colour, last_colour, scale) == 4) {
885 return strndup(buf, text_buffer_size);
888 if (sscanf(nographtype, "%63s %x %x", buf, first_colour, last_colour) == 3) {
889 return strndup(buf, text_buffer_size);
894 if (sscanf(nographtype, "%d,%d %u", h, w, scale) == 3) {
898 if (sscanf(nographtype, "%d,%d", h, w) == 2) {
901 if (sscanf(nographtype, "%63s %d,%d %u", buf, h, w, scale) < 4) {
903 //TODO: check the return value and throw an error?
904 sscanf(nographtype, "%63s %d,%d", buf, h, w);
907 return strndup(buf, text_buffer_size);
910 if (buf[0] == '\0') {
913 return strndup(buf, text_buffer_size);
917 static inline void new_hr(char *buf, int a)
919 new_special(buf, HORIZONTAL_LINE)->height = a;
922 static inline void new_stippled_hr(char *buf, int a, int b)
924 struct special_t *s = new_special(buf, STIPPLED_HR);
930 static inline void new_fg(char *buf, long c)
932 new_special(buf, FG)->arg = c;
935 static inline void new_bg(char *buf, long c)
937 new_special(buf, BG)->arg = c;
940 static inline void new_outline(char *buf, long c)
942 new_special(buf, OUTLINE)->arg = c;
945 static inline void new_offset(char *buf, long c)
947 new_special(buf, OFFSET)->arg = c;
950 static inline void new_voffset(char *buf, long c)
952 new_special(buf, VOFFSET)->arg = c;
955 static inline void new_alignr(char *buf, long c)
957 new_special(buf, ALIGNR)->arg = c;
960 // A postive offset pushes the text further left
961 static inline void new_alignc(char *buf, long c)
963 new_special(buf, ALIGNC)->arg = c;
966 static inline void new_goto(char *buf, long c)
968 new_special(buf, GOTO)->arg = c;
971 static inline void new_tab(char *buf, int a, int b)
973 struct special_t *s = new_special(buf, TAB);
979 /* quite boring functions */
981 static inline void for_each_line(char *b, void f(char *))
985 for (ps = b, pe = b; *pe; pe++) {
999 static void convert_escapes(char *buf)
1001 char *p = buf, *s = buf;
1008 } else if (*s == '\\') {
1019 /* Prints anything normally printed with snprintf according to the current value
1020 * of use_spacer. Actually slightly more flexible than snprintf, as you can
1021 * safely specify the destination buffer as one of your inputs. */
1022 static int spaced_print(char *, int, const char *, int, const char *, ...)
1023 __attribute__((format(printf, 3, 6)));
1025 static int spaced_print(char *buf, int size, const char *format, int width,
1026 const char *func_name, ...) {
1034 tempbuf = malloc(size * sizeof(char));
1036 // Passes the varargs along to vsnprintf
1037 va_start(argp, func_name);
1038 vsnprintf(tempbuf, size, format, argp);
1041 switch (use_spacer) {
1043 len = snprintf(buf, size, "%s", tempbuf);
1046 len = snprintf(buf, size, "%*s", width - 1, tempbuf);
1049 len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
1052 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
1061 /* converts from bytes to human readable format (k, M, G, T) */
1062 static void human_readable(long long num, char *buf, int size, const char *func_name)
1064 const char **suffix = suffixes;
1067 static const int WIDTH = 10, SHORT_WIDTH = 8;
1069 if (num < 1024LL && num > -1024LL) {
1071 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1074 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1079 while ((num / 1024 >= 1000LL || num / 1024 <= -1024LL) && **(suffix + 2)) {
1085 fnum = num / 1024.0;
1090 if (precision < 0) {
1094 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1095 precision, fnum, **suffix);
1097 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1100 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1105 enum text_object_type {
1107 #if defined(__linux__)
1109 #endif /* __linux__ */
1118 OBJ_battery_percent,
1120 #endif /* !__OpenBSD__ */
1135 OBJ_conky_build_date,
1136 OBJ_conky_build_arch,
1146 OBJ_diskiograph_read,
1147 OBJ_diskiograph_write,
1183 #if defined(__linux__)
1189 OBJ_i8k_left_fan_status,
1190 OBJ_i8k_right_fan_status,
1191 OBJ_i8k_left_fan_rpm,
1192 OBJ_i8k_right_fan_rpm,
1194 OBJ_i8k_buttons_status,
1210 OBJ_wireless_bitrate,
1212 OBJ_wireless_link_qual,
1213 OBJ_wireless_link_qual_max,
1214 OBJ_wireless_link_qual_perc,
1215 OBJ_wireless_link_bar,
1216 #endif /* __linux__ */
1257 OBJ_running_processes,
1266 OBJ_temp1, /* i2c is used instead in these */
1290 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1291 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1293 OBJ_apm_battery_time,
1294 OBJ_apm_battery_life,
1295 #endif /* __FreeBSD__ __OpenBSD__ */
1297 OBJ_obsd_sensors_temp,
1298 OBJ_obsd_sensors_fan,
1299 OBJ_obsd_sensors_volt,
1302 #endif /* __OpenBSD__ */
1338 OBJ_music_player_interval,
1358 OBJ_xmms2_timesplayed,
1359 OBJ_if_xmms2_connected,
1362 OBJ_audacious_status,
1363 OBJ_audacious_title,
1364 OBJ_audacious_length,
1365 OBJ_audacious_length_seconds,
1366 OBJ_audacious_position,
1367 OBJ_audacious_position_seconds,
1368 OBJ_audacious_bitrate,
1369 OBJ_audacious_frequency,
1370 OBJ_audacious_channels,
1371 OBJ_audacious_filename,
1372 OBJ_audacious_playlist_length,
1373 OBJ_audacious_playlist_position,
1374 OBJ_audacious_main_volume,
1391 #ifdef TCP_PORT_MONITOR
1406 OBJ_smapi_bat_power,
1407 OBJ_if_smapi_bat_installed,
1411 OBJ_entropy_poolsize,
1415 struct text_object {
1417 char *s; /* some string */
1418 int i; /* some integer */
1419 long l; /* some other integer */
1420 unsigned int sensor;
1421 struct net_stat *net;
1423 struct diskio_stat *diskio;
1424 unsigned char loadavg[3];
1425 unsigned int cpu_index;
1426 struct mail_s *mail;
1434 char *tz; /* timezone variable */
1435 char *fmt; /* time display formatting */
1473 /* If not -1, a file descriptor to read from when
1474 * logfile is a FIFO. */
1491 timed_thread *p_timed_thread;
1497 #ifdef TCP_PORT_MONITOR
1499 /* starting port to monitor */
1500 in_port_t port_range_begin;
1501 /* ending port to monitor */
1502 in_port_t port_range_end;
1503 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1505 /* 0 to n-1 connections. */
1506 int connection_index;
1540 struct local_mail_s local_mail;
1542 struct nvidia_s nvidia;
1549 unsigned int c, d, e;
1555 struct text_object_list {
1556 unsigned int text_object_count;
1557 struct text_object *text_objects;
1560 static struct text_object_list *global_text_object_list;
1562 static void generate_text_internal(char *p, int p_max_size,
1563 struct text_object_list *text_object_list,
1564 struct information *cur);
1566 #define MAXDATASIZE 1000
1570 struct mail_s *parse_mail_args(char type, const char *arg)
1572 struct mail_s *mail;
1575 mail = malloc(sizeof(struct mail_s));
1576 memset(mail, 0, sizeof(struct mail_s));
1578 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1581 ERR("Scanning IMAP args failed");
1582 } else if (type == IMAP) {
1583 ERR("Scanning POP3 args failed");
1586 // see if password needs prompting
1587 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1588 int fp = fileno(stdin);
1589 struct termios term;
1591 tcgetattr(fp, &term);
1592 term.c_lflag &= ~ECHO;
1593 tcsetattr(fp, TCSANOW, &term);
1594 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1595 scanf("%128s", mail->pass);
1597 term.c_lflag |= ECHO;
1598 tcsetattr(fp, TCSANOW, &term);
1600 // now we check for optional args
1601 tmp = strstr(arg, "-r ");
1604 sscanf(tmp, "%u", &mail->retries);
1606 mail->retries = 5; // 5 retries after failure
1608 tmp = strstr(arg, "-i ");
1611 sscanf(tmp, "%f", &mail->interval);
1613 mail->interval = 300; // 5 minutes
1615 tmp = strstr(arg, "-p ");
1618 sscanf(tmp, "%lu", &mail->port);
1621 mail->port = 110; // default pop3 port
1622 } else if (type == IMAP) {
1623 mail->port = 143; // default imap port
1627 tmp = strstr(arg, "-f ");
1630 sscanf(tmp, "%s", mail->folder);
1632 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1635 tmp = strstr(arg, "-e ");
1640 if (tmp[0] == '\'') {
1641 len = strstr(tmp + 1, "'") - tmp - 1;
1646 strncpy(mail->command, tmp + 1, len);
1648 mail->command[0] = '\0';
1650 mail->p_timed_thread = NULL;
1654 int imap_command(int sockfd, const char *command, char *response, const char *verify)
1656 struct timeval timeout;
1658 int res, numbytes = 0;
1659 if (send(sockfd, command, strlen(command), 0) == -1) {
1663 timeout.tv_sec = 60; // 60 second timeout i guess
1664 timeout.tv_usec = 0;
1666 FD_SET(sockfd, &fdset);
1667 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1669 if ((numbytes = recv(sockfd, response, MAXDATASIZE - 1, 0)) == -1) {
1674 DBGP2("imap_command() received: %s", response);
1675 response[numbytes] = '\0';
1676 if (strstr(response, verify) == NULL) {
1682 int imap_check_status(char *recvbuf, struct mail_s *mail)
1685 reply = strstr(recvbuf, " (MESSAGES ");
1686 if (!reply || strlen(reply) < 2) {
1690 *strchr(reply, ')') = '\0';
1691 if (reply == NULL) {
1692 ERR("Error parsing IMAP response: %s", recvbuf);
1695 timed_thread_lock(mail->p_timed_thread);
1696 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1698 timed_thread_unlock(mail->p_timed_thread);
1703 void imap_unseen_command(struct mail_s *mail, unsigned long old_unseen, unsigned long old_messages)
1705 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1706 || (mail->messages > old_messages && mail->unseen > 0))) {
1708 if (system(mail->command) == -1) {
1714 void *imap_thread(void *arg)
1716 int sockfd, numbytes;
1717 char recvbuf[MAXDATASIZE];
1718 char sendbuf[MAXDATASIZE];
1719 unsigned int fail = 0;
1720 unsigned long old_unseen = ULONG_MAX;
1721 unsigned long old_messages = ULONG_MAX;
1722 struct stat stat_buf;
1723 struct hostent he, *he_res = 0;
1725 char hostbuff[2048];
1726 struct sockaddr_in their_addr; // connector's address information
1727 struct mail_s *mail = (struct mail_s *)arg;
1729 int threadfd = timed_thread_readfd(mail->p_timed_thread);
1731 #ifdef HAVE_GETHOSTBYNAME_R
1732 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1733 ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
1736 #else /* HAVE_GETHOSTBYNAME_R */
1737 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1738 herror("gethostbyname");
1741 #endif /* HAVE_GETHOSTBYNAME_R */
1742 while (fail < mail->retries) {
1743 struct timeval timeout;
1748 ERR("Trying IMAP connection again for %s@%s (try %u/%u)",
1749 mail->user, mail->host, fail + 1, mail->retries);
1752 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1759 their_addr.sin_family = AF_INET;
1760 // short, network byte order
1761 their_addr.sin_port = htons(mail->port);
1762 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1763 // zero the rest of the struct
1764 memset(&(their_addr.sin_zero), '\0', 8);
1766 if (connect(sockfd, (struct sockaddr *) &their_addr,
1767 sizeof(struct sockaddr)) == -1) {
1773 timeout.tv_sec = 60; // 60 second timeout i guess
1774 timeout.tv_usec = 0;
1776 FD_SET(sockfd, &fdset);
1777 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1779 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1785 ERR("IMAP connection failed: timeout");
1789 recvbuf[numbytes] = '\0';
1790 DBGP2("imap_thread() received: %s", recvbuf);
1791 if (strstr(recvbuf, "* OK") != recvbuf) {
1792 ERR("IMAP connection failed, probably not an IMAP server");
1796 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1797 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1798 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1799 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1800 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1801 if (imap_command(sockfd, sendbuf, recvbuf, "a1 OK")) {
1805 if (strstr(recvbuf, " IDLE ") != NULL) {
1809 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1810 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1811 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1812 MAXDATASIZE - strlen(sendbuf) - 1);
1813 if (imap_command(sockfd, sendbuf, recvbuf, "a2 OK")) {
1818 if (imap_check_status(recvbuf, mail)) {
1822 imap_unseen_command(mail, old_unseen, old_messages);
1824 old_unseen = mail->unseen;
1825 old_messages = mail->messages;
1828 strncpy(sendbuf, "a4 SELECT ", MAXDATASIZE);
1829 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1830 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1831 if (imap_command(sockfd, sendbuf, recvbuf, "a4 OK")) {
1836 strncpy(sendbuf, "a5 IDLE\r\n", MAXDATASIZE);
1837 if (imap_command(sockfd, sendbuf, recvbuf, "+ idling")) {
1845 * RFC 2177 says we have to re-idle every 29 minutes.
1846 * We'll do it every 20 minutes to be safe.
1848 timeout.tv_sec = 1200;
1849 timeout.tv_usec = 0;
1851 FD_SET(sockfd, &fdset);
1852 FD_SET(threadfd, &fdset);
1853 res = select(MAX(sockfd + 1, threadfd + 1), &fdset, NULL, NULL, NULL);
1854 if (timed_thread_test(mail->p_timed_thread, 1) || (res == -1 && errno == EINTR) || FD_ISSET(threadfd, &fdset)) {
1855 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1856 /* if a valid socket, close it */
1859 timed_thread_exit(mail->p_timed_thread);
1860 } else if (res > 0) {
1861 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1862 perror("recv idling");
1869 recvbuf[numbytes] = '\0';
1870 DBGP2("imap_thread() received: %s", recvbuf);
1871 if (strlen(recvbuf) > 2) {
1872 unsigned long messages, recent;
1873 char *buf = recvbuf;
1874 buf = strstr(buf, "EXISTS");
1875 while (buf && strlen(buf) > 1 && strstr(buf + 1, "EXISTS")) {
1876 buf = strstr(buf + 1, "EXISTS");
1879 // back up until we reach '*'
1880 while (buf >= recvbuf && buf[0] != '*') {
1883 if (sscanf(buf, "* %lu EXISTS\r\n", &messages) == 1) {
1884 timed_thread_lock(mail->p_timed_thread);
1885 mail->messages = messages;
1886 timed_thread_unlock(mail->p_timed_thread);
1890 buf = strstr(buf, "RECENT");
1891 while (buf && strlen(buf) > 1 && strstr(buf + 1, "RECENT")) {
1892 buf = strstr(buf + 1, "RECENT");
1895 // back up until we reach '*'
1896 while (buf >= recvbuf && buf[0] != '*') {
1899 if (sscanf(buf, "* %lu RECENT\r\n", &recent) != 1) {
1904 * check if we got a FETCH from server, recent was
1905 * something other than 0, or we had a timeout
1908 if (recent > 0 || (buf && strstr(buf, " FETCH ")) || timeout.tv_sec == 0) {
1909 // re-check messages and unseen
1910 if (imap_command(sockfd, "DONE\r\n", recvbuf, "a5 OK")) {
1914 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1915 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1916 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1917 MAXDATASIZE - strlen(sendbuf) - 1);
1918 if (imap_command(sockfd, sendbuf, recvbuf, "a2 OK")) {
1922 if (imap_check_status(recvbuf, mail)) {
1926 strncpy(sendbuf, "a5 IDLE\r\n", MAXDATASIZE);
1927 if (imap_command(sockfd, sendbuf, recvbuf, "+ idling")) {
1933 * check if we got a BYE from server
1936 if (buf && strstr(buf, "* BYE")) {
1937 // need to re-connect
1941 imap_unseen_command(mail, old_unseen, old_messages);
1943 old_unseen = mail->unseen;
1944 old_messages = mail->messages;
1947 strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
1948 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1953 timeout.tv_sec = 60; // 60 second timeout i guess
1954 timeout.tv_usec = 0;
1956 FD_SET(sockfd, &fdset);
1957 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1959 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1965 recvbuf[numbytes] = '\0';
1966 DBGP2("imap_thread() received: %s", recvbuf);
1967 if (strstr(recvbuf, "a3 OK") == NULL) {
1968 ERR("IMAP logout failed: %s", recvbuf);
1974 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1975 /* if a valid socket, close it */
1978 if (timed_thread_test(mail->p_timed_thread, 0)) {
1979 timed_thread_exit(mail->p_timed_thread);
1987 int pop3_command(int sockfd, const char *command, char *response, const char *verify)
1989 struct timeval timeout;
1991 int res, numbytes = 0;
1992 if (send(sockfd, command, strlen(command), 0) == -1) {
1996 timeout.tv_sec = 60; // 60 second timeout i guess
1997 timeout.tv_usec = 0;
1999 FD_SET(sockfd, &fdset);
2000 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
2002 if ((numbytes = recv(sockfd, response, MAXDATASIZE - 1, 0)) == -1) {
2007 DBGP2("pop3_command() received: %s", response);
2008 response[numbytes] = '\0';
2009 if (strstr(response, verify) == NULL) {
2015 void *pop3_thread(void *arg)
2017 int sockfd, numbytes;
2018 char recvbuf[MAXDATASIZE];
2019 char sendbuf[MAXDATASIZE];
2021 unsigned int fail = 0;
2022 unsigned long old_unseen = ULONG_MAX;
2023 struct stat stat_buf;
2024 struct hostent he, *he_res = 0;
2026 char hostbuff[2048];
2027 struct sockaddr_in their_addr; // connector's address information
2028 struct mail_s *mail = (struct mail_s *)arg;
2030 #ifdef HAVE_GETHOSTBYNAME_R
2031 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
2032 ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
2035 #else /* HAVE_GETHOSTBYNAME_R */
2036 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
2037 herror("gethostbyname");
2040 #endif /* HAVE_GETHOSTBYNAME_R */
2041 while (fail < mail->retries) {
2042 struct timeval timeout;
2047 ERR("Trying POP3 connection again for %s@%s (try %u/%u)",
2048 mail->user, mail->host, fail + 1, mail->retries);
2051 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
2058 their_addr.sin_family = AF_INET;
2059 // short, network byte order
2060 their_addr.sin_port = htons(mail->port);
2061 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
2062 // zero the rest of the struct
2063 memset(&(their_addr.sin_zero), '\0', 8);
2065 if (connect(sockfd, (struct sockaddr *) &their_addr,
2066 sizeof(struct sockaddr)) == -1) {
2072 timeout.tv_sec = 60; // 60 second timeout i guess
2073 timeout.tv_usec = 0;
2075 FD_SET(sockfd, &fdset);
2076 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
2078 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
2084 ERR("POP3 connection failed: timeout\n");
2088 DBGP2("pop3_thread received: %s", recvbuf);
2089 recvbuf[numbytes] = '\0';
2090 if (strstr(recvbuf, "+OK ") != recvbuf) {
2091 ERR("POP3 connection failed, probably not a POP3 server");
2095 strncpy(sendbuf, "USER ", MAXDATASIZE);
2096 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
2097 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
2098 if (pop3_command(sockfd, sendbuf, recvbuf, "+OK ")) {
2103 strncpy(sendbuf, "PASS ", MAXDATASIZE);
2104 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
2105 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
2106 if (pop3_command(sockfd, sendbuf, recvbuf, "+OK ")) {
2107 ERR("POP3 server login failed: %s", recvbuf);
2112 strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
2113 if (pop3_command(sockfd, sendbuf, recvbuf, "+OK ")) {
2114 perror("send STAT");
2119 // now we get the data
2120 reply = recvbuf + 4;
2121 if (reply == NULL) {
2122 ERR("Error parsing POP3 response: %s", recvbuf);
2126 timed_thread_lock(mail->p_timed_thread);
2127 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
2128 timed_thread_unlock(mail->p_timed_thread);
2131 strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
2132 if (pop3_command(sockfd, sendbuf, recvbuf, "+OK")) {
2133 ERR("POP3 logout failed: %s", recvbuf);
2138 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
2140 if (system(mail->command) == -1) {
2145 old_unseen = mail->unseen;
2147 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
2148 /* if a valid socket, close it */
2151 if (timed_thread_test(mail->p_timed_thread, 0)) {
2152 timed_thread_exit(mail->p_timed_thread);
2160 static inline void read_exec(const char *data, char *buf, const int size)
2162 FILE *fp = popen(data, "r");
2163 int length = fread(buf, 1, size, fp);
2167 if (length > 0 && buf[length - 1] == '\n') {
2168 buf[length - 1] = '\0';
2172 void *threaded_exec(void *) __attribute__((noreturn));
2174 void *threaded_exec(void *arg)
2177 struct text_object *obj = (struct text_object *)arg;
2180 p2 = obj->data.texeci.buffer;
2181 timed_thread_lock(obj->data.texeci.p_timed_thread);
2182 read_exec(obj->data.texeci.cmd, obj->data.texeci.buffer,
2185 if (*p2 == '\001') {
2190 timed_thread_unlock(obj->data.texeci.p_timed_thread);
2191 if (timed_thread_test(obj->data.texeci.p_timed_thread, 0)) {
2192 timed_thread_exit(obj->data.texeci.p_timed_thread);
2198 static struct text_object *new_text_object_internal(void)
2200 struct text_object *obj = malloc(sizeof(struct text_object));
2201 memset(obj, 0, sizeof(struct text_object));
2206 * call with full == 0 when freeing after 'internal' evaluation of objects
2208 static void free_text_objects(struct text_object_list *text_object_list, char full)
2211 struct text_object *obj;
2213 if (text_object_list == NULL) {
2217 for (i = 0; i < text_object_list->text_object_count; i++) {
2218 obj = &text_object_list->text_objects[i];
2219 switch (obj->type) {
2227 close(obj->data.sysfs.fd);
2229 #endif /* !__OpenBSD__ */
2235 free(obj->data.tztime.tz);
2236 free(obj->data.tztime.fmt);
2239 free(obj->data.mboxscan.args);
2240 free(obj->data.mboxscan.output);
2244 free(obj->data.local_mail.box);
2249 case OBJ_imap_unseen:
2250 if (!obj->global_mode) {
2251 free(obj->data.mail);
2254 case OBJ_imap_messages:
2255 if (!obj->global_mode) {
2256 free(obj->data.mail);
2262 case OBJ_pop3_unseen:
2263 if (!obj->global_mode) {
2264 free(obj->data.mail);
2268 if (!obj->global_mode) {
2269 free(obj->data.mail);
2273 case OBJ_if_existing:
2274 case OBJ_if_mounted:
2275 case OBJ_if_running:
2276 free(obj->data.ifblock.s);
2277 free(obj->data.ifblock.str);
2280 free(obj->data.tail.logfile);
2281 free(obj->data.tail.buffer);
2293 case OBJ_iconv_start:
2298 case OBJ_disk_protect:
2299 free(objs[i].data.s);
2302 free(objs[i].data.ifblock.s);
2303 free(objs[i].data.ifblock.str);
2306 free(objs[i].data.ifblock.s);
2307 free(objs[i].data.ifblock.str);
2310 if (info.gw_info.iface) {
2311 free(info.gw_info.iface);
2312 info.gw_info.iface = 0;
2314 if (info.gw_info.ip) {
2315 free(info.gw_info.ip);
2316 info.gw_info.ip = 0;
2319 case OBJ_ioscheduler:
2321 free(objs[i].data.s);
2325 case OBJ_xmms2_artist:
2326 if (info.xmms2.artist) {
2327 free(info.xmms2.artist);
2328 info.xmms2.artist = 0;
2331 case OBJ_xmms2_album:
2332 if (info.xmms2.album) {
2333 free(info.xmms2.album);
2334 info.xmms2.album = 0;
2337 case OBJ_xmms2_title:
2338 if (info.xmms2.title) {
2339 free(info.xmms2.title);
2340 info.xmms2.title = 0;
2343 case OBJ_xmms2_genre:
2344 if (info.xmms2.genre) {
2345 free(info.xmms2.genre);
2346 info.xmms2.genre = 0;
2349 case OBJ_xmms2_comment:
2350 if (info.xmms2.comment) {
2351 free(info.xmms2.comment);
2352 info.xmms2.comment = 0;
2356 if (info.xmms2.url) {
2357 free(info.xmms2.url);
2361 case OBJ_xmms2_date:
2362 if (info.xmms2.date) {
2363 free(info.xmms2.date);
2364 info.xmms2.date = 0;
2367 case OBJ_xmms2_status:
2368 if (info.xmms2.status) {
2369 free(info.xmms2.status);
2370 info.xmms2.status = 0;
2373 case OBJ_xmms2_playlist:
2374 if (info.xmms2.playlist) {
2375 free(info.xmms2.playlist);
2376 info.xmms2.playlist = 0;
2379 case OBJ_xmms2_smart:
2380 if (info.xmms2.artist) {
2381 free(info.xmms2.artist);
2382 info.xmms2.artist = 0;
2384 if (info.xmms2.title) {
2385 free(info.xmms2.title);
2386 info.xmms2.title = 0;
2388 if (info.xmms2.url) {
2389 free(info.xmms2.url);
2395 case OBJ_bmpx_title:
2396 case OBJ_bmpx_artist:
2397 case OBJ_bmpx_album:
2398 case OBJ_bmpx_track:
2400 case OBJ_bmpx_bitrate:
2409 free(obj->data.rss.uri);
2410 free(obj->data.rss.action);
2419 case OBJ_battery_time:
2422 #endif /* !__OpenBSD__ */
2426 case OBJ_execigraph:
2427 free(obj->data.execi.cmd);
2428 free(obj->data.execi.buffer);
2431 free(obj->data.texeci.cmd);
2432 free(obj->data.texeci.buffer);
2434 case OBJ_nameserver:
2439 if (info.first_process) {
2440 free_all_processes();
2441 info.first_process = NULL;
2446 free(obj->data.hddtemp.dev);
2447 free(obj->data.hddtemp.addr);
2448 if (obj->data.hddtemp.temp)
2449 free(obj->data.hddtemp.temp);
2452 case OBJ_entropy_avail:
2453 case OBJ_entropy_poolsize:
2454 case OBJ_entropy_bar:
2456 case OBJ_user_names:
2457 if (info.users.names) {
2458 free(info.users.names);
2459 info.users.names = 0;
2462 case OBJ_user_terms:
2463 if (info.users.terms) {
2464 free(info.users.terms);
2465 info.users.terms = 0;
2468 case OBJ_user_times:
2469 if (info.users.times) {
2470 free(info.users.times);
2471 info.users.times = 0;
2476 case OBJ_smapi_bat_perc:
2477 case OBJ_smapi_bat_temp:
2478 case OBJ_smapi_bat_power:
2481 case OBJ_if_smapi_bat_installed:
2482 free(obj->data.ifblock.s);
2483 free(obj->data.ifblock.str);
2492 case OBJ_mpd_artist:
2494 case OBJ_mpd_random:
2495 case OBJ_mpd_repeat:
2497 case OBJ_mpd_bitrate:
2498 case OBJ_mpd_status:
2501 case OBJ_mpd_password:
2503 case OBJ_mpd_elapsed:
2504 case OBJ_mpd_length:
2508 case OBJ_mpd_percent:
2510 case OBJ_if_mpd_playing:
2512 free_mpd_vars(&info.mpd);
2520 case OBJ_moc_artist:
2523 case OBJ_moc_totaltime:
2524 case OBJ_moc_timeleft:
2525 case OBJ_moc_curtime:
2526 case OBJ_moc_bitrate:
2528 free_moc(&info.moc);
2532 free(obj->data.scroll.text);
2536 if (full) {} // disable warning when MPD !defined
2537 free(text_object_list->text_objects);
2538 text_object_list->text_objects = NULL;
2539 text_object_list->text_object_count = 0;
2542 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2547 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2548 *a = mixer_init(buf1);
2549 scan_bar(arg + n, w, h);
2551 *a = mixer_init(NULL);
2552 scan_bar(arg, w, h);
2556 /* strip a leading /dev/ if any */
2557 #define DEV_NAME(x) x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 \
2560 /* construct_text_object() creates a new text_object */
2561 static struct text_object *construct_text_object(const char *s,
2562 const char *arg, unsigned int object_count,
2563 struct text_object *text_objects, long line, char allow_threaded)
2565 // struct text_object *obj = new_text_object();
2566 struct text_object *obj = new_text_object_internal();
2570 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2571 obj->type = OBJ_##a; need_mask |= (1 << n); {
2572 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
2573 obj->type = OBJ_##a; need_mask |= (1 << n); {
2574 #define END } } else
2578 obj->type = OBJ_color;
2579 obj->data.l = get_x11_color(s);
2583 OBJ(freq, INFO_FREQ)
2586 obj->data.i = open_acpi_temperature(arg);
2587 END OBJ(acpiacadapter, 0)
2588 END OBJ(freq, INFO_FREQ)
2589 #endif /* !__OpenBSD__ */
2591 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2592 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2593 obj->data.cpu_index = 1;
2594 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2595 "Displaying the clock for CPU 1."); */
2597 obj->data.cpu_index = atoi(&arg[0]);
2600 END OBJ(freq_g, INFO_FREQ)
2602 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2603 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2604 obj->data.cpu_index = 1;
2605 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2606 "CPUs! Displaying the clock for CPU 1."); */
2608 obj->data.cpu_index = atoi(&arg[0]);
2611 #if defined(__linux__)
2612 END OBJ(voltage_mv, 0)
2614 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2615 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2616 obj->data.cpu_index = 1;
2617 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2618 "CPUs! Displaying voltage for CPU 1."); */
2620 obj->data.cpu_index = atoi(&arg[0]);
2623 END OBJ(voltage_v, 0)
2625 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2626 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2627 obj->data.cpu_index = 1;
2628 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2629 "CPUs! Displaying voltage for CPU 1."); */
2631 obj->data.cpu_index = atoi(&arg[0]);
2636 END OBJ(wireless_essid, INFO_NET)
2638 obj->data.net = get_net_stat(arg);
2640 CRIT_ERR("wireless_essid: needs an argument");
2642 END OBJ(wireless_mode, INFO_NET)
2644 obj->data.net = get_net_stat(arg);
2646 CRIT_ERR("wireless_mode: needs an argument");
2648 END OBJ(wireless_bitrate, INFO_NET)
2650 obj->data.net = get_net_stat(arg);
2652 CRIT_ERR("wireless_bitrate: needs an argument");
2654 END OBJ(wireless_ap, INFO_NET)
2656 obj->data.net = get_net_stat(arg);
2658 CRIT_ERR("wireless_ap: needs an argument");
2660 END OBJ(wireless_link_qual, INFO_NET)
2662 obj->data.net = get_net_stat(arg);
2664 CRIT_ERR("wireless_link_qual: needs an argument");
2666 END OBJ(wireless_link_qual_max, INFO_NET)
2668 obj->data.net = get_net_stat(arg);
2670 CRIT_ERR("wireless_link_qual_max: needs an argument");
2672 END OBJ(wireless_link_qual_perc, INFO_NET)
2674 obj->data.net = get_net_stat(arg);
2676 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2678 END OBJ(wireless_link_bar, INFO_NET)
2680 arg = scan_bar(arg, &obj->a, &obj->b);
2681 obj->data.net = get_net_stat(arg);
2683 CRIT_ERR("wireless_link_bar: needs an argument");
2685 #endif /* HAVE_IWLIB */
2687 #endif /* __linux__ */
2695 sscanf(arg, "%63s", bat);
2697 strcpy(bat, "BAT0");
2699 obj->data.s = strndup(bat, text_buffer_size);
2700 END OBJ(battery_time, 0)
2704 sscanf(arg, "%63s", bat);
2706 strcpy(bat, "BAT0");
2708 obj->data.s = strndup(bat, text_buffer_size);
2709 END OBJ(battery_percent, 0)
2713 sscanf(arg, "%63s", bat);
2715 strcpy(bat, "BAT0");
2717 obj->data.s = strndup(bat, text_buffer_size);
2718 END OBJ(battery_bar, 0)
2722 arg = scan_bar(arg, &obj->a, &obj->b);
2723 sscanf(arg, "%63s", bat);
2725 strcpy(bat, "BAT0");
2727 obj->data.s = strndup(bat, text_buffer_size);
2728 #endif /* !__OpenBSD__ */
2730 #if defined(__linux__)
2731 END OBJ(disk_protect, 0)
2733 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2735 CRIT_ERR("disk_protect needs an argument");
2736 END OBJ(i8k_version, INFO_I8K)
2737 END OBJ(i8k_bios, INFO_I8K)
2738 END OBJ(i8k_serial, INFO_I8K)
2739 END OBJ(i8k_cpu_temp, INFO_I8K)
2740 END OBJ(i8k_left_fan_status, INFO_I8K)
2741 END OBJ(i8k_right_fan_status, INFO_I8K)
2742 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2743 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2744 END OBJ(i8k_ac_status, INFO_I8K)
2745 END OBJ(i8k_buttons_status, INFO_I8K)
2747 END OBJ(ibm_temps, 0)
2749 CRIT_ERR("ibm_temps: needs an argument");
2751 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2752 obj->data.sensor = 0;
2753 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2754 "Using 0 (CPU temp sensor).");
2756 obj->data.sensor = atoi(&arg[0]);
2757 END OBJ(ibm_volume, 0)
2758 END OBJ(ibm_brightness, 0)
2760 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2761 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2764 ERR("if_up needs an argument");
2765 obj->data.ifblock.s = 0;
2767 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2768 blockstart[blockdepth] = object_count;
2769 obj->data.ifblock.pos = object_count + 2;
2772 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2773 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2775 blockstart[blockdepth] = object_count;
2776 obj->data.ifblock.pos = object_count + 2;
2778 END OBJ(ioscheduler, 0)
2780 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
2783 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2784 END OBJ(laptop_mode, 0)
2785 END OBJ(pb_battery, 0)
2786 if (arg && strcmp(arg, "status") == EQUAL) {
2787 obj->data.i = PB_BATT_STATUS;
2788 } else if (arg && strcmp(arg, "percent") == EQUAL) {
2789 obj->data.i = PB_BATT_PERCENT;
2790 } else if (arg && strcmp(arg, "time") == EQUAL) {
2791 obj->data.i = PB_BATT_TIME;
2793 ERR("pb_battery: needs one argument: status, percent or time");
2798 #endif /* __linux__ */
2799 #if defined(__OpenBSD__)
2800 END OBJ(obsd_sensors_temp, 0)
2802 CRIT_ERR("obsd_sensors_temp: needs an argument");
2804 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2805 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2806 obj->data.sensor = 0;
2807 ERR("Invalid temperature sensor number!");
2809 obj->data.sensor = atoi(&arg[0]);
2810 END OBJ(obsd_sensors_fan, 0)
2812 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2815 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2816 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2817 obj->data.sensor = 0;
2818 ERR("Invalid fan sensor number!");
2820 obj->data.sensor = atoi(&arg[0]);
2821 END OBJ(obsd_sensors_volt, 0)
2823 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2826 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2827 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2828 obj->data.sensor = 0;
2829 ERR("Invalid voltage sensor number!");
2831 obj->data.sensor = atoi(&arg[0]);
2832 END OBJ(obsd_vendor, 0)
2833 END OBJ(obsd_product, 0)
2834 #endif /* __OpenBSD__ */
2835 END OBJ(buffers, INFO_BUFFERS)
2836 END OBJ(cached, INFO_BUFFERS)
2837 END OBJ(cpu, INFO_CPU)
2839 if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
2840 obj->data.cpu_index = atoi(&arg[3]);
2843 obj->data.cpu_index = 0;
2845 DBGP2("Adding $cpu for CPU %d", obj->data.cpu_index);
2847 obj->data.cpu_index = 0;
2849 END OBJ(cpubar, INFO_CPU)
2851 if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
2852 obj->data.cpu_index = atoi(&arg[3]);
2855 obj->data.cpu_index = 0;
2857 scan_bar(arg, &obj->a, &obj->b);
2859 scan_bar(arg, &obj->a, &obj->b);
2860 obj->data.cpu_index = 0;
2862 DBGP2("Adding $cpubar for CPU %d", obj->data.cpu_index);
2863 END OBJ(cpugraph, INFO_CPU)
2864 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2865 &obj->e, &obj->showaslog);
2868 if (strncmp(buf, "cpu", 3) == EQUAL && isdigit(buf[3])) {
2869 obj->data.cpu_index = atoi(&buf[3]);
2871 obj->data.cpu_index = 0;
2875 DBGP2("Adding $cpugraph for CPU %d", obj->data.cpu_index);
2876 END OBJ(loadgraph, INFO_LOADAVG)
2877 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2878 &obj->e, &obj->showaslog);
2882 r = sscanf(arg, "%d", &a);
2884 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2887 #if defined(__linux__)
2888 END OBJ(diskio, INFO_DISKIO)
2890 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2892 obj->data.diskio = NULL;
2894 END OBJ(diskio_read, INFO_DISKIO)
2896 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2898 obj->data.diskio = NULL;
2900 END OBJ(diskio_write, INFO_DISKIO)
2902 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2904 obj->data.diskio = NULL;
2906 END OBJ(diskiograph, INFO_DISKIO)
2907 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2908 &obj->e, &obj->showaslog);
2911 obj->data.diskio = prepare_diskio_stat(buf);
2914 obj->data.diskio = NULL;
2916 END OBJ(diskiograph_read, INFO_DISKIO)
2917 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2918 &obj->e, &obj->showaslog);
2921 obj->data.diskio = prepare_diskio_stat(buf);
2924 obj->data.diskio = NULL;
2926 END OBJ(diskiograph_write, INFO_DISKIO)
2927 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2928 &obj->e, &obj->showaslog);
2931 obj->data.diskio = prepare_diskio_stat(buf);
2934 obj->data.diskio = NULL;
2939 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2942 obj->data.l = color0;
2944 obj->data.l = color1;
2946 obj->data.l = color2;
2948 obj->data.l = color3;
2950 obj->data.l = color4;
2952 obj->data.l = color5;
2954 obj->data.l = color6;
2956 obj->data.l = color7;
2958 obj->data.l = color8;
2960 obj->data.l = color9;
2962 obj->data.s = scan_font(arg);
2963 END OBJ(conky_version, 0)
2964 END OBJ(conky_build_date, 0)
2965 END OBJ(conky_build_arch, 0)
2966 END OBJ(downspeed, INFO_NET)
2968 obj->data.net = get_net_stat(arg);
2970 CRIT_ERR("downspeed needs argument");
2972 END OBJ(downspeedf, INFO_NET)
2974 obj->data.net = get_net_stat(arg);
2976 CRIT_ERR("downspeedf needs argument");
2978 END OBJ(downspeedgraph, INFO_NET)
2979 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2980 &obj->e, &obj->showaslog);
2982 // default to DEFAULTNETDEV
2983 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2984 obj->data.net = get_net_stat(buf);
2988 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2990 blockstart[blockdepth - 1] = object_count;
2991 obj->data.ifblock.pos = object_count + 2;
2993 ERR("$else: no matching $if_*");
2998 text_objects[blockstart[blockdepth]].data.ifblock.pos =
3001 ERR("$endif: no matching $if_*");
3004 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
3007 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
3009 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
3011 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
3012 END OBJ(execgraph, 0)
3013 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
3014 END OBJ(execibar, 0)
3017 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
3020 ERR("${execibar <interval> command}");
3021 obj->type = OBJ_text;
3022 snprintf(buf, 256, "${%s}", s);
3023 obj->data.s = strndup(buf, text_buffer_size);
3025 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
3027 END OBJ(execigraph, 0)
3030 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
3033 ERR("${execigraph <interval> command}");
3034 obj->type = OBJ_text;
3035 snprintf(buf, 256, "${%s}", s);
3036 obj->data.s = strndup(buf, text_buffer_size);
3038 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
3043 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
3046 ERR("${execi <interval> command}");
3047 obj->type = OBJ_text;
3048 snprintf(buf, 256, "${%s}", s);
3049 obj->data.s = strndup(buf, text_buffer_size);
3051 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
3052 obj->data.execi.buffer = malloc(text_buffer_size);
3057 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
3060 ERR("${execi <interval> command}");
3061 obj->type = OBJ_text;
3062 snprintf(buf, 256, "${%s}", s);
3063 obj->data.s = strndup(buf, text_buffer_size);
3065 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
3066 obj->data.execi.buffer = malloc(text_buffer_size);
3068 END OBJ_THREAD(texeci, 0)
3071 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
3074 ERR("${texeci <interval> command}");
3075 obj->type = OBJ_text;
3076 snprintf(buf, 256, "${%s}", s);
3077 obj->data.s = strndup(buf, text_buffer_size);
3079 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
3080 obj->data.texeci.buffer = malloc(text_buffer_size);
3082 obj->data.texeci.p_timed_thread = NULL;
3083 END OBJ(pre_exec, 0)
3084 obj->type = OBJ_text;
3088 read_exec(arg, buf, sizeof(buf));
3089 obj->data.s = strndup(buf, text_buffer_size);
3091 obj->data.s = strndup("", text_buffer_size);
3094 END OBJ(fs_bar, INFO_FS)
3095 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
3097 while (isspace(*arg)) {
3106 obj->data.fsbar.fs = prepare_fs_stat(arg);
3107 END OBJ(fs_bar_free, INFO_FS)
3108 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
3110 while (isspace(*arg)) {
3120 obj->data.fsbar.fs = prepare_fs_stat(arg);
3121 END OBJ(fs_free, INFO_FS)
3125 obj->data.fs = prepare_fs_stat(arg);
3126 END OBJ(fs_used_perc, INFO_FS)
3130 obj->data.fs = prepare_fs_stat(arg);
3131 END OBJ(fs_free_perc, INFO_FS)
3135 obj->data.fs = prepare_fs_stat(arg);
3136 END OBJ(fs_size, INFO_FS)
3140 obj->data.fs = prepare_fs_stat(arg);
3141 END OBJ(fs_type, INFO_FS)
3145 obj->data.fs = prepare_fs_stat(arg);
3146 END OBJ(fs_used, INFO_FS)
3150 obj->data.fs = prepare_fs_stat(arg);
3152 obj->data.i = arg ? atoi(arg) : 1;
3153 END OBJ(nameserver, INFO_DNS)
3154 obj->data.i = arg ? atoi(arg) : 0;
3156 obj->data.i = arg ? atoi(arg) : 1;
3158 obj->data.i = arg ? atoi(arg) : 1;
3162 ERR("goto needs arguments");
3163 obj->type = OBJ_text;
3164 obj->data.s = strndup("${goto}", text_buffer_size);
3168 obj->data.i = atoi(arg);
3174 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3175 sscanf(arg, "%d", &b);
3181 obj->data.pair.a = a;
3182 obj->data.pair.b = b;
3185 END OBJ(i2c, INFO_SYSFS)
3186 char buf1[64], buf2[64];
3190 ERR("i2c needs arguments");
3191 obj->type = OBJ_text;
3192 // obj->data.s = strndup("${i2c}", text_buffer_size);
3196 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3197 /* if scanf couldn't read three values, read type and num and use
3199 sscanf(arg, "%63s %d", buf2, &n);
3200 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
3201 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3202 strncpy(obj->data.sysfs.type, buf2, 63);
3204 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
3205 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3206 strncpy(obj->data.sysfs.type, buf2, 63);
3209 END OBJ(platform, INFO_SYSFS)
3210 char buf1[64], buf2[64];
3214 ERR("platform needs arguments");
3215 obj->type = OBJ_text;
3219 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3220 /* if scanf couldn't read three values, read type and num and use
3222 sscanf(arg, "%63s %d", buf2, &n);
3223 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
3224 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3225 strncpy(obj->data.sysfs.type, buf2, 63);
3227 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
3228 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3229 strncpy(obj->data.sysfs.type, buf2, 63);
3232 END OBJ(hwmon, INFO_SYSFS)
3233 char buf1[64], buf2[64];
3237 ERR("hwmon needs argumanets");
3238 obj->type = OBJ_text;
3242 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3243 /* if scanf couldn't read three values, read type and num and use
3245 sscanf(arg, "%63s %d", buf2, &n);
3246 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
3247 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3248 strncpy(obj->data.sysfs.type, buf2, 63);
3250 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
3251 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3252 strncpy(obj->data.sysfs.type, buf2, 63);
3254 #endif /* !__OpenBSD__ */
3256 END OBJ(top, INFO_TOP)
3261 ERR("top needs arguments");
3262 obj->type = OBJ_text;
3263 // obj->data.s = strndup("${top}", text_buffer_size);
3266 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3267 if (strcmp(buf, "name") == EQUAL) {
3268 obj->data.top.type = TOP_NAME;
3269 } else if (strcmp(buf, "cpu") == EQUAL) {
3270 obj->data.top.type = TOP_CPU;
3271 } else if (strcmp(buf, "pid") == EQUAL) {
3272 obj->data.top.type = TOP_PID;
3273 } else if (strcmp(buf, "mem") == EQUAL) {
3274 obj->data.top.type = TOP_MEM;
3275 } else if (strcmp(buf, "time") == EQUAL) {
3276 obj->data.top.type = TOP_TIME;
3277 } else if (strcmp(buf, "mem_res") == EQUAL) {
3278 obj->data.top.type = TOP_MEM_RES;
3279 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
3280 obj->data.top.type = TOP_MEM_VSIZE;
3282 ERR("invalid arg for top");
3285 if (n < 1 || n > 10) {
3286 CRIT_ERR("invalid arg for top");
3289 obj->data.top.num = n - 1;
3293 ERR("invalid args given for top");
3296 END OBJ(top_mem, INFO_TOP)
3301 ERR("top_mem needs arguments");
3302 obj->type = OBJ_text;
3303 obj->data.s = strndup("${top_mem}", text_buffer_size);
3306 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3307 if (strcmp(buf, "name") == EQUAL) {
3308 obj->data.top.type = TOP_NAME;
3309 } else if (strcmp(buf, "cpu") == EQUAL) {
3310 obj->data.top.type = TOP_CPU;
3311 } else if (strcmp(buf, "pid") == EQUAL) {
3312 obj->data.top.type = TOP_PID;
3313 } else if (strcmp(buf, "mem") == EQUAL) {
3314 obj->data.top.type = TOP_MEM;
3315 } else if (strcmp(buf, "time") == EQUAL) {
3316 obj->data.top.type = TOP_TIME;
3317 } else if (strcmp(buf, "mem_res") == EQUAL) {
3318 obj->data.top.type = TOP_MEM_RES;
3319 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
3320 obj->data.top.type = TOP_MEM_VSIZE;
3322 ERR("invalid arg for top");
3325 if (n < 1 || n > 10) {
3326 CRIT_ERR("invalid arg for top");
3329 obj->data.top.num = n - 1;
3333 ERR("invalid args given for top");
3336 END OBJ(addr, INFO_NET)
3338 obj->data.net = get_net_stat(arg);
3340 CRIT_ERR("addr needs argument");
3342 #if defined(__linux__)
3343 END OBJ(addrs, INFO_NET)
3345 obj->data.net = get_net_stat(arg);
3347 CRIT_ERR("addrs needs argument");
3349 #endif /* __linux__ */
3356 ERR("tail needs arguments");
3357 obj->type = OBJ_text;
3358 obj->data.s = strndup("${tail}", text_buffer_size);
3361 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3362 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3363 CRIT_ERR("invalid arg for tail, number of lines must be "
3364 "between 1 and %i", MAX_TAIL_LINES);
3370 obj->data.tail.fd = -1;
3372 if (stat(buf, &st) == 0) {
3373 if (S_ISFIFO(st.st_mode)) {
3374 fd = open(buf, O_RDONLY | O_NONBLOCK);
3377 CRIT_ERR("tail logfile does not exist, or you do "
3378 "not have correct permissions");
3381 obj->data.tail.fd = fd;
3383 fp = fopen(buf, "r");
3387 if (fp || obj->data.tail.fd != -1) {
3388 obj->data.tail.logfile = malloc(text_buffer_size);
3389 strcpy(obj->data.tail.logfile, buf);
3390 obj->data.tail.wantedlines = n1;
3391 obj->data.tail.interval = update_interval * 2;
3393 if (obj->data.tail.fd == -1) {
3398 CRIT_ERR("tail logfile does not exist, or you do not have "
3399 "correct permissions");
3402 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3403 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3404 CRIT_ERR("invalid arg for tail, number of lines must be "
3405 "between 1 and %i", MAX_TAIL_LINES);
3407 } else if (n2 < 1 || n2 < update_interval) {
3408 CRIT_ERR("invalid arg for tail, interval must be greater than "
3409 "0 and "PACKAGE_NAME"'s interval");
3415 obj->data.tail.fd = -1;
3417 if (stat(buf, &st) == 0) {
3418 if (S_ISFIFO(st.st_mode)) {
3419 fd = open(buf, O_RDONLY | O_NONBLOCK);
3422 CRIT_ERR("tail logfile does not exist, or you do "
3423 "not have correct permissions");
3426 obj->data.tail.fd = fd;
3428 fp = fopen(buf, "r");
3432 if (fp || obj->data.tail.fd != -1) {
3433 obj->data.tail.logfile = malloc(text_buffer_size);
3434 strcpy(obj->data.tail.logfile, buf);
3435 obj->data.tail.wantedlines = n1;
3436 obj->data.tail.interval = n2;
3438 if (obj->data.tail.fd == -1) {
3443 CRIT_ERR("tail logfile does not exist, or you do not have "
3444 "correct permissions");
3448 ERR("invalid args given for tail");
3451 /* asumming all else worked */
3452 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3458 ERR("head needs arguments");
3459 obj->type = OBJ_text;
3460 obj->data.s = strndup("${head}", text_buffer_size);
3463 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3464 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3465 CRIT_ERR("invalid arg for head, number of lines must be "
3466 "between 1 and %i", MAX_TAIL_LINES);
3471 fp = fopen(buf, "r");
3473 obj->data.tail.logfile = malloc(text_buffer_size);
3474 strcpy(obj->data.tail.logfile, buf);
3475 obj->data.tail.wantedlines = n1;
3476 obj->data.tail.interval = update_interval * 2;
3480 CRIT_ERR("head logfile does not exist, or you do not have "
3481 "correct permissions");
3484 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3485 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3486 CRIT_ERR("invalid arg for head, number of lines must be "
3487 "between 1 and %i", MAX_TAIL_LINES);
3489 } else if (n2 < 1 || n2 < update_interval) {
3490 CRIT_ERR("invalid arg for head, interval must be greater than "
3491 "0 and "PACKAGE_NAME"'s interval");
3496 fp = fopen(buf, "r");
3498 obj->data.tail.logfile = malloc(text_buffer_size);
3499 strcpy(obj->data.tail.logfile, buf);
3500 obj->data.tail.wantedlines = n1;
3501 obj->data.tail.interval = n2;
3505 CRIT_ERR("head logfile does not exist, or you do not have "
3506 "correct permissions");
3510 ERR("invalid args given for head");
3513 /* asumming all else worked */
3514 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3517 obj->data.s = strdup(arg);
3519 CRIT_ERR("lines needs a argument");
3523 obj->data.s = strdup(arg);
3525 CRIT_ERR("words needs a argument");
3527 END OBJ(loadavg, INFO_LOADAVG)
3528 int a = 1, b = 2, c = 3, r = 3;
3531 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3532 if (r >= 3 && (c < 1 || c > 3)) {
3535 if (r >= 2 && (b < 1 || b > 3)) {
3538 if (r >= 1 && (a < 1 || a > 3)) {
3542 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3543 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3544 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3545 END OBJ(if_empty, 0)
3546 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3547 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3550 ERR("if_empty needs an argument");
3551 obj->data.ifblock.s = 0;
3553 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3555 blockstart[blockdepth] = object_count;
3556 obj->data.ifblock.pos = object_count + 2;
3558 END OBJ(if_existing, 0)
3559 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3560 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3563 ERR("if_existing needs an argument or two");
3564 obj->data.ifblock.s = NULL;
3565 obj->data.ifblock.str = NULL;
3567 char buf1[256], buf2[256];
3568 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3571 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3572 obj->data.ifblock.str = NULL;
3574 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3575 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
3578 blockstart[blockdepth] = object_count;
3579 obj->data.ifblock.pos = object_count + 2;
3581 END OBJ(if_mounted, 0)
3582 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3583 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3586 ERR("if_mounted needs an argument");
3587 obj->data.ifblock.s = 0;
3589 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3591 blockstart[blockdepth] = object_count;
3592 obj->data.ifblock.pos = object_count + 2;
3594 END OBJ(if_running, 0)
3595 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3596 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3601 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3602 obj->data.ifblock.s = strndup(buf, text_buffer_size);
3604 ERR("if_running needs an argument");
3605 obj->data.ifblock.s = 0;
3607 blockstart[blockdepth] = object_count;
3608 obj->data.ifblock.pos = object_count + 2;
3614 char box[256], dst[256];
3618 /* Kapil: Changed from MAIL_FILE to
3619 current_mail_spool since the latter
3620 is a copy of the former if undefined
3621 but the latter should take precedence
3623 strncpy(box, current_mail_spool, sizeof(box));
3625 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3627 strncpy(box, arg, sizeof(box));
3631 variable_substitute(box, dst, sizeof(dst));
3632 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3633 obj->data.local_mail.interval = n1;
3634 END OBJ(mboxscan, 0)
3635 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
3636 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3637 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3638 obj->data.mboxscan.output[0] = 1;
3639 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
3640 END OBJ(mem, INFO_MEM)
3641 END OBJ(memeasyfree, INFO_MEM)
3642 END OBJ(memfree, INFO_MEM)
3643 END OBJ(memmax, INFO_MEM)
3644 END OBJ(memperc, INFO_MEM)
3645 END OBJ(membar, INFO_MEM)
3646 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3647 END OBJ(memgraph, INFO_MEM)
3648 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3649 &obj->e, &obj->showaslog);
3654 END OBJ(mixer, INFO_MIXER)
3655 obj->data.l = mixer_init(arg);
3656 END OBJ(mixerl, INFO_MIXER)
3657 obj->data.l = mixer_init(arg);
3658 END OBJ(mixerr, INFO_MIXER)
3659 obj->data.l = mixer_init(arg);
3660 END OBJ(mixerbar, INFO_MIXER)
3661 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3662 &obj->data.mixerbar.h);
3663 END OBJ(mixerlbar, INFO_MIXER)
3664 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3665 &obj->data.mixerbar.h);
3666 END OBJ(mixerrbar, INFO_MIXER)
3667 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3668 &obj->data.mixerbar.h);
3670 END OBJ(monitor, INFO_X11)
3671 END OBJ(monitor_number, INFO_X11)
3673 END OBJ(new_mails, 0)
3675 char box[256], dst[256];
3679 /* Kapil: Changed from MAIL_FILE to
3680 current_mail_spool since the latter
3681 is a copy of the former if undefined
3682 but the latter should take precedence
3684 strncpy(box, current_mail_spool, sizeof(box));
3686 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3688 strncpy(box, arg, sizeof(box));
3692 variable_substitute(box, dst, sizeof(dst));
3693 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3694 obj->data.local_mail.interval = n1;
3695 END OBJ(nodename, 0)
3696 END OBJ(processes, INFO_PROCS)
3697 END OBJ(running_processes, INFO_RUN_PROCS)
3698 END OBJ(shadecolor, 0)
3700 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3702 END OBJ(outlinecolor, 0)
3704 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3706 END OBJ(stippled_hr, 0)
3708 int a = stippled_borders, b = 1;
3711 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3712 sscanf(arg, "%d", &b);
3718 obj->data.pair.a = a;
3719 obj->data.pair.b = b;
3721 END OBJ(swap, INFO_MEM)
3722 END OBJ(swapmax, INFO_MEM)
3723 END OBJ(swapperc, INFO_MEM)
3724 END OBJ(swapbar, INFO_MEM)
3725 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3728 END OBJ(temp1, INFO_SYSFS)
3729 obj->type = OBJ_i2c;
3730 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3731 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3732 END OBJ(temp2, INFO_SYSFS)
3733 obj->type = OBJ_i2c;
3734 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3735 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3738 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3740 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3742 char buf1[256], buf2[256], *fmt, *tz;
3746 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3756 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
3757 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
3759 END OBJ(iconv_start, 0)
3760 if (iconv_converting) {
3761 CRIT_ERR("You must stop your last iconv conversion before "
3762 "starting another");
3765 char iconv_from[CODEPAGE_LENGTH];
3766 char iconv_to[CODEPAGE_LENGTH];
3768 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3769 CRIT_ERR("Invalid arguments for iconv_start");
3773 new_iconv = iconv_open(iconv_to, iconv_from);
3774 if (new_iconv == (iconv_t) (-1)) {
3775 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3777 obj->a = register_iconv(&new_iconv);
3778 iconv_converting = 1;
3782 CRIT_ERR("Iconv requires arguments");
3784 END OBJ(iconv_stop, 0)
3785 iconv_converting = 0;
3788 END OBJ(totaldown, INFO_NET)
3790 obj->data.net = get_net_stat(arg);
3792 CRIT_ERR("totaldown needs argument");
3794 END OBJ(totalup, INFO_NET)
3795 obj->data.net = get_net_stat(arg);
3797 obj->data.net = get_net_stat(arg);
3799 CRIT_ERR("totalup needs argument");
3803 obj->data.i = arg ? atoi(arg) : 0;
3805 obj->data.i = arg ? atoi(arg) : 0;
3806 END OBJ(upspeed, INFO_NET)
3808 obj->data.net = get_net_stat(arg);
3810 CRIT_ERR("upspeed needs argument");
3812 END OBJ(upspeedf, INFO_NET)
3814 obj->data.net = get_net_stat(arg);
3816 CRIT_ERR("upspeedf needs argument");
3819 END OBJ(upspeedgraph, INFO_NET)
3820 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3821 &obj->e, &obj->showaslog);
3823 // default to DEFAULTNETDEV
3824 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
3825 obj->data.net = get_net_stat(buf);
3827 END OBJ(uptime_short, INFO_UPTIME)
3828 END OBJ(uptime, INFO_UPTIME)
3829 END OBJ(user_names, INFO_USERS)
3830 END OBJ(user_times, INFO_USERS)
3831 END OBJ(user_terms, INFO_USERS)
3832 END OBJ(user_number, INFO_USERS)
3833 #if defined(__linux__)
3834 END OBJ(gw_iface, INFO_GW)
3835 END OBJ(gw_ip, INFO_GW)
3836 END OBJ(if_gw, INFO_GW)
3837 #endif /* !__linux__ */
3839 END OBJ(adt746xcpu, 0)
3840 END OBJ(adt746xfan, 0)
3841 #endif /* !__OpenBSD__ */
3842 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3843 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3844 END OBJ(apm_adapter, 0)
3845 END OBJ(apm_battery_life, 0)
3846 END OBJ(apm_battery_time, 0)
3847 #endif /* __FreeBSD__ */
3848 END OBJ_THREAD(imap_unseen, 0)
3851 obj->data.mail = parse_mail_args(IMAP, arg);
3852 obj->global_mode = 0;
3854 obj->global_mode = 1;
3856 END OBJ_THREAD(imap_messages, 0)
3859 obj->data.mail = parse_mail_args(IMAP, arg);
3860 obj->global_mode = 0;
3862 obj->global_mode = 1;
3864 END OBJ_THREAD(pop3_unseen, 0)
3867 obj->data.mail = parse_mail_args(POP3, arg);
3868 obj->global_mode = 0;
3870 obj->global_mode = 1;
3872 END OBJ_THREAD(pop3_used, 0)
3875 obj->data.mail = parse_mail_args(POP3, arg);
3876 obj->global_mode = 0;
3878 obj->global_mode = 1;
3883 obj->data.s = strndup(arg, text_buffer_size);
3885 ERR("smapi needs an argument");
3886 END OBJ(if_smapi_bat_installed, 0)
3887 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3888 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3891 ERR("if_smapi_bat_installed needs an argument");
3892 obj->data.ifblock.s = 0;
3894 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3895 blockstart[blockdepth] = object_count;
3896 obj->data.ifblock.pos = object_count + 2;
3898 END OBJ(smapi_bat_perc, 0)
3900 obj->data.s = strndup(arg, text_buffer_size);
3902 ERR("smapi_bat_perc needs an argument");
3903 END OBJ(smapi_bat_temp, 0)
3905 obj->data.s = strndup(arg, text_buffer_size);
3907 ERR("smapi_bat_temp needs an argument");
3908 END OBJ(smapi_bat_power, 0)
3910 obj->data.s = strndup(arg, text_buffer_size);
3912 ERR("smapi_bat_power needs an argument");
3913 END OBJ(smapi_bat_bar, 0)
3916 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
3917 ERR("first argument to smapi_bat_bar must be an integer value");
3921 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
3924 ERR("if_smapi_bat_bar needs an argument");
3927 END OBJ_THREAD(mpd_artist, INFO_MPD)
3928 END OBJ_THREAD(mpd_title, INFO_MPD)
3930 sscanf(arg, "%d", &obj->data.i);
3931 if (obj->data.i > 0) {
3934 CRIT_ERR("mpd_title: invalid length argument");
3939 END OBJ_THREAD(mpd_random, INFO_MPD)
3940 END OBJ_THREAD(mpd_repeat, INFO_MPD)
3941 END OBJ_THREAD(mpd_elapsed, INFO_MPD)
3942 END OBJ_THREAD(mpd_length, INFO_MPD)
3943 END OBJ_THREAD(mpd_track, INFO_MPD)
3944 END OBJ_THREAD(mpd_name, INFO_MPD)
3945 END OBJ_THREAD(mpd_file, INFO_MPD)
3946 END OBJ_THREAD(mpd_percent, INFO_MPD)
3947 END OBJ_THREAD(mpd_album, INFO_MPD)
3948 END OBJ_THREAD(mpd_vol, INFO_MPD)
3949 END OBJ_THREAD(mpd_bitrate, INFO_MPD)
3950 END OBJ_THREAD(mpd_status, INFO_MPD)
3951 END OBJ_THREAD(mpd_bar, INFO_MPD)
3952 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3953 END OBJ_THREAD(mpd_smart, INFO_MPD)
3955 sscanf(arg, "%d", &obj->data.i);
3956 if (obj->data.i > 0) {
3959 CRIT_ERR("mpd_smart: invalid length argument");
3964 END OBJ_THREAD(if_mpd_playing, INFO_MPD)
3965 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3966 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3968 blockstart[blockdepth] = object_count;
3969 obj->data.ifblock.pos = object_count + 2;
3973 END OBJ_THREAD(moc_state, INFO_MOC)
3974 END OBJ_THREAD(moc_file, INFO_MOC)
3975 END OBJ_THREAD(moc_title, INFO_MOC)
3976 END OBJ_THREAD(moc_artist, INFO_MOC)
3977 END OBJ_THREAD(moc_song, INFO_MOC)
3978 END OBJ_THREAD(moc_album, INFO_MOC)
3979 END OBJ_THREAD(moc_totaltime, INFO_MOC)
3980 END OBJ_THREAD(moc_timeleft, INFO_MOC)
3981 END OBJ_THREAD(moc_curtime, INFO_MOC)
3982 END OBJ_THREAD(moc_bitrate, INFO_MOC)
3983 END OBJ_THREAD(moc_rate, INFO_MOC)
3986 END OBJ(xmms2_artist, INFO_XMMS2)
3987 END OBJ(xmms2_album, INFO_XMMS2)
3988 END OBJ(xmms2_title, INFO_XMMS2)
3989 END OBJ(xmms2_genre, INFO_XMMS2)
3990 END OBJ(xmms2_comment, INFO_XMMS2)
3991 END OBJ(xmms2_url, INFO_XMMS2)
3992 END OBJ(xmms2_tracknr, INFO_XMMS2)
3993 END OBJ(xmms2_bitrate, INFO_XMMS2)
3994 END OBJ(xmms2_date, INFO_XMMS2)
3995 END OBJ(xmms2_id, INFO_XMMS2)
3996 END OBJ(xmms2_duration, INFO_XMMS2)
3997 END OBJ(xmms2_elapsed, INFO_XMMS2)
3998 END OBJ(xmms2_size, INFO_XMMS2)
3999 END OBJ(xmms2_status, INFO_XMMS2)
4000 END OBJ(xmms2_percent, INFO_XMMS2)
4001 END OBJ(xmms2_bar, INFO_XMMS2)
4002 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
4003 END OBJ(xmms2_smart, INFO_XMMS2)
4004 END OBJ(xmms2_playlist, INFO_XMMS2)
4005 END OBJ(xmms2_timesplayed, INFO_XMMS2)
4006 END OBJ(if_xmms2_connected, INFO_XMMS2)
4007 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
4008 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
4010 blockstart[blockdepth] = object_count;
4011 obj->data.ifblock.pos = object_count + 2;
4015 END OBJ(audacious_status, INFO_AUDACIOUS)
4016 END OBJ(audacious_title, INFO_AUDACIOUS)
4018 sscanf(arg, "%d", &info.audacious.max_title_len);
4019 if (info.audacious.max_title_len > 0) {
4020 info.audacious.max_title_len++;
4022 CRIT_ERR("audacious_title: invalid length argument");
4025 END OBJ(audacious_length, INFO_AUDACIOUS)
4026 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
4027 END OBJ(audacious_position, INFO_AUDACIOUS)
4028 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
4029 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
4030 END OBJ(audacious_frequency, INFO_AUDACIOUS)
4031 END OBJ(audacious_channels, INFO_AUDACIOUS)
4032 END OBJ(audacious_filename, INFO_AUDACIOUS)
4033 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
4034 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
4035 END OBJ(audacious_main_volume, INFO_AUDACIOUS)
4036 END OBJ(audacious_bar, INFO_AUDACIOUS)
4037 scan_bar(arg, &obj->a, &obj->b);
4040 END OBJ(bmpx_title, INFO_BMPX)
4041 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
4042 END OBJ(bmpx_artist, INFO_BMPX)
4043 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
4044 END OBJ(bmpx_album, INFO_BMPX)
4045 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
4046 END OBJ(bmpx_track, INFO_BMPX)
4047 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
4048 END OBJ(bmpx_uri, INFO_BMPX)
4049 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
4050 END OBJ(bmpx_bitrate, INFO_BMPX)
4051 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
4057 char *userid = (char *) malloc(20 * sizeof(char));
4058 char *apikey = (char *) malloc(64 * sizeof(char));
4059 char *charid = (char *) malloc(20 * sizeof(char));
4061 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
4062 obj->data.eve.charid = charid;
4063 obj->data.eve.userid = userid;
4064 obj->data.eve.apikey = apikey;
4068 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
4074 int argc, delay, act_par;
4075 char *uri = (char *) malloc(128 * sizeof(char));
4076 char *action = (char *) malloc(64 * sizeof(char));
4078 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
4080 obj->data.rss.uri = uri;
4081 obj->data.rss.delay = delay;
4082 obj->data.rss.action = action;
4083 obj->data.rss.act_par = act_par;
4087 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
4093 if (scan_hddtemp(arg, &obj->data.hddtemp.dev,
4094 &obj->data.hddtemp.addr, &obj->data.hddtemp.port)) {
4095 ERR("hddtemp needs arguments");
4096 obj->type = OBJ_text;
4097 obj->data.s = strndup("${hddtemp}", text_buffer_size);
4098 obj->data.hddtemp.update_time = 0;
4100 obj->data.hddtemp.temp = NULL;
4102 #ifdef TCP_PORT_MONITOR
4103 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
4104 int argc, port_begin, port_end, item, connection_index;
4107 memset(itembuf, 0, sizeof(itembuf));
4108 connection_index = 0;
4109 /* massive argument checking */
4111 CRIT_ERR("tcp_portmon: needs arguments");
4113 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
4115 if ((argc != 3) && (argc != 4)) {
4116 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
4118 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
4119 || (port_end > 65535)) {
4120 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
4122 if (port_begin > port_end) {
4123 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
4125 if (strncmp(itembuf, "count", 31) == EQUAL) {
4127 } else if (strncmp(itembuf, "rip", 31) == EQUAL) {
4129 } else if (strncmp(itembuf, "rhost", 31) == EQUAL) {
4131 } else if (strncmp(itembuf, "rport", 31) == EQUAL) {
4133 } else if (strncmp(itembuf, "rservice", 31) == EQUAL) {
4134 item = REMOTESERVICE;
4135 } else if (strncmp(itembuf, "lip", 31) == EQUAL) {
4137 } else if (strncmp(itembuf, "lhost", 31) == EQUAL) {
4139 } else if (strncmp(itembuf, "lport", 31) == EQUAL) {
4141 } else if (strncmp(itembuf, "lservice", 31) == EQUAL) {
4142 item = LOCALSERVICE;
4144 CRIT_ERR("tcp_portmon: invalid item specified");
4146 if ((argc == 3) && (item != COUNT)) {
4147 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
4150 if ((argc == 4) && (connection_index < 0)) {
4151 CRIT_ERR("tcp_portmon: connection index must be non-negative");
4153 /* ok, args looks good. save the text object data */
4154 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
4155 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
4156 obj->data.tcp_port_monitor.item = item;
4157 obj->data.tcp_port_monitor.connection_index = connection_index;
4159 /* if the port monitor collection hasn't been created,
4160 * we must create it */
4161 if (!info.p_tcp_port_monitor_collection) {
4162 info.p_tcp_port_monitor_collection =
4163 create_tcp_port_monitor_collection();
4164 if (!info.p_tcp_port_monitor_collection) {
4165 CRIT_ERR("tcp_portmon: unable to create port monitor "
4170 /* if a port monitor for this port does not exist,
4171 * create one and add it to the collection */
4172 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
4173 port_begin, port_end) == NULL) {
4174 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
4175 port_end, &tcp_port_monitor_args);
4178 CRIT_ERR("tcp_portmon: unable to create port monitor");
4180 /* add the newly created monitor to the collection */
4181 if (insert_tcp_port_monitor_into_collection(
4182 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
4183 CRIT_ERR("tcp_portmon: unable to add port monitor to "
4188 END OBJ(entropy_avail, INFO_ENTROPY)
4189 END OBJ(entropy_poolsize, INFO_ENTROPY)
4190 END OBJ(entropy_bar, INFO_ENTROPY)
4191 scan_bar(arg, &obj->a, &obj->b);
4195 obj->data.scroll.step = 1;
4196 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n1) > 0) {
4197 if (sscanf(arg + n1, "%u %n", &obj->data.scroll.step, &n2) > 0)
4199 obj->data.scroll.text = strndup(arg + n1, text_buffer_size);
4200 obj->data.scroll.start = 0;
4202 CRIT_ERR("scroll needs arguments: <length> [<step>] <text>");
4207 CRIT_ERR("nvidia needs an argument\n");
4208 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
4209 CRIT_ERR("nvidia: invalid argument"
4210 " specified: '%s'\n", arg);
4216 ERR("unknown variable %s", s);
4217 obj->type = OBJ_text;
4218 snprintf(buf, 256, "${%s}", s);
4219 obj->data.s = strndup(buf, text_buffer_size);
4226 static struct text_object *create_plain_text(const char *s)
4228 struct text_object *obj;
4230 if (s == NULL || *s == '\0') {
4234 obj = new_text_object_internal();
4236 obj->type = OBJ_text;
4237 obj->data.s = strndup(s, text_buffer_size);
4241 /* backslash_escape - do the actual substitution task for template objects
4243 * The field templates is used for substituting the \N occurences. Set it to
4244 * NULL to leave them as they are.
4246 static char *backslash_escape(const char *src, char **templates, unsigned int template_count)
4250 int dup_idx = 0, dup_len;
4252 dup_len = strlen(src);
4255 for (i = 0; i < template_count; i++)
4256 dup_len += strlen(templates[i]);
4259 src_dup = malloc(dup_len * sizeof(char));
4266 if (*(p + 1) == '\\') {
4267 src_dup[dup_idx++] = '\\';
4269 } else if (*(p + 1) == ' ') {
4270 src_dup[dup_idx++] = ' ';
4272 } else if (*(p + 1) == 'n') {
4273 src_dup[dup_idx++] = '\n';
4275 } else if (templates) {
4276 unsigned int tmpl_num;
4278 if ((sscanf(p + 1, "%u%n", &tmpl_num, &digits) <= 0) ||
4279 (tmpl_num > template_count))
4281 sprintf(src_dup + dup_idx, "%s", templates[tmpl_num - 1]);
4282 dup_idx += strlen(templates[tmpl_num - 1]);
4287 src_dup[dup_idx++] = *p;
4292 src_dup[dup_idx] = '\0';
4293 src_dup = realloc(src_dup, (strlen(src_dup) + 1) * sizeof(char));
4296 static struct text_object_list *extract_variable_text_internal(const char *, char);
4298 /* handle_template_object - core logic of the template object
4300 * use config variables like this:
4301 * template1 = "$\1\2"
4302 * template2 = "\1: ${fs_bar 4,100 \2} ${fs_used \2} / ${fs_size \2}"
4304 * and use them like this:
4305 * ${template1 node name}
4306 * ${template2 root /}
4307 * ${template2 cdrom /mnt/cdrom}
4309 static int handle_template_object(struct text_object_list **list,
4310 char allow_threaded, const char *tmpl, const char *args)
4312 char *args_dup, *template_dup, *p, *p_old;
4313 char **argsp = NULL;
4314 unsigned int argcnt = 0, template_idx, i;
4316 struct text_object_list *eval_list;
4318 if ((sscanf(tmpl, "template%u", &template_idx) != 1) ||
4322 args_dup = strdup(args);
4325 while (*p && (*p == ' ' && *(p - 1) != '\\'))
4327 if (*(p - 1) == '\\')
4330 while (*p && (*p != ' ' || *(p - 1) == '\\'))
4336 argsp = realloc(argsp, ++argcnt * sizeof(char *));
4337 argsp[argcnt - 1] = p_old;
4339 for (i = 0; i < argcnt; i++) {
4341 tmp = backslash_escape(argsp[i], NULL, 0);
4342 DBGP2("%s: substituted arg '%s' to '%s'", tmpl, argsp[i], tmp);
4343 sprintf(argsp[i], "%s", tmp);
4347 p = template_dup = strdup(template[template_idx]);
4349 eval_text = backslash_escape(template[template_idx], argsp, argcnt);
4350 DBGP("substituted %s, output is '%s'", tmpl, eval_text);
4352 eval_list = extract_variable_text_internal(eval_text, allow_threaded);
4354 (*list)->text_objects = realloc((*list)->text_objects,
4355 sizeof(struct text_object) *
4356 ((*list)->text_object_count +
4357 eval_list->text_object_count));
4358 memcpy((*list)->text_objects + (*list)->text_object_count,
4359 eval_list->text_objects,
4360 sizeof(struct text_object) *
4361 eval_list->text_object_count);
4362 (*list)->text_object_count += eval_list->text_object_count;
4363 free(eval_list->text_objects);
4373 static struct text_object_list *extract_variable_text_internal(const char *const_p, char allow_threaded)
4375 struct text_object_list *retval;
4376 struct text_object *obj;
4377 char *p, *s, *orig_p;
4380 p = strndup(const_p, max_user_text);
4383 retval = malloc(sizeof(struct text_object_list));
4384 memset(retval, 0, sizeof(struct text_object_list));
4385 retval->text_object_count = 0;
4387 line = global_text_lines;
4395 obj = create_plain_text(s);
4397 // allocate memory for the object
4398 retval->text_objects = realloc(retval->text_objects,
4399 sizeof(struct text_object) *
4400 (retval->text_object_count + 1));
4401 // assign the new object to the end of the list.
4402 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4403 sizeof(struct text_object));
4415 /* variable is either $foo or ${foo} */
4417 unsigned int brl = 1, brr = 0;
4421 while (*p && brl != brr) {
4436 while (*p && (isalnum((int) *p) || *p == '_')) {
4441 /* copy variable to buffer */
4442 len = (p - s > 255) ? 255 : (p - s);
4443 strncpy(buf, s, len);
4453 /* if variable wasn't found in environment, use some special */
4459 if (strchr(buf, ' ')) {
4460 arg = strchr(buf, ' ');
4463 while (isspace((int) *arg)) {
4471 /* lowercase variable name */
4474 *tmp_p = tolower(*tmp_p);
4478 if (!strncmp(buf, "template", 8)) {
4479 if (handle_template_object(&retval, allow_threaded, buf, arg))
4480 printf("Error: handling template '%s' failed for args '%s'\n", buf, arg);
4482 // create new object
4483 obj = construct_text_object(buf, arg,
4484 retval->text_object_count, retval->text_objects, line, allow_threaded);
4486 // allocate memory for the object
4487 retval->text_objects = realloc(retval->text_objects,
4488 sizeof(struct text_object) *
4489 (retval->text_object_count + 1));
4490 // assign the new object to the end of the list.
4492 &retval->text_objects[retval->text_object_count++],
4493 obj, sizeof(struct text_object));
4500 obj = create_plain_text("$");
4502 // allocate memory for the object
4503 retval->text_objects = realloc(retval->text_objects,
4504 sizeof(struct text_object) *
4505 (retval->text_object_count + 1));
4506 // assign the new object to the end of the list.
4507 memcpy(&retval->text_objects[retval->text_object_count++],
4508 obj, sizeof(struct text_object));
4515 obj = create_plain_text(s);
4517 // allocate memory for the object
4518 retval->text_objects = realloc(retval->text_objects,
4519 sizeof(struct text_object) * (retval->text_object_count + 1));
4520 // assign the new object to the end of the list.
4521 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4522 sizeof(struct text_object));
4527 ERR("one or more $endif's are missing");
4534 static void extract_variable_text(const char *p)
4536 free_text_objects(global_text_object_list, 1);
4537 free(global_text_object_list);
4551 global_text_object_list = extract_variable_text_internal(p, 1);
4554 struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
4556 struct text_object_list *object_list =
4557 extract_variable_text_internal(txt, 0);
4559 generate_text_internal(p, max_user_text, object_list, cur);
4563 /* Allows reading from a FIFO (i.e., /dev/xconsole).
4564 * The file descriptor is set to non-blocking which makes this possible.
4566 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
4567 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
4569 #define TAIL_PIPE_BUFSIZE 4096
4573 int fd = obj->data.tail.fd;
4576 char buf[TAIL_PIPE_BUFSIZE];
4577 ssize_t len = read(fd, buf, sizeof(buf));
4581 if (errno != EAGAIN) {
4582 strcpy(obj->data.tail.buffer, "Logfile Read Error");
4583 snprintf(dst, dst_size, "Logfile Read Error");
4587 } else if (len == 0) {
4588 strcpy(obj->data.tail.buffer, "Logfile Empty");
4589 snprintf(dst, dst_size, "Logfile Empty");
4593 for (line_len = 0, i = 0; i < len; i++) {
4597 if (buf[i] == '\n') {
4600 if (obj->data.tail.readlines > 0) {
4605 for (n = 0; obj->data.tail.buffer[n]; n++) {
4606 if (obj->data.tail.buffer[n] == '\n') {
4611 if (++olines < obj->data.tail.wantedlines) {
4617 p = obj->data.tail.buffer + first_line;
4618 pos = n - first_line;
4619 memmove(obj->data.tail.buffer,
4620 obj->data.tail.buffer + first_line, strlen(p));
4621 obj->data.tail.buffer[pos] = 0;
4627 p = buf + last_line;
4629 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
4630 obj->data.tail.buffer[pos + line_len] = 0;
4633 obj->data.tail.readlines = lines;
4641 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
4644 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
4645 void *thread(void *), const char *text)
4647 if (obj->global_mode && info.mail) {
4648 // this means we use info
4649 if (!info.mail->p_timed_thread) {
4650 info.mail->p_timed_thread =
4651 timed_thread_create(thread,
4652 (void *) info.mail, info.mail->interval * 1000000);
4653 if (!info.mail->p_timed_thread) {
4654 ERR("Error creating %s timed thread", text);
4656 timed_thread_register(info.mail->p_timed_thread,
4657 &info.mail->p_timed_thread);
4658 if (timed_thread_run(info.mail->p_timed_thread)) {
4659 ERR("Error running %s timed thread", text);
4663 } else if (obj->data.mail) {
4664 // this means we use obj
4665 if (!obj->data.mail->p_timed_thread) {
4666 obj->data.mail->p_timed_thread =
4667 timed_thread_create(thread,
4668 (void *) obj->data.mail,
4669 obj->data.mail->interval * 1000000);
4670 if (!obj->data.mail->p_timed_thread) {
4671 ERR("Error creating %s timed thread", text);
4673 timed_thread_register(obj->data.mail->p_timed_thread,
4674 &obj->data.mail->p_timed_thread);
4675 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4676 ERR("Error running %s timed thread", text);
4679 return obj->data.mail;
4680 } else if (!obj->a) {
4681 // something is wrong, warn once then stop
4682 ERR("Theres a problem with your %s_unseen settings. "
4683 "Check that the global %s settings are defined "
4684 "properly (line %li).", global_text, global_text, obj->line);
4690 char *format_time(unsigned long timeval, const int width)
4693 unsigned long nt; // narrow time, for speed on 32-bit
4694 unsigned cc; // centiseconds
4695 unsigned nn; // multi-purpose whatever
4698 cc = nt % 100; // centiseconds past second
4699 nt /= 100; // total seconds
4700 nn = nt % 60; // seconds past the minute
4701 nt /= 60; // total minutes
4702 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
4704 return strndup(buf, text_buffer_size);
4706 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
4707 return strndup(buf, text_buffer_size);
4709 nn = nt % 60; // minutes past the hour
4710 nt /= 60; // total hours
4711 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
4712 return strndup(buf, text_buffer_size);
4714 nn = nt; // now also hours
4715 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
4716 return strndup(buf, text_buffer_size);
4718 nn /= 24; // now days
4719 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
4720 return strndup(buf, text_buffer_size);
4722 nn /= 7; // now weeks
4723 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
4724 return strndup(buf, text_buffer_size);
4726 // well shoot, this outta' fit...
4727 return strndup("<inf>", text_buffer_size);
4730 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
4731 //string has to end with \0 and it's length should fit in a int
4733 void remove_deleted_chars(char *string){
4735 while(string[i] != 0){
4736 if(string[i] == BACKSPACE){
4738 strcpy( &(string[i-1]), &(string[i+1]) );
4740 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
4745 static inline void format_media_player_time(char *buf, const int size,
4748 int days, hours, minutes;
4750 days = seconds / (24 * 60 * 60);
4751 seconds %= (24 * 60 * 60);
4752 hours = seconds / (60 * 60);
4753 seconds %= (60 * 60);
4754 minutes = seconds / 60;
4758 snprintf(buf, size, "%i days %i:%02i:%02i", days,
4759 hours, minutes, seconds);
4760 } else if (hours > 0) {
4761 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
4764 snprintf(buf, size, "%i:%02i", minutes, seconds);
4768 static inline double get_barnum(char *buf)
4780 if (sscanf(buf, "%lf", &barnum) == 0) {
4781 ERR("reading execbar value failed (perhaps it's not the "
4782 "correct format?)");
4785 if (barnum > 100.0 || barnum < 0.0) {
4786 ERR("your execbar value is not between 0 and 100, "
4787 "therefore it will be ignored");
4793 static void generate_text_internal(char *p, int p_max_size,
4794 struct text_object_list *text_object_list,
4795 struct information *cur)
4800 char buff_in[p_max_size];
4802 iconv_converting = 0;
4806 for (i = 0; i < text_object_list->text_object_count; i++) {
4807 struct text_object *obj = &(text_object_list->text_objects[i]);
4809 if (p_max_size < 1) {
4813 #define OBJ(a) break; case OBJ_##a:
4815 switch (obj->type) {
4817 ERR("not implemented obj type %d", obj->type);
4820 temp_print(p, p_max_size, get_acpi_temperature(obj->data.i), TEMP_CELSIUS);
4822 #endif /* !__OpenBSD__ */
4825 obj->a = get_freq(p, p_max_size, "%.0f", 1,
4826 obj->data.cpu_index);
4832 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
4833 obj->data.cpu_index);
4835 /* OpenBSD has no such flag (SUSv2) */
4836 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
4837 obj->data.cpu_index);
4841 #if defined(__linux__)
4844 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
4845 obj->data.cpu_index);
4850 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
4851 obj->data.cpu_index);
4856 OBJ(wireless_essid) {
4857 snprintf(p, p_max_size, "%s", obj->data.net->essid);
4859 OBJ(wireless_mode) {
4860 snprintf(p, p_max_size, "%s", obj->data.net->mode);
4862 OBJ(wireless_bitrate) {
4863 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
4866 snprintf(p, p_max_size, "%s", obj->data.net->ap);
4868 OBJ(wireless_link_qual) {
4869 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
4870 obj->data.net->link_qual);
4872 OBJ(wireless_link_qual_max) {
4873 spaced_print(p, p_max_size, "%d", 4,
4874 "wireless_link_qual_max", obj->data.net->link_qual_max);
4876 OBJ(wireless_link_qual_perc) {
4877 if (obj->data.net->link_qual_max > 0) {
4878 spaced_print(p, p_max_size, "%.0f", 5,
4879 "wireless_link_qual_perc",
4880 (double) obj->data.net->link_qual /
4881 obj->data.net->link_qual_max * 100);
4883 spaced_print(p, p_max_size, "unk", 5,
4884 "wireless_link_qual_perc");
4887 OBJ(wireless_link_bar) {
4888 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4889 obj->data.net->link_qual_max) * 255.0);
4891 #endif /* HAVE_IWLIB */
4893 #endif /* __linux__ */
4897 get_adt746x_cpu(p, p_max_size);
4900 get_adt746x_fan(p, p_max_size);
4903 get_acpi_fan(p, p_max_size);
4905 OBJ(acpiacadapter) {
4906 get_acpi_ac_adapter(p, p_max_size);
4909 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4912 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4914 OBJ(battery_percent) {
4915 spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
4916 pad_percents, get_battery_perct(obj->data.s));
4919 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4921 #endif /* __OpenBSD__ */
4924 human_readable(cur->buffers * 1024, p, 255, "buffers");
4927 human_readable(cur->cached * 1024, p, 255, "buffers");
4930 if (obj->data.cpu_index > info.cpu_count) {
4931 printf("obj->data.cpu_index %i info.cpu_count %i",
4932 obj->data.cpu_index, info.cpu_count);
4933 CRIT_ERR("attempting to use more CPUs than you have!");
4935 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4936 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4939 new_bar(p, obj->a, obj->b,
4940 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4943 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4944 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4945 100, 1, obj->showaslog);
4948 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
4949 obj->e, 1, obj->showaslog);
4952 new_fg(p, obj->data.l);
4984 OBJ(conky_version) {
4985 snprintf(p, p_max_size, "%s", VERSION);
4987 OBJ(conky_build_date) {
4988 snprintf(p, p_max_size, "%s", BUILD_DATE);
4990 OBJ(conky_build_arch) {
4991 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4993 #if defined(__linux__)
4995 snprintf(p, p_max_size, "%s",
4996 get_disk_protect_queue(obj->data.s));
4999 snprintf(p, p_max_size, "%s", i8k.version);
5002 snprintf(p, p_max_size, "%s", i8k.bios);
5005 snprintf(p, p_max_size, "%s", i8k.serial);
5010 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
5011 temp_print(p, p_max_size, (double)cpu_temp, TEMP_CELSIUS);
5013 OBJ(i8k_left_fan_status) {
5014 int left_fan_status;
5016 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
5017 if (left_fan_status == 0) {
5018 snprintf(p, p_max_size, "off");
5020 if (left_fan_status == 1) {
5021 snprintf(p, p_max_size, "low");
5023 if (left_fan_status == 2) {
5024 snprintf(p, p_max_size, "high");
5027 OBJ(i8k_right_fan_status) {
5028 int right_fan_status;
5030 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
5031 if (right_fan_status == 0) {
5032 snprintf(p, p_max_size, "off");
5034 if (right_fan_status == 1) {
5035 snprintf(p, p_max_size, "low");
5037 if (right_fan_status == 2) {
5038 snprintf(p, p_max_size, "high");
5041 OBJ(i8k_left_fan_rpm) {
5042 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
5044 OBJ(i8k_right_fan_rpm) {
5045 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
5047 OBJ(i8k_ac_status) {
5050 sscanf(i8k.ac_status, "%d", &ac_status);
5051 if (ac_status == -1) {
5052 snprintf(p, p_max_size, "disabled (read i8k docs)");
5054 if (ac_status == 0) {
5055 snprintf(p, p_max_size, "off");
5057 if (ac_status == 1) {
5058 snprintf(p, p_max_size, "on");
5061 OBJ(i8k_buttons_status) {
5062 snprintf(p, p_max_size, "%s", i8k.buttons_status);
5065 get_ibm_acpi_fan(p, p_max_size);
5068 get_ibm_acpi_temps();
5069 temp_print(p, p_max_size,
5070 ibm_acpi.temps[obj->data.sensor], TEMP_CELSIUS);
5073 get_ibm_acpi_volume(p, p_max_size);
5075 OBJ(ibm_brightness) {
5076 get_ibm_acpi_brightness(p, p_max_size);
5079 if ((obj->data.ifblock.s)
5080 && (!interface_up(obj->data.ifblock.s))) {
5081 i = obj->data.ifblock.pos;
5088 if (!cur->gw_info.count) {
5089 i = obj->data.ifblock.pos;
5096 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
5099 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
5102 snprintf(p, p_max_size, "%d", get_laptop_mode());
5105 get_powerbook_batt_info(p, p_max_size, obj->data.i);
5107 #endif /* __linux__ */
5110 OBJ(obsd_sensors_temp) {
5111 obsd_sensors.device = sensor_device;
5112 update_obsd_sensors();
5113 temp_print(p, p_max_size,
5114 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor],
5117 OBJ(obsd_sensors_fan) {
5118 obsd_sensors.device = sensor_device;
5119 update_obsd_sensors();
5120 snprintf(p, p_max_size, "%d",
5121 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
5123 OBJ(obsd_sensors_volt) {
5124 obsd_sensors.device = sensor_device;
5125 update_obsd_sensors();
5126 snprintf(p, p_max_size, "%.2f",
5127 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
5130 get_obsd_vendor(p, p_max_size);
5133 get_obsd_product(p, p_max_size);
5135 #endif /* __OpenBSD__ */
5139 new_font(p, obj->data.s);
5142 /* TODO: move this correction from kB to kB/s elsewhere
5143 * (or get rid of it??) */
5145 if (obj->data.diskio) {
5147 (obj->data.diskio->current / update_interval) * 1024LL,
5148 p, p_max_size, "diskio");
5150 human_readable(info.diskio_value * 1024LL, p, p_max_size,
5155 if (obj->data.diskio) {
5156 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
5159 human_readable(info.diskio_write_value * 1024LL, p, p_max_size,
5164 if (obj->data.diskio) {
5165 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
5168 human_readable(info.diskio_read_value * 1024LL, p, p_max_size,
5173 if (obj->data.diskio) {
5174 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5175 obj->data.diskio->current, obj->e, 1, obj->showaslog);
5177 new_graph(p, obj->a, obj->b, obj->c, obj->d, info.diskio_value,
5178 obj->e, 1, obj->showaslog);
5181 OBJ(diskiograph_read) {
5182 if (obj->data.diskio) {
5183 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5184 obj->data.diskio->current_read, obj->e, 1, obj->showaslog);
5186 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5187 info.diskio_read_value, obj->e, 1, obj->showaslog);
5190 OBJ(diskiograph_write) {
5191 if (obj->data.diskio) {
5192 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5193 obj->data.diskio->current_write, obj->e, 1, obj->showaslog);
5195 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5196 info.diskio_write_value, obj->e, 1, obj->showaslog);
5200 spaced_print(p, p_max_size, "%d", 6, "downspeed",
5201 round_to_int(obj->data.net->recv_speed / 1024));
5204 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
5205 obj->data.net->recv_speed / 1024.0);
5207 OBJ(downspeedgraph) {
5208 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5209 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog);
5213 i = obj->data.ifblock.pos - 1;
5223 if ((obj->data.net->addr.sa_data[2] & 255) == 0
5224 && (obj->data.net->addr.sa_data[3] & 255) == 0
5225 && (obj->data.net->addr.sa_data[4] & 255) == 0
5226 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
5227 snprintf(p, p_max_size, "No Address");
5229 snprintf(p, p_max_size, "%u.%u.%u.%u",
5230 obj->data.net->addr.sa_data[2] & 255,
5231 obj->data.net->addr.sa_data[3] & 255,
5232 obj->data.net->addr.sa_data[4] & 255,
5233 obj->data.net->addr.sa_data[5] & 255);
5236 #if defined(__linux__)
5238 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
5240 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
5241 strcpy(p, obj->data.net->addrs);
5244 strcpy(p, "0.0.0.0");
5246 #endif /* __linux__ */
5248 #if defined(IMLIB2) && defined(X11)
5253 Imlib_Image image, buffer;
5255 image = imlib_load_image(obj->data.s);
5256 imlib_context_set_image(image);
5260 w = imlib_image_get_width();
5261 h = imlib_image_get_height();
5262 buffer = imlib_create_image(w, h);
5263 imlib_context_set_display(display);
5264 imlib_context_set_drawable(window.drawable);
5265 imlib_context_set_colormap(DefaultColormap(display,
5267 imlib_context_set_visual(DefaultVisual(display,
5269 imlib_context_set_image(buffer);
5270 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
5271 text_start_x, text_start_y, w, h);
5272 imlib_render_image_on_drawable(text_start_x,
5275 imlib_context_set_image(image);
5283 read_exec(obj->data.s, p, text_buffer_size);
5284 remove_deleted_chars(p);
5287 struct information *tmp_info;
5288 struct text_object_list *text_objects;
5290 read_exec(obj->data.s, p, text_buffer_size);
5292 tmp_info = malloc(sizeof(struct information));
5293 memcpy(tmp_info, cur, sizeof(struct information));
5294 text_objects = parse_conky_vars(p, p, tmp_info);
5296 free_text_objects(text_objects, 0);
5303 read_exec(obj->data.s, p, text_buffer_size);
5304 barnum = get_barnum(p);
5306 if (barnum >= 0.0) {
5308 new_bar(p, 0, 4, round_to_int(barnum * 255.0));
5312 char showaslog = FALSE;
5315 if(strncasecmp(obj->data.s, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
5317 read_exec(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), p, text_buffer_size);
5318 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
5319 read_exec(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), p, text_buffer_size);
5321 read_exec(obj->data.s, p, text_buffer_size);
5323 barnum = get_barnum(p);
5325 if (barnum >= 0.0) {
5326 new_graph(p, 0, 25, obj->c, obj->d, round_to_int(barnum),
5331 if (current_update_time - obj->data.execi.last_update
5332 >= obj->data.execi.interval) {
5335 read_exec(obj->data.execi.cmd, p, text_buffer_size);
5336 barnum = get_barnum(p);
5338 if (barnum >= 0.0) {
5339 obj->f = 255 * barnum / 100.0;
5341 obj->data.execi.last_update = current_update_time;
5343 new_bar(p, 0, 4, round_to_int(obj->f));
5346 if (current_update_time - obj->data.execi.last_update
5347 >= obj->data.execi.interval) {
5350 read_exec(obj->data.execi.cmd, p, text_buffer_size);
5351 barnum = get_barnum(p);
5353 if (barnum >= 0.0) {
5356 obj->data.execi.last_update = current_update_time;
5358 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1, FALSE);
5361 if (current_update_time - obj->data.execi.last_update
5362 >= obj->data.execi.interval
5363 && obj->data.execi.interval != 0) {
5364 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
5366 obj->data.execi.last_update = current_update_time;
5368 snprintf(p, text_buffer_size, "%s", obj->data.execi.buffer);
5371 struct text_object_list *text_objects = 0;
5372 struct information *tmp_info =
5373 malloc(sizeof(struct information));
5374 memcpy(tmp_info, cur, sizeof(struct information));
5376 if (current_update_time - obj->data.execi.last_update
5377 < obj->data.execi.interval
5378 || obj->data.execi.interval == 0) {
5379 text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info);
5381 char *output = obj->data.execi.buffer;
5382 FILE *fp = popen(obj->data.execi.cmd, "r");
5383 int length = fread(output, 1, text_buffer_size, fp);
5387 output[length] = '\0';
5388 if (length > 0 && output[length - 1] == '\n') {
5389 output[length - 1] = '\0';
5392 text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info);
5393 obj->data.execi.last_update = current_update_time;
5395 free_text_objects(text_objects, 0);
5400 if (!obj->data.texeci.p_timed_thread) {
5401 obj->data.texeci.p_timed_thread =
5402 timed_thread_create(&threaded_exec,
5403 (void *) obj, obj->data.texeci.interval * 1000000);
5404 if (!obj->data.texeci.p_timed_thread) {
5405 ERR("Error creating texeci timed thread");
5407 timed_thread_register(obj->data.texeci.p_timed_thread,
5408 &obj->data.texeci.p_timed_thread);
5409 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
5410 ERR("Error running texeci timed thread");
5413 timed_thread_lock(obj->data.texeci.p_timed_thread);
5414 snprintf(p, text_buffer_size, "%s", obj->data.texeci.buffer);
5415 timed_thread_unlock(obj->data.texeci.p_timed_thread);
5417 #endif /* HAVE_POPEN */
5419 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
5421 if (mail && mail->p_timed_thread) {
5422 timed_thread_lock(mail->p_timed_thread);
5423 snprintf(p, p_max_size, "%lu", mail->unseen);
5424 timed_thread_unlock(mail->p_timed_thread);
5427 OBJ(imap_messages) {
5428 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
5430 if (mail && mail->p_timed_thread) {
5431 timed_thread_lock(mail->p_timed_thread);
5432 snprintf(p, p_max_size, "%lu", mail->messages);
5433 timed_thread_unlock(mail->p_timed_thread);
5437 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
5439 if (mail && mail->p_timed_thread) {
5440 timed_thread_lock(mail->p_timed_thread);
5441 snprintf(p, p_max_size, "%lu", mail->unseen);
5442 timed_thread_unlock(mail->p_timed_thread);
5446 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
5448 if (mail && mail->p_timed_thread) {
5449 timed_thread_lock(mail->p_timed_thread);
5450 snprintf(p, p_max_size, "%.1f",
5451 mail->used / 1024.0 / 1024.0);
5452 timed_thread_unlock(mail->p_timed_thread);
5456 if (obj->data.fs != NULL) {
5457 if (obj->data.fs->size == 0) {
5458 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5460 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5461 (int) (255 - obj->data.fsbar.fs->avail * 255 /
5462 obj->data.fs->size));
5467 if (obj->data.fs != NULL) {
5468 human_readable(obj->data.fs->avail, p, 255, "fs_free");
5472 if (obj->data.fs != NULL) {
5473 if (obj->data.fs->size) {
5474 spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
5475 pad_percents, (int) ((obj->data.fs->avail * 100) /
5476 obj->data.fs->size));
5478 snprintf(p, p_max_size, "0");
5483 if (obj->data.fs != NULL) {
5484 human_readable(obj->data.fs->size, p, 255, "fs_size");
5488 if (obj->data.fs != NULL)
5489 snprintf(p, p_max_size, "%s", obj->data.fs->type);
5492 if (obj->data.fs != NULL) {
5493 human_readable(obj->data.fs->size - (obj->data.fs->free
5494 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
5499 if (obj->data.fs != NULL) {
5500 if (obj->data.fs->size == 0) {
5501 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5503 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5504 (int) (obj->data.fsbar.fs->avail * 255 /
5505 obj->data.fs->size));
5510 if (obj->data.fs != NULL) {
5511 if (obj->data.fs->size) {
5512 spaced_print(p, 4, "%*d", 4, "fs_used_perc",
5513 pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
5514 obj->data.fs->size)));
5516 snprintf(p, p_max_size, "0");
5521 float *v = info.loadavg;
5523 if (obj->data.loadavg[2]) {
5524 snprintf(p, p_max_size, "%.2f %.2f %.2f",
5525 v[obj->data.loadavg[0] - 1],
5526 v[obj->data.loadavg[1] - 1],
5527 v[obj->data.loadavg[2] - 1]);
5528 } else if (obj->data.loadavg[1]) {
5529 snprintf(p, p_max_size, "%.2f %.2f",
5530 v[obj->data.loadavg[0] - 1],
5531 v[obj->data.loadavg[1] - 1]);
5532 } else if (obj->data.loadavg[0]) {
5533 snprintf(p, p_max_size, "%.2f",
5534 v[obj->data.loadavg[0] - 1]);
5538 new_goto(p, obj->data.i);
5541 new_tab(p, obj->data.pair.a, obj->data.pair.b);
5544 new_hr(p, obj->data.i);
5547 if (cur->nameserver_info.nscount > obj->data.i)
5548 snprintf(p, p_max_size, "%s",
5549 cur->nameserver_info.ns_list[obj->data.i]);
5553 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
5554 snprintf(p, p_max_size, "%s", skill);
5559 PRSS *data = get_rss_info(obj->data.rss.uri,
5560 obj->data.rss.delay);
5564 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
5566 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
5568 // remove trailing new line if one exists
5569 if (str[strlen(str) - 1] == '\n') {
5570 str[strlen(str) - 1] = 0;
5572 snprintf(p, p_max_size, "%s", str);
5573 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
5574 if (obj->data.rss.act_par < data->item_count) {
5575 str = data->items[obj->data.rss.act_par].title;
5576 // remove trailing new line if one exists
5577 if (str[strlen(str) - 1] == '\n') {
5578 str[strlen(str) - 1] = 0;
5580 snprintf(p, p_max_size, "%s", str);
5582 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
5583 if (obj->data.rss.act_par < data->item_count) {
5585 data->items[obj->data.rss.act_par].description;
5586 // remove trailing new line if one exists
5587 if (str[strlen(str) - 1] == '\n') {
5588 str[strlen(str) - 1] = 0;
5590 snprintf(p, p_max_size, "%s", str);
5592 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
5593 if (data->item_count > 0) {
5599 if (obj->data.rss.act_par > data->item_count) {
5600 show = data->item_count;
5602 show = obj->data.rss.act_par;
5604 for (itmp = 0; itmp < show; itmp++) {
5605 PRSS_Item *item = &data->items[itmp];
5609 // don't add new line before first item
5611 strncat(p, "\n", p_max_size);
5613 /* remove trailing new line if one exists,
5614 * we have our own */
5615 if (str[strlen(str) - 1] == '\n') {
5616 str[strlen(str) - 1] = 0;
5618 strncat(p, str, p_max_size);
5630 if (obj->data.hddtemp.update_time < current_update_time - 30) {
5631 if (obj->data.hddtemp.temp)
5632 free(obj->data.hddtemp.temp);
5633 obj->data.hddtemp.temp = get_hddtemp_info(obj->data.hddtemp.dev,
5634 obj->data.hddtemp.addr, obj->data.hddtemp.port);
5635 obj->data.hddtemp.update_time = current_update_time;
5637 if (!obj->data.hddtemp.temp) {
5638 snprintf(p, p_max_size, "N/A");
5640 val = strtol(obj->data.hddtemp.temp + 1, &endptr, 10);
5641 unit = obj->data.hddtemp.temp[0];
5643 if (*endptr != '\0')
5644 snprintf(p, p_max_size, "N/A");
5645 else if (unit == 'C')
5646 temp_print(p, p_max_size, (double)val, TEMP_CELSIUS);
5647 else if (unit == 'F')
5648 temp_print(p, p_max_size, (double)val, TEMP_FAHRENHEIT);
5650 snprintf(p, p_max_size, "N/A");
5655 new_offset(p, obj->data.i);
5658 new_voffset(p, obj->data.i);
5664 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5665 obj->data.sysfs.devtype, obj->data.sysfs.type);
5667 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
5668 temp_print(p, p_max_size, r, TEMP_CELSIUS);
5669 } else if (r >= 100.0 || r == 0) {
5670 snprintf(p, p_max_size, "%d", (int) r);
5672 snprintf(p, p_max_size, "%.1f", r);
5678 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5679 obj->data.sysfs.devtype, obj->data.sysfs.type);
5681 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
5682 temp_print(p, p_max_size, r, TEMP_CELSIUS);
5683 } else if (r >= 100.0 || r == 0) {
5684 snprintf(p, p_max_size, "%d", (int) r);
5686 snprintf(p, p_max_size, "%.1f", r);
5692 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5693 obj->data.sysfs.devtype, obj->data.sysfs.type);
5695 if (!strncmp(obj->data.sysfs.type, "temp", 4)) {
5696 temp_print(p, p_max_size, r, TEMP_CELSIUS);
5697 } else if (r >= 100.0 || r == 0) {
5698 snprintf(p, p_max_size, "%d", (int) r);
5700 snprintf(p, p_max_size, "%.1f", r);
5703 #endif /* !__OpenBSD__ */
5705 new_alignr(p, obj->data.i);
5708 new_alignc(p, obj->data.i);
5711 struct text_object_list *text_objects;
5712 struct information *tmp_info =
5713 malloc(sizeof(struct information));
5714 memcpy(tmp_info, cur, sizeof(struct information));
5715 text_objects = parse_conky_vars(obj->data.ifblock.s, p, tmp_info);
5717 if (strlen(p) != 0) {
5718 i = obj->data.ifblock.pos;
5724 free_text_objects(text_objects, 0);
5731 if ((obj->data.ifblock.s)
5732 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
5733 i = obj->data.ifblock.pos;
5736 if (obj->data.ifblock.str) {
5737 if (!check_contains(obj->data.ifblock.s,
5738 obj->data.ifblock.str)) {
5739 i = obj->data.ifblock.pos;
5750 if ((obj->data.ifblock.s)
5751 && (!check_mount(obj->data.ifblock.s))) {
5752 i = obj->data.ifblock.pos;
5759 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5760 i = obj->data.ifblock.pos;
5766 #if defined(__linux__)
5768 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
5772 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5775 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5780 human_readable(cur->mem * 1024, p, 255, "mem");
5783 human_readable(cur->memeasyfree * 1024, p, 255, "memeasyfree");
5786 human_readable(cur->memfree * 1024, p, 255, "memfree");
5789 human_readable(cur->memmax * 1024, p, 255, "memmax");
5793 spaced_print(p, p_max_size, "%*llu", 4, "memperc",
5794 pad_percents, cur->mem * 100 / cur->memmax);
5798 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5799 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5802 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5803 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5804 100, 1, obj->showaslog);
5809 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5812 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5815 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5818 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5819 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5822 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5823 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5826 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5827 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5831 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
5833 OBJ(monitor_number) {
5834 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
5840 update_mail_count(&obj->data.local_mail);
5841 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5844 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5846 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5849 update_mail_count(&obj->data.local_mail);
5850 snprintf(p, p_max_size, "%d",
5851 obj->data.local_mail.new_mail_count);
5854 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5857 new_outline(p, obj->data.l);
5860 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5862 OBJ(running_processes) {
5863 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5866 snprintf(p, p_max_size, "%s", obj->data.s);
5869 new_bg(p, obj->data.l);
5872 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5875 human_readable(cur->swap * 1024, p, 255, "swap");
5878 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5881 if (cur->swapmax == 0) {
5882 strncpy(p, "No swap", p_max_size);
5884 spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
5885 pad_percents, cur->swap * 100 / cur->swapmax);
5889 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5890 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5893 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5896 time_t t = time(NULL);
5897 struct tm *tm = localtime(&t);
5899 setlocale(LC_TIME, "");
5900 strftime(p, p_max_size, obj->data.s, tm);
5903 time_t t = time(NULL);
5904 struct tm *tm = gmtime(&t);
5906 strftime(p, p_max_size, obj->data.s, tm);
5913 if (obj->data.tztime.tz) {
5914 oldTZ = getenv("TZ");
5915 setenv("TZ", obj->data.tztime.tz, 1);
5921 setlocale(LC_TIME, "");
5922 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5924 setenv("TZ", oldTZ, 1);
5929 // Needless to free oldTZ since getenv gives ptr to static data
5932 human_readable(obj->data.net->recv, p, 255, "totaldown");
5935 human_readable(obj->data.net->trans, p, 255, "totalup");
5938 snprintf(p, p_max_size, "%d", total_updates);
5941 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5942 round_to_int(obj->data.net->trans_speed / 1024));
5945 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5946 obj->data.net->trans_speed / 1024.0);
5949 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5950 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog);
5953 format_seconds_short(p, p_max_size, (int) cur->uptime);
5956 format_seconds(p, p_max_size, (int) cur->uptime);
5959 snprintf(p, p_max_size, "%s", cur->users.names);
5962 snprintf(p, p_max_size, "%s", cur->users.terms);
5965 snprintf(p, p_max_size, "%s", cur->users.times);
5968 snprintf(p, p_max_size, "%d", cur->users.number);
5970 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5971 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5975 msg = get_apm_adapter();
5976 snprintf(p, p_max_size, "%s", msg);
5979 OBJ(apm_battery_life) {
5982 msg = get_apm_battery_life();
5983 snprintf(p, p_max_size, "%s", msg);
5986 OBJ(apm_battery_time) {
5989 msg = get_apm_battery_time();
5990 snprintf(p, p_max_size, "%s", msg);
5993 #endif /* __FreeBSD__ __OpenBSD__ */
5997 int len = obj->data.i;
5998 if (len == 0 || len > p_max_size)
6000 snprintf(p, len, "%s", cur->mpd.title);
6003 snprintf(p, p_max_size, "%s", cur->mpd.artist);
6006 snprintf(p, p_max_size, "%s", cur->mpd.album);
6009 snprintf(p, p_max_size, "%s", cur->mpd.random);
6012 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
6015 snprintf(p, p_max_size, "%s", cur->mpd.track);
6018 snprintf(p, p_max_size, "%s", cur->mpd.name);
6021 snprintf(p, p_max_size, "%s", cur->mpd.file);
6024 snprintf(p, p_max_size, "%i", cur->mpd.volume);
6027 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
6030 snprintf(p, p_max_size, "%s", cur->mpd.status);
6033 format_media_player_time(p, p_max_size, cur->mpd.elapsed);
6036 format_media_player_time(p, p_max_size, cur->mpd.length);
6039 spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
6040 pad_percents, (int) (cur->mpd.progress * 100));
6043 new_bar(p, obj->data.pair.a, obj->data.pair.b,
6044 (int) (cur->mpd.progress * 255.0f));
6047 int len = obj->data.i;
6048 if (len == 0 || len > p_max_size)
6051 memset(p, 0, p_max_size);
6052 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
6053 && *cur->mpd.title) {
6054 snprintf(p, len, "%s - %s", cur->mpd.artist,
6056 } else if (cur->mpd.title && *cur->mpd.title) {
6057 snprintf(p, len, "%s", cur->mpd.title);
6058 } else if (cur->mpd.artist && *cur->mpd.artist) {
6059 snprintf(p, len, "%s", cur->mpd.artist);
6060 } else if (cur->mpd.file && *cur->mpd.file) {
6061 snprintf(p, len, "%s", cur->mpd.file);
6066 OBJ(if_mpd_playing) {
6067 if (cur->mpd.is_playing) {
6070 i = obj->data.ifblock.pos;
6078 snprintf(p, p_max_size, "%s", (cur->moc.state ? cur->moc.state : "??"));
6081 snprintf(p, p_max_size, "%s", (cur->moc.file ? cur->moc.file : "no file"));
6084 snprintf(p, p_max_size, "%s", (cur->moc.title ? cur->moc.title : "no title"));
6087 snprintf(p, p_max_size, "%s", (cur->moc.artist ? cur->moc.artist : "no artist"));
6090 snprintf(p, p_max_size, "%s", (cur->moc.song ? cur->moc.song : "no song"));
6093 snprintf(p, p_max_size, "%s", (cur->moc.album ? cur->moc.album : "no album"));
6095 OBJ(moc_totaltime) {
6096 snprintf(p, p_max_size, "%s", (cur->moc.totaltime ? cur->moc.totaltime : "0:00"));
6099 snprintf(p, p_max_size, "%s", (cur->moc.timeleft ? cur->moc.timeleft : "0:00"));
6102 snprintf(p, p_max_size, "%s", (cur->moc.curtime ? cur->moc.curtime : "0:00"));
6105 snprintf(p, p_max_size, "%s", (cur->moc.bitrate ? cur->moc.bitrate : "0Kbps"));
6108 snprintf(p, p_max_size, "%s", (cur->moc.rate ? cur->moc.rate : "0KHz"));
6113 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
6116 snprintf(p, p_max_size, "%s", cur->xmms2.album);
6119 snprintf(p, p_max_size, "%s", cur->xmms2.title);
6122 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
6124 OBJ(xmms2_comment) {
6125 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
6128 snprintf(p, p_max_size, "%s", cur->xmms2.url);
6131 snprintf(p, p_max_size, "%s", cur->xmms2.status);
6134 snprintf(p, p_max_size, "%s", cur->xmms2.date);
6136 OBJ(xmms2_tracknr) {
6137 if (cur->xmms2.tracknr != -1) {
6138 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
6141 OBJ(xmms2_bitrate) {
6142 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
6145 snprintf(p, p_max_size, "%u", cur->xmms2.id);
6148 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
6150 OBJ(xmms2_elapsed) {
6151 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
6152 (cur->xmms2.elapsed / 1000) % 60);
6154 OBJ(xmms2_duration) {
6155 snprintf(p, p_max_size, "%02d:%02d",
6156 cur->xmms2.duration / 60000,
6157 (cur->xmms2.duration / 1000) % 60);
6159 OBJ(xmms2_percent) {
6160 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
6163 new_bar(p, obj->data.pair.a, obj->data.pair.b,
6164 (int) (cur->xmms2.progress * 255.0f));
6166 OBJ(xmms2_playlist) {
6167 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
6169 OBJ(xmms2_timesplayed) {
6170 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
6173 if (strlen(cur->xmms2.title) < 2
6174 && strlen(cur->xmms2.title) < 2) {
6175 snprintf(p, p_max_size, "%s", cur->xmms2.url);
6177 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
6181 OBJ(if_xmms2_connected) {
6182 if (cur->xmms2_conn_state == 1) {
6185 i = obj->data.ifblock.pos;
6191 OBJ(audacious_status) {
6192 snprintf(p, p_max_size, "%s",
6193 cur->audacious.items[AUDACIOUS_STATUS]);
6195 OBJ(audacious_title) {
6196 snprintf(p, cur->audacious.max_title_len > 0
6197 ? cur->audacious.max_title_len : p_max_size, "%s",
6198 cur->audacious.items[AUDACIOUS_TITLE]);
6200 OBJ(audacious_length) {
6201 snprintf(p, p_max_size, "%s",
6202 cur->audacious.items[AUDACIOUS_LENGTH]);
6204 OBJ(audacious_length_seconds) {
6205 snprintf(p, p_max_size, "%s",
6206 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
6208 OBJ(audacious_position) {
6209 snprintf(p, p_max_size, "%s",
6210 cur->audacious.items[AUDACIOUS_POSITION]);
6212 OBJ(audacious_position_seconds) {
6213 snprintf(p, p_max_size, "%s",
6214 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
6216 OBJ(audacious_bitrate) {
6217 snprintf(p, p_max_size, "%s",
6218 cur->audacious.items[AUDACIOUS_BITRATE]);
6220 OBJ(audacious_frequency) {
6221 snprintf(p, p_max_size, "%s",
6222 cur->audacious.items[AUDACIOUS_FREQUENCY]);
6224 OBJ(audacious_channels) {
6225 snprintf(p, p_max_size, "%s",
6226 cur->audacious.items[AUDACIOUS_CHANNELS]);
6228 OBJ(audacious_filename) {
6229 snprintf(p, p_max_size, "%s",
6230 cur->audacious.items[AUDACIOUS_FILENAME]);
6232 OBJ(audacious_playlist_length) {
6233 snprintf(p, p_max_size, "%s",
6234 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
6236 OBJ(audacious_playlist_position) {
6237 snprintf(p, p_max_size, "%s",
6238 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
6240 OBJ(audacious_main_volume) {
6241 snprintf(p, p_max_size, "%s",
6242 cur->audacious.items[AUDACIOUS_MAIN_VOLUME]);
6244 OBJ(audacious_bar) {
6248 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
6249 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
6250 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
6256 snprintf(p, p_max_size, "%s", cur->bmpx.title);
6259 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
6262 snprintf(p, p_max_size, "%s", cur->bmpx.album);
6265 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
6268 snprintf(p, p_max_size, "%i", cur->bmpx.track);
6271 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
6275 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
6278 switch (obj->data.top.type) {
6280 snprintf(p, 16, "%-15s",
6281 cur->cpu[obj->data.top.num]->name);
6284 snprintf(p, 7, "%6.2f",
6285 cur->cpu[obj->data.top.num]->amount);
6288 snprintf(p, 6, "%5i",
6289 cur->cpu[obj->data.top.num]->pid);
6292 snprintf(p, 7, "%6.2f",
6293 cur->cpu[obj->data.top.num]->totalmem);
6296 timeval = format_time(
6297 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
6298 snprintf(p, 10, "%9s", timeval);
6302 human_readable(cur->cpu[obj->data.top.num]->rss,
6306 human_readable(cur->cpu[obj->data.top.num]->vsize,
6310 ERR("Unhandled top data type: %d\n",
6311 obj->data.top.type);
6314 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
6318 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
6321 switch (obj->data.top.type) {
6323 snprintf(p, 16, "%-15s",
6324 cur->memu[obj->data.top.num]->name);
6327 snprintf(p, 7, "%6.2f",
6328 cur->memu[obj->data.top.num]->amount);
6331 snprintf(p, 6, "%5i",
6332 cur->memu[obj->data.top.num]->pid);
6335 snprintf(p, 7, "%6.2f",
6336 cur->memu[obj->data.top.num]->totalmem);
6339 timeval = format_time(
6340 cur->memu[obj->data.top.num]->total_cpu_time,
6342 snprintf(p, 10, "%9s", timeval);
6346 human_readable(cur->cpu[obj->data.top.num]->rss,
6350 human_readable(cur->cpu[obj->data.top.num]->vsize,
6354 ERR("Unhandled top data type: %d\n",
6355 obj->data.top.type);
6358 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
6362 if (current_update_time - obj->data.tail.last_update
6363 < obj->data.tail.interval) {
6364 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6370 obj->data.tail.last_update = current_update_time;
6372 if (obj->data.tail.fd != -1) {
6373 tail_pipe(obj, p, p_max_size);
6377 fp = fopen(obj->data.tail.logfile, "rt");
6380 /* Send one message, but do not consistently spam
6381 * on missing logfiles. */
6382 if (obj->data.tail.readlines != 0) {
6383 ERR("tail logfile failed to open");
6384 strcpy(obj->data.tail.buffer, "Logfile Missing");
6386 obj->data.tail.readlines = 0;
6387 snprintf(p, p_max_size, "Logfile Missing");
6389 obj->data.tail.readlines = 0;
6390 /* -1 instead of 0 to avoid counting a trailing
6392 fseek(fp, -1, SEEK_END);
6393 bsize = ftell(fp) + 1;
6394 for (iter = obj->data.tail.wantedlines; iter > 0;
6396 nl = rev_fcharfind(fp, '\n', iter);
6401 obj->data.tail.readlines = iter;
6402 if (obj->data.tail.readlines
6403 < obj->data.tail.wantedlines) {
6404 fseek(fp, 0, SEEK_SET);
6406 fseek(fp, nl + 1, SEEK_SET);
6409 /* Make sure bsize is at least 1 byte smaller than the
6410 * buffer max size. */
6411 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
6412 fseek(fp, bsize - text_buffer_size * 20 - 1,
6414 bsize = text_buffer_size * 20 - 1;
6416 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
6419 /* Clean up trailing newline, make sure the
6420 * buffer is null terminated. */
6421 if (obj->data.tail.buffer[bsize - 1] == '\n') {
6422 obj->data.tail.buffer[bsize - 1] = '\0';
6424 obj->data.tail.buffer[bsize] = '\0';
6426 snprintf(p, p_max_size, "%s",
6427 obj->data.tail.buffer);
6429 strcpy(obj->data.tail.buffer, "Logfile Empty");
6430 snprintf(p, p_max_size, "Logfile Empty");
6433 } /* if cur_upd_time >= */
6434 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6438 if (current_update_time - obj->data.tail.last_update
6439 < obj->data.tail.interval) {
6440 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6446 obj->data.tail.last_update = current_update_time;
6448 fp = fopen(obj->data.tail.logfile, "rt");
6450 /* Send one message, but do not consistently spam
6451 * on missing logfiles. */
6452 if (obj->data.tail.readlines != 0) {
6453 ERR("head logfile failed to open");
6454 strcpy(obj->data.tail.buffer, "Logfile Missing");
6456 obj->data.tail.readlines = 0;
6457 snprintf(p, p_max_size, "Logfile Missing");
6459 obj->data.tail.readlines = 0;
6460 for (iter = obj->data.tail.wantedlines; iter > 0;
6462 nl = fwd_fcharfind(fp, '\n', iter);
6467 obj->data.tail.readlines = iter;
6468 /* Make sure nl is at least 1 byte smaller than the
6469 * buffer max size. */
6470 if (nl > (long) ((text_buffer_size * 20) - 1)) {
6471 nl = text_buffer_size * 20 - 1;
6473 nl = fread(obj->data.tail.buffer, 1, nl, fp);
6476 /* Clean up trailing newline, make sure the buffer
6477 * is null terminated. */
6478 if (obj->data.tail.buffer[nl - 1] == '\n') {
6479 obj->data.tail.buffer[nl - 1] = '\0';
6481 obj->data.tail.buffer[nl] = '\0';
6483 snprintf(p, p_max_size, "%s",
6484 obj->data.tail.buffer);
6486 strcpy(obj->data.tail.buffer, "Logfile Empty");
6487 snprintf(p, p_max_size, "Logfile Empty");
6489 } /* if fp == null */
6490 } /* cur_upd_time >= */
6491 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6495 FILE *fp = fopen(obj->data.s,"r");
6502 while(fgets(buf, BUFSZ, fp) != NULL){
6503 for(j = 0; buf[j] != 0; j++) {
6504 if(buf[j] == '\n') {
6509 sprintf(p, "%d", lines);
6512 sprintf(p, "File Unreadable");
6517 FILE *fp = fopen(obj->data.s,"r");
6522 char inword = FALSE;
6525 while(fgets(buf, BUFSZ, fp) != NULL){
6526 for(j = 0; buf[j] != 0; j++) {
6527 if(!isspace(buf[j])) {
6528 if(inword == FALSE) {
6537 sprintf(p, "%d", words);
6540 sprintf(p, "File Unreadable");
6543 #ifdef TCP_PORT_MONITOR
6545 /* grab a pointer to this port monitor */
6546 tcp_port_monitor_t *p_monitor =
6547 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
6548 obj->data.tcp_port_monitor.port_range_begin,
6549 obj->data.tcp_port_monitor.port_range_end);
6552 snprintf(p, p_max_size, "monitor not found");
6556 /* now grab the text of interest */
6557 if (peek_tcp_port_monitor(p_monitor,
6558 obj->data.tcp_port_monitor.item,
6559 obj->data.tcp_port_monitor.connection_index, p,
6561 snprintf(p, p_max_size, "monitor peek error");
6569 iconv_converting = 1;
6570 iconv_selected = obj->a;
6573 iconv_converting = 0;
6578 OBJ(entropy_avail) {
6579 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
6581 OBJ(entropy_poolsize) {
6582 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
6585 double entropy_perc;
6587 entropy_perc = (double) cur->entropy.entropy_avail /
6588 (double) cur->entropy.poolsize;
6589 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
6595 s = smapi_get_val(obj->data.s);
6596 snprintf(p, p_max_size, "%s", s);
6600 OBJ(if_smapi_bat_installed) {
6602 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
6603 if(!smapi_bat_installed(idx)) {
6604 i = obj->data.ifblock.pos;
6609 ERR("argument to if_smapi_bat_installed must be an integer");
6611 OBJ(smapi_bat_perc) {
6613 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6614 val = smapi_bat_installed(idx) ?
6615 smapi_get_bat_int(idx, "remaining_percent") : 0;
6616 spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
6618 ERR("argument to smapi_bat_perc must be an integer");
6620 OBJ(smapi_bat_temp) {
6622 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6623 val = smapi_bat_installed(idx) ?
6624 smapi_get_bat_int(idx, "temperature") : 0;
6625 /* temperature is in milli degree celsius */
6626 temp_print(p, p_max_size, val / 1000, TEMP_CELSIUS);
6628 ERR("argument to smapi_bat_temp must be an integer");
6630 OBJ(smapi_bat_power) {
6632 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6633 val = smapi_bat_installed(idx) ?
6634 smapi_get_bat_int(idx, "power_now") : 0;
6635 /* power_now is in mW, set to W with one digit precision */
6636 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
6638 ERR("argument to smapi_bat_power must be an integer");
6640 OBJ(smapi_bat_bar) {
6641 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
6642 new_bar(p, obj->a, obj->b, (int)
6643 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
6645 new_bar(p, obj->a, obj->b, 0);
6651 parse_conky_vars(obj->data.scroll.text, p, cur);
6653 if (strlen(p) <= obj->data.scroll.show) {
6656 #define LINESEPARATOR '|'
6657 //place all the lines behind each other with LINESEPARATOR between them
6658 for(j = 0; p[j] != 0; j++) {
6663 //scroll the output obj->data.scroll.start places by copying that many chars from
6664 //the front of the string to tmp, scrolling the rest to the front and placing tmp
6665 //at the back of the string
6666 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
6667 strncpy(tmp, p, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
6668 for(j = obj->data.scroll.start; p[j] != 0; j++){
6669 p[j - obj->data.scroll.start] = p[j];
6671 strcpy(&p[j - obj->data.scroll.start], tmp);
6673 //only show the requested number of chars
6674 if(obj->data.scroll.show < j) {
6675 p[obj->data.scroll.show] = 0;
6677 //next time, scroll a place more or reset scrolling if we are at the end
6678 obj->data.scroll.start += obj->data.scroll.step;
6679 if(obj->data.scroll.start >= j){
6680 obj->data.scroll.start = 0;
6685 int value = get_nvidia_value(obj->data.nvidia.type, display);
6687 snprintf(p, p_max_size, "N/A");
6688 else if (obj->data.nvidia.type == NV_TEMP)
6689 temp_print(p, p_max_size, (double)value, TEMP_CELSIUS);
6690 else if (obj->data.nvidia.print_as_float &&
6691 value > 0 && value < 100)
6692 snprintf(p, p_max_size, "%.1f", (float)value);
6694 snprintf(p, p_max_size, "%d", value);
6702 unsigned int a = strlen(p);
6705 if (a > 0 && iconv_converting && iconv_selected > 0
6706 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6708 size_t dummy1, dummy2;
6709 char *ptr = buff_in;
6712 dummy1 = dummy2 = a;
6714 strncpy(buff_in, p, p_max_size);
6716 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6717 while (dummy1 > 0) {
6718 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6721 ERR("Iconv codeset conversion failed");
6726 /* It is nessecary when we are converting from multibyte to
6727 * singlebyte codepage */
6730 #endif /* HAVE_ICONV */
6737 double current_update_time, next_update_time, last_update_time;
6739 static void generate_text(void)
6741 struct information *cur = &info;
6748 current_update_time = get_time();
6751 /* fix diskio rates to b/s (use update_interval */
6752 info.diskio_read_value /= update_interval;
6753 info.diskio_write_value /= update_interval;
6754 info.diskio_value /= update_interval;
6756 /* add things to the buffer */
6762 generate_text_internal(p, max_user_text, global_text_object_list, cur);
6764 if (stuff_in_upper_case) {
6767 tmp_p = text_buffer;
6769 *tmp_p = toupper(*tmp_p);
6774 next_update_time += update_interval;
6775 if (next_update_time < get_time()) {
6776 next_update_time = get_time() + update_interval;
6777 } else if (next_update_time > get_time() + update_interval) {
6778 next_update_time = get_time() + update_interval;
6780 last_update_time = current_update_time;
6786 static void set_font(void)
6790 if (window.xftdraw != NULL) {
6791 XftDrawDestroy(window.xftdraw);
6793 window.xftdraw = XftDrawCreate(display, window.drawable,
6794 DefaultVisual(display, screen), DefaultColormap(display, screen));
6798 XSetFont(display, window.gc, fonts[selected_font].font->fid);
6804 static inline int get_string_width(const char *s)
6807 return *s ? calc_text_width(s, strlen(s)) : 0;
6813 static inline int get_string_width_special(char *s)
6825 p = strndup(s, text_buffer_size);
6829 if (*p == SPECIAL_CHAR) {
6830 /* shift everything over by 1 so that the special char
6831 * doesn't mess up the size calculation */
6832 for (i = 0; i < strlen(p); i++) {
6833 *(p + i) = *(p + i + 1);
6835 if (specials[special_index + idx].type == GRAPH
6836 || specials[special_index + idx].type == BAR) {
6837 width += specials[special_index + idx].width;
6844 if (strlen(final) > 1) {
6845 width += calc_text_width(final, strlen(final));
6850 return (s) ? strlen(s) : 0;
6855 static void text_size_updater(char *s);
6857 int last_font_height;
6858 static void update_text_area(void)
6862 /* update text size if it isn't fixed */
6867 text_width = minimum_width;
6870 last_font_height = font_height();
6871 for_each_line(text_buffer, text_size_updater);
6873 if (text_height < minimum_height) {
6874 text_height = minimum_height;
6876 if (text_width > maximum_width && maximum_width > 0) {
6877 text_width = maximum_width;
6881 /* get text position on workarea */
6882 switch (text_alignment) {
6889 x = workarea[2] - text_width - gap_x;
6894 x = workarea[2] / 2 - text_width / 2 - gap_x;
6901 y = workarea[3] - text_height - gap_y;
6905 x = workarea[2] - text_width - gap_x;
6906 y = workarea[3] - text_height - gap_y;
6910 x = workarea[2] / 2 - text_width / 2 - gap_x;
6911 y = workarea[3] - text_height - gap_y;
6916 y = workarea[3] / 2 - text_height / 2 - gap_y;
6920 x = workarea[2] - text_width - gap_x;
6921 y = workarea[3] / 2 - text_height / 2 - gap_y;
6925 case NONE: // Let the WM manage the window
6936 if (own_window && !fixed_pos) {
6939 text_start_x = border_margin + 1;
6940 text_start_y = border_margin + 1;
6941 window.x = x - border_margin - 1;
6942 window.y = y - border_margin - 1;
6946 /* If window size doesn't match to workarea's size,
6947 * then window probably includes panels (gnome).
6948 * Blah, doesn't work on KDE. */
6949 if (workarea[2] != window.width || workarea[3] != window.height) {
6961 static int cur_x, cur_y; /* current x and y for drawing */
6963 //draw_mode also without X11 because we only need to print to stdout with FG
6964 static int draw_mode; /* FG, BG or OUTLINE */
6966 static long current_color;
6969 static void text_size_updater(char *s)
6974 /* get string widths and skip specials */
6977 if (*p == SPECIAL_CHAR) {
6979 w += get_string_width(s);
6982 if (specials[special_index].type == BAR
6983 || specials[special_index].type == GRAPH) {
6984 w += specials[special_index].width;
6985 if (specials[special_index].height > last_font_height) {
6986 last_font_height = specials[special_index].height;
6987 last_font_height += font_ascent();
6989 } else if (specials[special_index].type == OFFSET) {
6990 if (specials[special_index].arg > 0) {
6991 w += specials[special_index].arg;
6993 } else if (specials[special_index].type == VOFFSET) {
6994 last_font_height += specials[special_index].arg;
6995 } else if (specials[special_index].type == GOTO) {
6996 if (specials[special_index].arg > cur_x) {
6997 w = (int) specials[special_index].arg;
6999 } else if (specials[special_index].type == TAB) {
7000 int start = specials[special_index].arg;
7001 int step = specials[special_index].width;
7003 if (!step || step < 0) {
7006 w += step - (cur_x - text_start_x - start) % step;
7007 } else if (specials[special_index].type == FONT) {
7008 selected_font = specials[special_index].font_added;
7009 if (font_height() > last_font_height) {
7010 last_font_height = font_height();
7019 w += get_string_width(s);
7020 if (w > text_width) {
7023 if (text_width > maximum_width && maximum_width) {
7024 text_width = maximum_width;
7027 text_height += last_font_height;
7028 last_font_height = font_height();
7032 static inline void set_foreground_color(long c)
7035 XSetForeground(display, window.gc, c);
7039 static void draw_string(const char *s)
7041 int i, i2, pos, width_of_s;
7049 width_of_s = get_string_width(s);
7050 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
7052 fflush(stdout); /* output immediately, don't buffer */
7054 memset(tmpstring1, 0, text_buffer_size);
7055 memset(tmpstring2, 0, text_buffer_size);
7056 strncpy(tmpstring1, s, text_buffer_size - 1);
7061 max = ((text_width - width_of_s) / get_string_width(" "));
7063 /* This code looks for tabs in the text and coverts them to spaces.
7064 * The trick is getting the correct number of spaces, and not going
7065 * over the window's size without forcing the window larger. */
7066 for (i = 0; i < (int) text_buffer_size; i++) {
7067 if (tmpstring1[i] == '\t') {
7069 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
7070 /* guard against overrun */
7071 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
7076 /* guard against overrun */
7077 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
7082 if (text_width == maximum_width) {
7083 /* this means the text is probably pushing the limit,
7084 * so we'll chop it */
7085 while (cur_x + get_string_width(tmpstring2) - text_start_x
7086 > maximum_width && strlen(tmpstring2) > 0) {
7087 tmpstring2[strlen(tmpstring2) - 1] = '\0';
7098 c.pixel = current_color;
7099 XQueryColor(display, DefaultColormap(display, screen), &c);
7102 c2.color.red = c.red;
7103 c2.color.green = c.green;
7104 c2.color.blue = c.blue;
7105 c2.color.alpha = fonts[selected_font].font_alpha;
7107 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
7108 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
7110 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
7111 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
7116 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
7119 cur_x += width_of_s;
7121 memcpy(tmpstring1, s, text_buffer_size);
7124 long redmask, greenmask, bluemask;
7126 void set_up_gradient(void)
7130 colour_depth = DisplayPlanes(display, screen);
7134 if (colour_depth != 24 && colour_depth != 16) {
7135 ERR("using non-standard colour depth, gradients may look like a "
7142 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
7144 greenmask |= 1 << i;
7147 if (colour_depth % 3 == 1) {
7148 greenmask |= 1 << (colour_depth / 3);
7150 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
7151 greenmask = greenmask << (colour_depth / 3);
7154 /* this function returns the next colour between two colours for a gradient */
7155 unsigned long do_gradient(unsigned long first_colour,
7156 unsigned long last_colour)
7159 int red1, green1, blue1; // first colour
7160 int red2, green2, blue2; // second colour
7161 int red3 = 0, green3 = 0, blue3 = 0; // difference
7162 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
7163 short greenshift = (colour_depth / 3);
7165 red1 = (first_colour & redmask) >> redshift;
7166 green1 = (first_colour & greenmask) >> greenshift;
7167 blue1 = first_colour & bluemask;
7168 red2 = (last_colour & redmask) >> redshift;
7169 green2 = (last_colour & greenmask) >> greenshift;
7170 blue2 = last_colour & bluemask;
7177 if (green1 > green2) {
7180 if (green1 < green2) {
7183 if (blue1 > blue2) {
7186 if (blue1 < blue2) {
7201 if (red1 > bluemask) {
7204 if (green1 > bluemask) {
7207 if (blue1 > bluemask) {
7210 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
7214 /* this function returns the max diff for a gradient */
7215 unsigned long gradient_max(unsigned long first_colour,
7216 unsigned long last_colour)
7218 int red1, green1, blue1; // first colour
7219 int red2, green2, blue2; // second colour
7220 int red3 = 0, green3 = 0, blue3 = 0; // difference
7221 long redshift, greenshift;
7224 if (colour_depth == 0) {
7227 redshift = (2 * colour_depth / 3 + colour_depth % 3);
7228 greenshift = (colour_depth / 3);
7230 red1 = (first_colour & redmask) >> redshift;
7231 green1 = (first_colour & greenmask) >> greenshift;
7232 blue1 = first_colour & bluemask;
7233 red2 = (last_colour & redmask) >> redshift;
7234 green2 = (last_colour & greenmask) >> greenshift;
7235 blue2 = last_colour & bluemask;
7236 red3 = abs(red1 - red2);
7237 green3 = abs(green1 - green2);
7238 blue3 = abs(blue1 - blue2);
7250 static void draw_line(char *s)
7258 cur_x = text_start_x;
7259 cur_y += font_ascent();
7260 font_h = font_height();
7262 /* find specials and draw stuff */
7265 if (*p == SPECIAL_CHAR) {
7268 /* draw string before special */
7275 switch (specials[special_index].type) {
7276 case HORIZONTAL_LINE:
7278 int h = specials[special_index].height;
7279 int mid = font_ascent() / 2;
7281 w = text_start_x + text_width - cur_x;
7283 XSetLineAttributes(display, window.gc, h, LineSolid,
7284 CapButt, JoinMiter);
7285 XDrawLine(display, window.drawable, window.gc, cur_x,
7286 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
7292 int h = specials[special_index].height;
7293 int tmp_s = specials[special_index].arg;
7294 int mid = font_ascent() / 2;
7295 char ss[2] = { tmp_s, tmp_s };
7297 w = text_start_x + text_width - cur_x - 1;
7298 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
7299 CapButt, JoinMiter);
7300 XSetDashes(display, window.gc, 0, ss, 2);
7301 XDrawLine(display, window.drawable, window.gc, cur_x,
7302 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
7308 int h, bar_usage, by;
7309 if (cur_x - text_start_x > maximum_width
7310 && maximum_width > 0) {
7313 h = specials[special_index].height;
7314 bar_usage = specials[special_index].arg;
7315 by = cur_y - (font_ascent() / 2) - 1;
7317 if (h < font_height()) {
7320 w = specials[special_index].width;
7322 w = text_start_x + text_width - cur_x - 1;
7328 XSetLineAttributes(display, window.gc, 1, LineSolid,
7329 CapButt, JoinMiter);
7331 XDrawRectangle(display, window.drawable, window.gc, cur_x,
7333 XFillRectangle(display, window.drawable, window.gc, cur_x,
7334 by, w * bar_usage / 255, h);
7335 if (specials[special_index].height > cur_y_add
7336 && specials[special_index].height > font_h) {
7337 cur_y_add = specials[special_index].height;
7344 int h, by, i, j = 0;
7345 int gradient_size = 0;
7346 float gradient_factor = 0;
7347 float gradient_update = 0;
7348 unsigned long last_colour = current_color;
7349 unsigned long tmpcolour = current_color;
7350 if (cur_x - text_start_x > maximum_width
7351 && maximum_width > 0) {
7354 h = specials[special_index].height;
7355 by = cur_y - (font_ascent() / 2) - 1;
7357 if (h < font_height()) {
7360 w = specials[special_index].width;
7362 w = text_start_x + text_width - cur_x - 1;
7367 if (draw_graph_borders) {
7368 XSetLineAttributes(display, window.gc, 1, LineSolid,
7369 CapButt, JoinMiter);
7370 XDrawRectangle(display, window.drawable, window.gc,
7373 XSetLineAttributes(display, window.gc, 1, LineSolid,
7374 CapButt, JoinMiter);
7376 if (specials[special_index].last_colour != 0
7377 || specials[special_index].first_colour != 0) {
7378 tmpcolour = specials[special_index].last_colour;
7380 gradient_max(specials[special_index].last_colour,
7381 specials[special_index].first_colour);
7382 gradient_factor = (float) gradient_size / (w - 2);
7384 for (i = w - 2; i > -1; i--) {
7385 if (specials[special_index].last_colour != 0
7386 || specials[special_index].first_colour != 0) {
7387 XSetForeground(display, window.gc, tmpcolour);
7388 gradient_update += gradient_factor;
7389 while (gradient_update > 0) {
7390 tmpcolour = do_gradient(tmpcolour,
7391 specials[special_index].first_colour);
7395 if ((w - i) / ((float) (w - 2) /
7396 (specials[special_index].graph_width)) > j
7397 && j < MAX_GRAPH_DEPTH - 3) {
7400 /* this is mugfugly, but it works */
7401 XDrawLine(display, window.drawable, window.gc,
7402 cur_x + i + 1, by + h, cur_x + i + 1,
7403 by + h - specials[special_index].graph[j] *
7404 (h - 1) / specials[special_index].graph_scale);
7406 if (specials[special_index].height > cur_y_add
7407 && specials[special_index].height > font_h) {
7408 cur_y_add = specials[special_index].height;
7410 /* if (draw_mode == BG) {
7411 set_foreground_color(default_bg_color);
7412 } else if (draw_mode == OUTLINE) {
7413 set_foreground_color(default_out_color);
7415 set_foreground_color(default_fg_color);
7417 if (show_graph_range) {
7420 unsigned short int seconds = update_interval * w;
7425 unsigned short int timeunits;
7427 timeunits = seconds / 86400; seconds %= 86400;
7428 if( timeunits > 0 ) {
7429 asprintf(&tmp_day_str, "%dd", timeunits);
7431 tmp_day_str = strdup("");
7433 timeunits = seconds / 3600; seconds %= 3600;
7434 if( timeunits > 0 ) {
7435 asprintf(&tmp_hour_str, "%dh", timeunits);
7437 tmp_hour_str = strdup("");
7439 timeunits = seconds / 60; seconds %= 60;
7441 asprintf(&tmp_min_str, "%dm", timeunits);
7443 tmp_min_str = strdup("");
7446 asprintf(&tmp_sec_str, "%ds", seconds);
7448 tmp_sec_str = strdup("");
7450 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
7451 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
7453 asprintf(&tmp_str, "Range not possible"); //should never happen, but better safe then sorry
7455 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
7456 cur_y += font_height() / 2;
7457 draw_string(tmp_str);
7463 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
7466 cur_x += font_ascent() / 2;
7467 cur_y += font_height() / 2;
7469 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
7471 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
7472 draw_string(tmp_str);
7478 set_foreground_color(last_colour);
7484 int old = font_ascent();
7486 cur_y -= font_ascent();
7487 selected_font = specials[special_index].font_added;
7488 if (cur_y + font_ascent() < cur_y + old) {
7491 cur_y += font_ascent();
7497 if (draw_mode == FG) {
7498 set_foreground_color(specials[special_index].arg);
7503 if (draw_mode == BG) {
7504 set_foreground_color(specials[special_index].arg);
7509 if (draw_mode == OUTLINE) {
7510 set_foreground_color(specials[special_index].arg);
7515 w += specials[special_index].arg;
7519 cur_y += specials[special_index].arg;
7523 if (specials[special_index].arg >= 0) {
7524 cur_x = (int) specials[special_index].arg;
7530 int start = specials[special_index].arg;
7531 int step = specials[special_index].width;
7533 if (!step || step < 0) {
7536 w = step - (cur_x - text_start_x - start) % step;
7542 /* TODO: add back in "+ border_margin" to the end of
7544 int pos_x = text_start_x + text_width -
7545 get_string_width_special(s);
7547 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
7548 "get_string_width(p) %i gap_x %i "
7549 "specials[special_index].arg %i border_margin %i "
7550 "border_width %i\n", pos_x, text_start_x, text_width,
7551 cur_x, get_string_width_special(s), gap_x,
7552 specials[special_index].arg, border_margin,
7554 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
7555 cur_x = pos_x - specials[special_index].arg;
7562 int pos_x = (text_width) / 2 - get_string_width_special(s) /
7563 2 - (cur_x - text_start_x);
7564 /* int pos_x = text_start_x + text_width / 2 -
7565 get_string_width_special(s) / 2; */
7567 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
7568 "get_string_width(p) %i gap_x %i "
7569 "specials[special_index].arg %i\n", pos_x, text_start_x,
7570 text_width, cur_x, get_string_width(s), gap_x,
7571 specials[special_index].arg); */
7572 if (pos_x > specials[special_index].arg) {
7573 w = pos_x - specials[special_index].arg;
7590 if (cur_y_add > 0) {
7592 cur_y -= font_descent();
7597 cur_y += font_descent();
7601 static void draw_text(void)
7604 cur_y = text_start_y;
7607 if (draw_borders && border_width > 0) {
7608 unsigned int b = (border_width + 1) / 2;
7610 if (stippled_borders) {
7611 char ss[2] = { stippled_borders, stippled_borders };
7612 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
7613 CapButt, JoinMiter);
7614 XSetDashes(display, window.gc, 0, ss, 2);
7616 XSetLineAttributes(display, window.gc, border_width, LineSolid,
7617 CapButt, JoinMiter);
7620 XDrawRectangle(display, window.drawable, window.gc,
7621 text_start_x - border_margin + b, text_start_y - border_margin + b,
7622 text_width + border_margin * 2 - 1 - b * 2,
7623 text_height + border_margin * 2 - 1 - b * 2);
7629 for_each_line(text_buffer, draw_line);
7632 static void draw_stuff(void)
7636 if (draw_shades && !draw_outline) {
7639 set_foreground_color(default_bg_color);
7650 for (i = -1; i < 2; i++) {
7651 for (j = -1; j < 2; j++) {
7652 if (i == 0 && j == 0) {
7657 set_foreground_color(default_out_color);
7658 draw_mode = OUTLINE;
7666 set_foreground_color(default_fg_color);
7675 swap.swap_window = window.window;
7676 swap.swap_action = XdbeBackground;
7677 XdbeSwapBuffers(display, &swap, 1);
7684 static void clear_text(int exposures)
7688 /* The swap action is XdbeBackground, which clears */
7693 /* there is some extra space for borders and outlines */
7694 XClearArea(display, window.window, text_start_x - border_margin - 1,
7695 text_start_y - border_margin - 1,
7696 text_width + border_margin * 2 + 2,
7697 text_height + border_margin * 2 + 2, exposures ? True : 0);
7702 static int need_to_update;
7704 /* update_text() generates new text and clears old text area */
7705 static void update_text(void)
7714 static void main_loop(void)
7716 #ifdef SIGNAL_BLOCKING
7717 sigset_t newmask, oldmask;
7721 Region region = XCreateRegion();
7725 XserverRegion region2, part;
7726 int event_base, error_base;
7728 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
7729 ERR("Xdamage extension unavailable");
7731 damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7732 region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7733 part = XFixesCreateRegionFromWindow(display, window.window, 0);
7734 #endif /* HAVE_XDAMAGE */
7737 #ifdef SIGNAL_BLOCKING
7738 sigemptyset(&newmask);
7739 sigaddset(&newmask, SIGINT);
7740 sigaddset(&newmask, SIGTERM);
7741 sigaddset(&newmask, SIGUSR1);
7744 next_update_time = last_update_time = get_time();
7746 while (total_run_times == 0 || info.looped < total_run_times) {
7749 #ifdef SIGNAL_BLOCKING
7750 /* block signals. we will inspect for pending signals later */
7751 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7752 CRIT_ERR("unable to sigprocmask()");
7759 /* wait for X event or timeout */
7761 if (!XPending(display)) {
7765 t = next_update_time - get_time();
7769 } else if (t > update_interval) {
7770 t = update_interval;
7773 tv.tv_sec = (long) t;
7774 tv.tv_usec = (long) (t * 1000000) % 1000000;
7776 FD_SET(ConnectionNumber(display), &fdsr);
7778 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7780 if (errno != EINTR) {
7781 ERR("can't select(): %s", strerror(errno));
7787 t = (next_update_time - get_time()) * 1000000;
7788 usleep((useconds_t)t);
7796 if (need_to_update) {
7798 int wx = window.x, wy = window.y;
7806 /* resize window if it isn't right size */
7808 && (text_width + border_margin * 2 + 1 != window.width
7809 || text_height + border_margin * 2 + 1 != window.height)) {
7810 window.width = text_width + border_margin * 2 + 1;
7811 window.height = text_height + border_margin * 2 + 1;
7812 XResizeWindow(display, window.window, window.width,
7815 set_transparent_background(window.window);
7819 /* move window if it isn't in right position */
7820 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7821 XMoveWindow(display, window.window, window.x, window.y);
7832 r.x = text_start_x - border_margin;
7833 r.y = text_start_y - border_margin;
7834 r.width = text_width + border_margin * 2;
7835 r.height = text_height + border_margin * 2;
7836 XUnionRectWithRegion(&r, region, region);
7841 /* handle X events */
7842 while (XPending(display)) {
7845 XNextEvent(display, &ev);
7853 r.width = ev.xexpose.width;
7854 r.height = ev.xexpose.height;
7855 XUnionRectWithRegion(&r, region, region);
7860 case ReparentNotify:
7861 /* set background to ParentRelative for all parents */
7863 set_transparent_background(window.window);
7867 case ConfigureNotify:
7869 /* if window size isn't what expected, set fixed size */
7870 if (ev.xconfigure.width != window.width
7871 || ev.xconfigure.height != window.height) {
7872 if (window.width != 0 && window.height != 0) {
7876 /* clear old stuff before screwing up
7881 XWindowAttributes attrs;
7883 if (XGetWindowAttributes(display,
7884 window.window, &attrs)) {
7885 window.width = attrs.width;
7886 window.height = attrs.height;
7890 text_width = window.width - border_margin * 2 - 1;
7891 text_height = window.height - border_margin * 2 - 1;
7892 if (text_width > maximum_width
7893 && maximum_width > 0) {
7894 text_width = maximum_width;
7898 /* if position isn't what expected, set fixed pos
7899 * total_updates avoids setting fixed_pos when window
7900 * is set to weird locations when started */
7901 /* // this is broken
7902 if (total_updates >= 2 && !fixed_pos
7903 && (window.x != ev.xconfigure.x
7904 || window.y != ev.xconfigure.y)
7905 && (ev.xconfigure.x != 0
7906 || ev.xconfigure.y != 0)) {
7915 /* if an ordinary window with decorations */
7916 if ((window.type == TYPE_NORMAL)
7917 && (!TEST_HINT(window.hints,
7918 HINT_UNDECORATED))) {
7919 /* allow conky to hold input focus. */
7922 /* forward the click to the desktop window */
7923 XUngrabPointer(display, ev.xbutton.time);
7924 ev.xbutton.window = window.desktop;
7925 XSendEvent(display, ev.xbutton.window, False,
7926 ButtonPressMask, &ev);
7927 XSetInputFocus(display, ev.xbutton.window,
7928 RevertToParent, ev.xbutton.time);
7935 /* if an ordinary window with decorations */
7936 if ((window.type == TYPE_NORMAL)
7937 && (!TEST_HINT(window.hints,
7938 HINT_UNDECORATED))) {
7939 /* allow conky to hold input focus. */
7942 /* forward the release to the desktop window */
7943 ev.xbutton.window = window.desktop;
7944 XSendEvent(display, ev.xbutton.window, False,
7945 ButtonReleaseMask, &ev);
7954 if (ev.type == event_base + XDamageNotify) {
7955 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7957 XFixesSetRegion(display, part, &dev->area, 1);
7958 XFixesUnionRegion(display, region2, region2, part);
7960 #endif /* HAVE_XDAMAGE */
7966 XDamageSubtract(display, damage, region2, None);
7967 XFixesSetRegion(display, region2, 0, 0);
7968 #endif /* HAVE_XDAMAGE */
7970 /* XDBE doesn't seem to provide a way to clear the back buffer without
7971 * interfering with the front buffer, other than passing XdbeBackground
7972 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7973 * redraw the text even if it wasn't part of the exposed area. OTOH,
7974 * if we're not going to call draw_stuff at all, then no swap happens
7975 * and we can safely do nothing. */
7977 if (!XEmptyRegion(region)) {
7982 r.x = text_start_x - border_margin;
7983 r.y = text_start_y - border_margin;
7984 r.width = text_width + border_margin * 2;
7985 r.height = text_height + border_margin * 2;
7986 XUnionRectWithRegion(&r, region, region);
7989 XSetRegion(display, window.gc, region);
7992 XftDrawSetClip(window.xftdraw, region);
7998 XDestroyRegion(region);
7999 region = XCreateRegion();
8003 #ifdef SIGNAL_BLOCKING
8004 /* unblock signals of interest and let handler fly */
8005 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
8006 CRIT_ERR("unable to sigprocmask()");
8010 switch (g_signal_pending) {
8013 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
8018 ERR("received SIGINT or SIGTERM to terminate. bye!");
8021 XDestroyRegion(region);
8024 XDamageDestroy(display, damage);
8025 XFixesDestroyRegion(display, region2);
8026 XFixesDestroyRegion(display, part);
8027 #endif /* HAVE_XDAMAGE */
8029 return; /* return from main_loop */
8032 /* Reaching here means someone set a signal
8033 * (SIGXXXX, signal_handler), but didn't write any code
8035 * If you don't want to handle a signal, don't set a handler on
8036 * it in the first place. */
8037 if (g_signal_pending) {
8038 ERR("ignoring signal (%d)", g_signal_pending);
8042 g_signal_pending = 0;
8045 #if defined(X11) && defined(HAVE_XDAMAGE)
8046 XDamageDestroy(display, damage);
8047 XFixesDestroyRegion(display, region2);
8048 XFixesDestroyRegion(display, part);
8049 XDestroyRegion(region);
8051 #endif /* X11 && HAVE_XDAMAGE */
8054 static void load_config_file(const char *);
8056 /* reload the config file */
8057 void reload_config(void)
8059 timed_thread_destroy_registered_threads();
8061 if (info.cpu_usage) {
8062 free(info.cpu_usage);
8063 info.cpu_usage = NULL;
8071 if (info.mpd.title) {
8072 free(info.mpd.title);
8073 info.mpd.title = NULL;
8075 if (info.mpd.artist) {
8076 free(info.mpd.artist);
8077 info.mpd.artist = NULL;
8079 if (info.mpd.album) {
8080 free(info.mpd.album);
8081 info.mpd.album = NULL;
8083 if (info.mpd.random) {
8084 free(info.mpd.random);
8085 info.mpd.random = NULL;
8087 if (info.mpd.repeat) {
8088 free(info.mpd.repeat);
8089 info.mpd.repeat = NULL;
8091 if (info.mpd.track) {
8092 free(info.mpd.track);
8093 info.mpd.track = NULL;
8095 if (info.mpd.name) {
8096 free(info.mpd.name);
8097 info.mpd.name = NULL;
8099 if (info.mpd.file) {
8100 free(info.mpd.file);
8101 info.mpd.file = NULL;
8103 if (info.mpd.status) {
8104 free(info.mpd.status);
8105 info.mpd.status = NULL;
8110 free_moc(&info.moc);
8117 #ifdef TCP_PORT_MONITOR
8118 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
8121 if (current_config) {
8123 load_config_file(current_config);
8125 /* re-init specials array */
8126 if ((specials = realloc((void *) specials,
8127 sizeof(struct special_t) * max_specials)) == 0) {
8128 ERR("failed to realloc specials array");
8134 // clear the window first
8135 XClearWindow(display, RootWindow(display, screen));
8138 #ifdef TCP_PORT_MONITOR
8139 info.p_tcp_port_monitor_collection = NULL;
8141 extract_variable_text(global_text);
8147 tmpstring1 = malloc(text_buffer_size);
8148 memset(tmpstring1, 0, text_buffer_size);
8152 tmpstring2 = malloc(text_buffer_size);
8153 memset(tmpstring2, 0, text_buffer_size);
8157 text_buffer = malloc(max_user_text);
8158 memset(text_buffer, 0, max_user_text);
8165 timed_thread_destroy_registered_threads();
8167 if (info.cpu_usage) {
8168 free(info.cpu_usage);
8169 info.cpu_usage = NULL;
8174 XdbeDeallocateBackBufferName(display, window.back_buffer);
8179 XDestroyWindow(display, window.window);
8180 XClearWindow(display, RootWindow(display, screen));
8185 XClearWindow(display, RootWindow(display, screen));
8190 XFreeGC(display, window.gc);
8194 free_text_objects(global_text_object_list, 1);
8195 free(global_text_object_list);
8196 global_text_object_list = NULL;
8215 free(current_config);
8217 #ifdef TCP_PORT_MONITOR
8218 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
8219 info.p_tcp_port_monitor_collection = NULL;
8228 for (i = 0; i < special_count; i++) {
8229 if (specials[i].type == GRAPH) {
8230 free(specials[i].graph);
8237 clear_diskio_stats();
8240 static int string_to_bool(const char *s)
8243 // Assumes an option without a true/false means true
8245 } else if (strcasecmp(s, "yes") == EQUAL) {
8247 } else if (strcasecmp(s, "true") == EQUAL) {
8249 } else if (strcasecmp(s, "1") == EQUAL) {
8256 static enum alignment string_to_alignment(const char *s)
8258 if (strcasecmp(s, "top_left") == EQUAL) {
8260 } else if (strcasecmp(s, "top_right") == EQUAL) {
8262 } else if (strcasecmp(s, "top_middle") == EQUAL) {
8264 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
8266 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
8267 return BOTTOM_RIGHT;
8268 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
8269 return BOTTOM_MIDDLE;
8270 } else if (strcasecmp(s, "middle_left") == EQUAL) {
8272 } else if (strcasecmp(s, "middle_right") == EQUAL) {
8273 return MIDDLE_RIGHT;
8274 } else if (strcasecmp(s, "tl") == EQUAL) {
8276 } else if (strcasecmp(s, "tr") == EQUAL) {
8278 } else if (strcasecmp(s, "tm") == EQUAL) {
8280 } else if (strcasecmp(s, "bl") == EQUAL) {
8282 } else if (strcasecmp(s, "br") == EQUAL) {
8283 return BOTTOM_RIGHT;
8284 } else if (strcasecmp(s, "bm") == EQUAL) {
8285 return BOTTOM_MIDDLE;
8286 } else if (strcasecmp(s, "ml") == EQUAL) {
8288 } else if (strcasecmp(s, "mr") == EQUAL) {
8289 return MIDDLE_RIGHT;
8290 } else if (strcasecmp(s, "none") == EQUAL) {
8297 static void set_default_configurations(void)
8299 fork_to_background = 0;
8300 total_run_times = 0;
8301 info.cpu_avg_samples = 2;
8302 info.net_avg_samples = 2;
8309 strcpy(info.mpd.host, "localhost");
8310 info.mpd.port = 6600;
8311 info.mpd.status = NULL;
8312 info.mpd.artist = NULL;
8313 info.mpd.album = NULL;
8314 info.mpd.title = NULL;
8315 info.mpd.random = NULL;
8316 info.mpd.track = NULL;
8317 info.mpd.name = NULL;
8318 info.mpd.file = NULL;
8321 init_moc(&info.moc);
8324 info.xmms2.artist = NULL;
8325 info.xmms2.album = NULL;
8326 info.xmms2.title = NULL;
8327 info.xmms2.genre = NULL;
8328 info.xmms2.comment = NULL;
8329 info.xmms2.url = NULL;
8330 info.xmms2.status = NULL;
8331 info.xmms2.playlist = NULL;
8333 use_spacer = NO_SPACER;
8335 output_methods = TO_X;
8337 output_methods = TO_STDOUT;
8340 show_graph_scale = 0;
8341 show_graph_range = 0;
8342 default_fg_color = WhitePixel(display, screen);
8343 default_bg_color = BlackPixel(display, screen);
8344 default_out_color = BlackPixel(display, screen);
8345 color0 = default_fg_color;
8346 color1 = default_fg_color;
8347 color2 = default_fg_color;
8348 color3 = default_fg_color;
8349 color4 = default_fg_color;
8350 color5 = default_fg_color;
8351 color6 = default_fg_color;
8352 color7 = default_fg_color;
8353 color8 = default_fg_color;
8354 color9 = default_fg_color;
8355 template[0] = strdup("");
8356 template[1] = strdup("");
8357 template[2] = strdup("");
8358 template[3] = strdup("");
8359 template[4] = strdup("");
8360 template[5] = strdup("");
8361 template[6] = strdup("");
8362 template[7] = strdup("");
8363 template[8] = strdup("");
8364 template[9] = strdup("");
8367 draw_graph_borders = 1;
8369 set_first_font("6x10");
8377 window.type = TYPE_NORMAL;
8379 strcpy(window.class_name, PACKAGE_NAME);
8381 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
8383 stippled_borders = 0;
8386 text_alignment = BOTTOM_LEFT;
8387 info.x11.monitor.number = 1;
8388 info.x11.monitor.current = 0;
8391 free(current_mail_spool);
8395 variable_substitute(MAIL_FILE, buf, 256);
8396 if (buf[0] != '\0') {
8397 current_mail_spool = strndup(buf, text_buffer_size);
8402 update_interval = 3.0;
8403 info.music_player_interval = 1.0;
8404 stuff_in_upper_case = 0;
8405 info.users.number = 1;
8407 #ifdef TCP_PORT_MONITOR
8408 tcp_port_monitor_args.max_port_monitor_connections =
8409 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8413 static void load_config_file(const char *f)
8415 #define CONF_ERR ERR("%s: %d: config file error", f, line)
8419 set_default_configurations();
8426 char buf[256], *p, *p2, *name, *value;
8429 if (fgets(buf, 256, fp) == NULL) {
8435 /* break at comment */
8436 p2 = strchr(p, '#');
8442 while (*p && isspace((int) *p)) {
8446 continue; /* empty line */
8453 while (*p2 && !isspace((int) *p2)) {
8457 *p2 = '\0'; /* break at name's end */
8464 while (*p && isspace((int) *p)) {
8470 p2 = value + strlen(value);
8471 while (isspace((int) *(p2 - 1))) {
8478 #define CONF2(a) if (strcasecmp(name, a) == 0)
8479 #define CONF(a) else CONF2(a)
8480 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
8481 || strcasecmp(name, b) == 0)
8484 CONF2("alignment") {
8485 if (window.type == TYPE_DOCK)
8488 int a = string_to_alignment(value);
8499 CONF("background") {
8500 fork_to_background = string_to_bool(value);
8503 CONF2("background") {
8504 fork_to_background = string_to_bool(value);
8508 CONF("show_graph_scale") {
8509 show_graph_scale = string_to_bool(value);
8511 CONF("show_graph_range") {
8512 show_graph_range = string_to_bool(value);
8514 CONF("border_margin") {
8516 border_margin = strtol(value, 0, 0);
8521 CONF("border_width") {
8523 border_width = strtol(value, 0, 0);
8530 color0 = get_x11_color(value);
8537 color1 = get_x11_color(value);
8544 color2 = get_x11_color(value);
8551 color3 = get_x11_color(value);
8558 color4 = get_x11_color(value);
8565 color5 = get_x11_color(value);
8572 color6 = get_x11_color(value);
8579 color7 = get_x11_color(value);
8586 color8 = get_x11_color(value);
8593 color9 = get_x11_color(value);
8598 #define TEMPLATE_CONF(n) \
8599 CONF("template"#n) { \
8601 free(template[n]); \
8602 template[n] = strdup(value); \
8617 CONF("default_color") {
8619 default_fg_color = get_x11_color(value);
8624 CONF3("default_shade_color", "default_shadecolor") {
8626 default_bg_color = get_x11_color(value);
8631 CONF3("default_outline_color", "default_outlinecolor") {
8633 default_out_color = get_x11_color(value);
8641 info.mail = parse_mail_args(IMAP, value);
8648 info.mail = parse_mail_args(POP3, value);
8656 strncpy(info.mpd.host, value, 127);
8663 info.mpd.port = strtol(value, 0, 0);
8664 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
8669 CONF("mpd_password") {
8671 strncpy(info.mpd.password, value, 127);
8677 CONF("music_player_interval") {
8679 info.music_player_interval = strtod(value, 0);
8685 CONF("sensor_device") {
8687 sensor_device = strtol(value, 0, 0);
8693 CONF("cpu_avg_samples") {
8695 cpu_avg_samples = strtol(value, 0, 0);
8696 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8699 info.cpu_avg_samples = cpu_avg_samples;
8705 CONF("net_avg_samples") {
8707 net_avg_samples = strtol(value, 0, 0);
8708 if (net_avg_samples < 1 || net_avg_samples > 14) {
8711 info.net_avg_samples = net_avg_samples;
8719 CONF("double_buffer") {
8720 use_xdbe = string_to_bool(value);
8724 CONF("override_utf8_locale") {
8725 utf8_mode = string_to_bool(value);
8727 CONF("draw_borders") {
8728 draw_borders = string_to_bool(value);
8730 CONF("draw_graph_borders") {
8731 draw_graph_borders = string_to_bool(value);
8733 CONF("draw_shades") {
8734 draw_shades = string_to_bool(value);
8736 CONF("draw_outline") {
8737 draw_outline = string_to_bool(value);
8740 CONF("out_to_console") {
8741 if(string_to_bool(value)) output_methods |= TO_STDOUT;
8743 CONF("use_spacer") {
8745 if (strcasecmp(value, "left") == EQUAL) {
8746 use_spacer = LEFT_SPACER;
8747 } else if (strcasecmp(value, "right") == EQUAL) {
8748 use_spacer = RIGHT_SPACER;
8749 } else if (strcasecmp(value, "none") == EQUAL) {
8750 use_spacer = NO_SPACER;
8752 use_spacer = string_to_bool(value);
8753 ERR("use_spacer should have an argument of left, right, or"
8754 " none. '%s' seems to be some form of '%s', so"
8755 " defaulting to %s.", value,
8756 use_spacer ? "true" : "false",
8757 use_spacer ? "right" : "none");
8759 use_spacer = RIGHT_SPACER;
8761 use_spacer = NO_SPACER;
8765 ERR("use_spacer should have an argument. Defaulting to right.");
8766 use_spacer = RIGHT_SPACER;
8772 use_xft = string_to_bool(value);
8776 set_first_font(value);
8782 if (value && font_count >= 0) {
8783 fonts[0].font_alpha = atof(value) * 65535.0;
8792 if (string_to_bool(value)) {
8793 ERR("Xft not enabled");
8797 /* xftfont silently ignored when no Xft */
8800 /* xftalpha is silently ignored when no Xft */
8805 set_first_font(value);
8815 gap_x = atoi(value);
8822 gap_y = atoi(value);
8828 CONF("mail_spool") {
8832 variable_substitute(value, buffer, 256);
8834 if (buffer[0] != '\0') {
8835 if (current_mail_spool) {
8836 free(current_mail_spool);
8838 current_mail_spool = strndup(buffer, text_buffer_size);
8845 CONF("minimum_size") {
8847 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8849 if (sscanf(value, "%d", &minimum_width) != 1) {
8857 CONF("maximum_width") {
8859 if (sscanf(value, "%d", &maximum_width) != 1) {
8867 CONF("no_buffers") {
8868 no_buffers = string_to_bool(value);
8870 CONF("top_cpu_separate") {
8871 cpu_separate = string_to_bool(value);
8873 CONF("short_units") {
8874 short_units = string_to_bool(value);
8876 CONF("pad_percents") {
8877 pad_percents = atoi(value);
8881 CONF("own_window") {
8883 own_window = string_to_bool(value);
8888 CONF("own_window_class") {
8890 memset(window.class_name, 0, sizeof(window.class_name));
8891 strncpy(window.class_name, value,
8892 sizeof(window.class_name) - 1);
8897 CONF("own_window_title") {
8899 memset(window.title, 0, sizeof(window.title));
8900 strncpy(window.title, value, sizeof(window.title) - 1);
8905 CONF("own_window_transparent") {
8907 set_transparent = string_to_bool(value);
8912 CONF("own_window_colour") {
8914 background_colour = get_x11_color(value);
8916 ERR("Invalid colour for own_window_colour (try omitting the "
8917 "'#' for hex colours");
8920 CONF("own_window_hints") {
8922 char *p_hint, *p_save;
8923 char delim[] = ", ";
8925 /* tokenize the value into individual hints */
8926 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8928 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8929 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
8930 SET_HINT(window.hints, HINT_UNDECORATED);
8931 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
8932 SET_HINT(window.hints, HINT_BELOW);
8933 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
8934 SET_HINT(window.hints, HINT_ABOVE);
8935 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
8936 SET_HINT(window.hints, HINT_STICKY);
8937 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
8938 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8939 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
8940 SET_HINT(window.hints, HINT_SKIP_PAGER);
8945 p_hint = strtok_r(NULL, delim, &p_save);
8946 } while (p_hint != NULL);
8952 CONF("own_window_type") {
8954 if (strncmp(value, "normal", 6) == EQUAL) {
8955 window.type = TYPE_NORMAL;
8956 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8957 window.type = TYPE_DESKTOP;
8958 } else if (strncmp(value, "dock", 7) == EQUAL) {
8959 window.type = TYPE_DOCK;
8960 text_alignment = TOP_LEFT;
8961 } else if (strncmp(value, "override", 8) == EQUAL) {
8962 window.type = TYPE_OVERRIDE;
8971 CONF("stippled_borders") {
8973 stippled_borders = strtol(value, 0, 0);
8975 stippled_borders = 4;
8980 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
8984 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
8987 CONF("update_interval") {
8989 update_interval = strtod(value, 0);
8993 if (info.music_player_interval == 0) {
8994 // default to update_interval
8995 info.music_player_interval = update_interval;
8998 CONF("total_run_times") {
9000 total_run_times = strtod(value, 0);
9006 stuff_in_upper_case = string_to_bool(value);
9008 CONF("max_specials") {
9010 max_specials = atoi(value);
9015 CONF("max_user_text") {
9017 max_user_text = atoi(value);
9022 CONF("text_buffer_size") {
9024 text_buffer_size = atoi(value);
9025 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
9026 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
9027 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
9039 global_text = (char *) malloc(1);
9040 global_text[0] = '\0';
9043 unsigned int l = strlen(global_text);
9045 if (fgets(buf, 256, fp) == NULL) {
9048 global_text = (char *) realloc(global_text, l + strlen(buf) + 1);
9049 strcat(global_text, buf);
9051 if (strlen(global_text) > max_user_text) {
9056 if (strlen(global_text) < 1) {
9057 CRIT_ERR("no text supplied in configuration; exiting");
9059 global_text_lines = line + 1;
9062 #ifdef TCP_PORT_MONITOR
9063 CONF("max_port_monitor_connections") {
9064 if (!value || (sscanf(value, "%d",
9065 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
9066 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
9067 /* an error. use default, warn and continue. */
9068 tcp_port_monitor_args.max_port_monitor_connections =
9069 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
9071 } else if (tcp_port_monitor_args.max_port_monitor_connections
9073 /* no error, just use default */
9074 tcp_port_monitor_args.max_port_monitor_connections =
9075 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
9077 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
9081 CONF("if_up_strictness") {
9083 ERR("incorrect if_up_strictness value, defaulting to 'up'");
9084 ifup_strictness = IFUP_UP;
9085 } else if (strcasecmp(value, "up") == EQUAL) {
9086 ifup_strictness = IFUP_UP;
9087 } else if (strcasecmp(value, "link") == EQUAL) {
9088 ifup_strictness = IFUP_LINK;
9089 } else if (strcasecmp(value, "address") == EQUAL) {
9090 ifup_strictness = IFUP_ADDR;
9092 ERR("incorrect if_up_strictness value, defaulting to 'up'");
9093 ifup_strictness = IFUP_UP;
9097 CONF("temperature_unit") {
9099 ERR("config option 'temperature_unit' needs an argument");
9100 } else if (set_temp_output_unit(value)) {
9101 ERR("temperature_unit: incorrect argument");
9106 ERR("%s: %d: no such configuration: '%s'", f, line, name);
9117 if (info.music_player_interval == 0) {
9118 // default to update_interval
9119 info.music_player_interval = update_interval;
9121 if (!global_text) { // didn't supply any text
9122 CRIT_ERR("missing text block in configuration; exiting");
9126 static void print_help(const char *prog_name) {
9127 printf("Usage: %s [OPTION]...\n"
9128 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
9129 "window. Command line options will override configurations defined in config\n"
9131 " -v, --version version\n"
9132 " -q, --quiet quiet mode\n"
9133 " -D, --debug increase debugging output\n"
9134 " -c, --config=FILE config file to load\n"
9135 " -d, --daemonize daemonize, fork to background\n"
9136 " -h, --help help\n"
9138 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
9139 " -f, --font=FONT font to use\n"
9141 " -o, --own-window create own window to draw\n"
9144 " -b, --double-buffer double buffer (prevents flickering)\n"
9146 " -w, --window-id=WIN_ID window id to draw\n"
9147 " -x X x position\n"
9148 " -y Y y position\n"
9150 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
9151 " -u, --interval=SECS update interval\n"
9152 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
9157 /* : means that character before that takes an argument */
9158 static const char *getopt_string = "vVqdDt:u:i:hc:"
9170 static const struct option longopts[] = {
9171 { "help", 0, NULL, 'h' },
9172 { "version", 0, NULL, 'V' },
9173 { "debug", 0, NULL, 'D' },
9174 { "config", 1, NULL, 'c' },
9175 { "daemonize", 0, NULL, 'd' },
9177 { "alignment", 1, NULL, 'a' },
9178 { "font", 1, NULL, 'f' },
9180 { "own-window", 0, NULL, 'o' },
9183 { "double-buffer", 0, NULL, 'b' },
9185 { "window-id", 1, NULL, 'w' },
9187 { "text", 1, NULL, 't' },
9188 { "interval", 0, NULL, 'u' },
9192 int main(int argc, char **argv)
9198 struct sigaction act, oact;
9200 g_signal_pending = 0;
9201 memset(&info, 0, sizeof(info));
9204 #ifdef TCP_PORT_MONITOR
9205 tcp_port_monitor_args.max_port_monitor_connections =
9206 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
9209 /* handle command line parameters that don't change configs */
9211 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
9212 || ((s = getenv("LANG")) && *s)) {
9213 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
9215 ERR("malloc failed");
9217 for (x = 0; x < strlen(s); x++) {
9218 temp[x] = tolower(s[x]);
9221 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
9227 if (!setlocale(LC_CTYPE, "")) {
9228 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
9232 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
9243 if (current_config) {
9244 free(current_config);
9246 current_config = strndup(optarg, max_user_text);
9249 freopen("/dev/null", "w", stderr);
9252 print_help(argv[0]);
9256 window.window = strtol(optarg, 0, 0);
9265 /* initalize X BEFORE we load config.
9266 * (we need to so that 'screen' is set) */
9270 /* check if specified config file is valid */
9271 if (current_config) {
9273 if (stat(current_config, &sb) ||
9274 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
9275 ERR("invalid configuration file '%s'\n", current_config);
9276 free(current_config);
9281 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
9283 if (!current_config) {
9284 /* load default config file */
9288 /* Try to use personal config file first */
9289 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
9290 if (buf[0] && (fp = fopen(buf, "r"))) {
9291 current_config = strndup(buf, max_user_text);
9295 /* Try to use system config file if personal config not readable */
9296 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
9297 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
9301 /* No readable config found */
9302 if (!current_config) {
9303 CRIT_ERR("no readable personal or system-wide config file found");
9307 load_config_file(current_config);
9309 /* init specials array */
9310 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
9311 ERR("failed to create specials array");
9315 if (current_mail_spool == NULL) {
9318 variable_substitute(MAIL_FILE, buf, 256);
9320 if (buf[0] != '\0') {
9321 current_mail_spool = strndup(buf, text_buffer_size);
9326 /* handle other command line arguments */
9328 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
9329 || defined(__NetBSD__)
9330 optind = optreset = 1;
9335 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9336 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
9337 "kvm_open")) == NULL) {
9338 CRIT_ERR("cannot read kvm");
9343 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
9351 fork_to_background = 1;
9354 global_debug_level++;
9358 set_first_font(optarg);
9361 text_alignment = string_to_alignment(optarg);
9380 global_text = strndup(optarg, max_user_text);
9381 convert_escapes(global_text);
9385 update_interval = strtod(optarg, 0);
9386 if (info.music_player_interval == 0) {
9387 // default to update_interval
9388 info.music_player_interval = update_interval;
9393 total_run_times = strtod(optarg, 0);
9397 gap_x = atoi(optarg);
9401 gap_y = atoi(optarg);
9415 /* generate text and get initial size */
9416 extract_variable_text(global_text);
9423 if (fork_to_background) {
9428 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
9435 fprintf(stderr, "\n");
9440 /* parent process */
9441 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
9448 text_buffer = malloc(max_user_text);
9449 memset(text_buffer, 0, max_user_text);
9450 tmpstring1 = malloc(text_buffer_size);
9451 memset(tmpstring1, 0, text_buffer_size);
9452 tmpstring2 = malloc(text_buffer_size);
9453 memset(tmpstring2, 0, text_buffer_size);
9457 update_text_area(); /* to get initial size of the window */
9460 init_window(own_window, text_width + border_margin * 2 + 1,
9461 text_height + border_margin * 2 + 1, set_transparent, background_colour,
9463 #else /* OWN_WINDOW */
9464 init_window(0, text_width + border_margin * 2 + 1,
9465 text_height + border_margin * 2 + 1, set_transparent, 0,
9467 #endif /* OWN_WINDOW */
9470 update_text_area(); /* to position text/window on screen */
9473 if (own_window && !fixed_pos) {
9474 XMoveWindow(display, window.window, window.x, window.y);
9477 set_transparent_background(window.window);
9487 /* Set signal handlers */
9488 act.sa_handler = signal_handler;
9489 sigemptyset(&act.sa_mask);
9492 act.sa_flags |= SA_RESTART;
9495 if ( sigaction(SIGINT, &act, &oact) < 0
9496 || sigaction(SIGUSR1, &act, &oact) < 0
9497 || sigaction(SIGHUP, &act, &oact) < 0
9498 || sigaction(SIGTERM, &act, &oact) < 0) {
9499 ERR("error setting signal handler: %s", strerror(errno));
9504 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9511 void signal_handler(int sig)
9513 /* signal handler is light as a feather, as it should be.
9514 * we will poll g_signal_pending with each loop of conky
9515 * and do any signal processing there, NOT here. */
9516 g_signal_pending = sig;