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>
66 #define S_ISSOCK(x) ((x & S_IFMT) == S_IFSOCK)
69 #define MAIL_FILE "$MAIL"
70 #define MAX_IF_BLOCK_DEPTH 5
71 #define MAX_TAIL_LINES 100
73 /* #define SIGNAL_BLOCKING */
74 #undef SIGNAL_BLOCKING
76 static void print_version(void) __attribute__((noreturn));
78 static void print_version(void)
80 printf(PACKAGE_NAME" "VERSION" compiled "BUILD_DATE" for "BUILD_ARCH"\n");
82 printf("\nCompiled in features:\n\n"
83 "System config file: "SYSTEM_CONFIG_FILE"\n\n"
87 " * Xdamage extension\n"
88 # endif /* HAVE_XDAMAGE */
90 " * Xdbe extension (double buffer)\n"
91 # endif /* HAVE_XDBE */
96 "\n Music detection:\n"
99 #endif /* AUDACIOUS */
109 "\n General features:\n"
116 #ifdef TCP_PORT_MONITOR
118 #endif /* TCP_PORT_MONITOR */
127 #endif /* HAVE_IWLIB */
139 static const char *suffixes[] = { "B", "KiB", "MiB", "GiB", "TiB", "PiB", "" };
145 static int text_start_x, text_start_y; /* text start position in window */
146 static int text_width, text_height;
164 char name[DEFAULT_TEXT_BUFFER_SIZE];
174 static int selected_font = 0;
175 static int font_count = -1;
176 struct font_list *fonts = NULL;
180 #define font_height() (use_xft ? (fonts[selected_font].xftfont->ascent + \
181 fonts[selected_font].xftfont->descent) \
182 : (fonts[selected_font].font->max_bounds.ascent + \
183 fonts[selected_font].font->max_bounds.descent))
184 #define font_ascent() (use_xft ? fonts[selected_font].xftfont->ascent \
185 : fonts[selected_font].font->max_bounds.ascent)
186 #define font_descent() (use_xft ? fonts[selected_font].xftfont->descent \
187 : fonts[selected_font].font->max_bounds.descent)
191 #define font_height() (fonts[selected_font].font->max_bounds.ascent + \
192 fonts[selected_font].font->max_bounds.descent)
193 #define font_ascent() fonts[selected_font].font->max_bounds.ascent
194 #define font_descent() fonts[selected_font].font->max_bounds.descent
198 #define MAX_FONTS 64 // hmm, no particular reason, just makes sense.
200 static void set_font(void);
202 int addfont(const char *data_in)
204 if (font_count > MAX_FONTS) {
205 CRIT_ERR("you don't need that many fonts, sorry.");
208 if (font_count == 0) {
212 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
216 memset(fonts, 0, sizeof(struct font_list));
218 fonts = realloc(fonts, (sizeof(struct font_list) * (font_count + 1)));
219 memset(&fonts[font_count], 0, sizeof(struct font_list));
221 CRIT_ERR("realloc in addfont");
223 // must account for null terminator
224 if (strlen(data_in) < DEFAULT_TEXT_BUFFER_SIZE) {
225 strncpy(fonts[font_count].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
227 fonts[font_count].font_alpha = 0xffff;
230 CRIT_ERR("Oops...looks like something overflowed in addfont().");
235 void set_first_font(const char *data_in)
237 if (font_count < 0) {
238 if ((fonts = (struct font_list *) malloc(sizeof(struct font_list)))
242 memset(fonts, 0, sizeof(struct font_list));
245 if (strlen(data_in) > 1) {
246 strncpy(fonts[0].name, data_in, DEFAULT_TEXT_BUFFER_SIZE);
248 fonts[0].font_alpha = 0xffff;
253 void free_fonts(void)
257 for (i = 0; i <= font_count; i++) {
260 XftFontClose(display, fonts[i].xftfont);
261 fonts[i].xftfont = 0;
265 XFreeFont(display, fonts[i].font);
275 static void load_fonts(void)
279 for (i = 0; i <= font_count; i++) {
282 if (use_xft && fonts[i].xftfont) {
284 } else if (use_xft) {
285 /* if (fonts[i].xftfont != NULL && selected_font == 0) {
286 XftFontClose(display, fonts[i].xftfont);
288 fonts[i].xftfont = XftFontOpenName(display, screen,
290 if (fonts[i].xftfont != NULL) {
294 ERR("can't load Xft font '%s'", fonts[i].name);
295 if ((fonts[i].xftfont = XftFontOpenName(display, screen,
296 "courier-12")) != NULL) {
300 ERR("can't load Xft font '%s'", "courier-12");
302 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
303 CRIT_ERR("can't load font '%s'", "fixed");
310 /* load normal font */
311 /* if (fonts[i].font != NULL) {
312 XFreeFont(display, fonts[i].font);
315 if (fonts[i].font || (fonts[i].font = XLoadQueryFont(display, fonts[i].name)) == NULL) {
316 ERR("can't load font '%s'", fonts[i].name);
317 if ((fonts[i].font = XLoadQueryFont(display, "fixed")) == NULL) {
318 CRIT_ERR("can't load font '%s'", "fixed");
319 printf("loaded fixed?\n");
327 /* default config file */
328 static char *current_config;
330 /* set to 1 if you want all text to be in uppercase */
331 static unsigned int stuff_in_upper_case;
333 /* Run how many times? */
334 static unsigned long total_run_times;
337 static int fork_to_background;
339 static int cpu_avg_samples, net_avg_samples;
343 static int show_graph_scale;
344 static int show_graph_range;
346 /* Position on the screen */
347 static int text_alignment;
348 static int gap_x, gap_y;
351 static int draw_borders;
352 static int draw_graph_borders;
353 static int stippled_borders;
355 static int draw_shades, draw_outline;
357 static int border_margin, border_width;
359 static long default_fg_color, default_bg_color, default_out_color;
361 /* create own window or draw stuff to root? */
362 static int set_transparent = 0;
365 static int own_window = 0;
366 static int background_colour = 0;
368 /* fixed size/pos is set if wm/user changes them */
369 static int fixed_size = 0, fixed_pos = 0;
372 static int minimum_width, minimum_height;
373 static int maximum_width;
378 static int sensor_device;
381 static long color0, color1, color2, color3, color4, color5, color6, color7,
384 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
385 static unsigned int max_specials = MAX_SPECIALS_DEFAULT;
387 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
388 static unsigned int max_user_text = MAX_USER_TEXT_DEFAULT;
390 /* maximum size of individual text buffers, ie $exec buffer size */
391 unsigned int text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
394 #define CODEPAGE_LENGTH 20
396 long iconv_count = 0;
397 char iconv_converting;
398 static iconv_t **iconv_cd = 0;
400 int register_iconv(iconv_t *new_iconv)
402 iconv_cd = realloc(iconv_cd, sizeof(iconv_t *) * (iconv_count + 1));
404 CRIT_ERR("Out of memory");
406 iconv_cd[iconv_count] = malloc(sizeof(iconv_t));
407 if (!iconv_cd[iconv_count]) {
408 CRIT_ERR("Out of memory");
410 memcpy(iconv_cd[iconv_count], new_iconv, sizeof(iconv_t));
415 void free_iconv(void)
420 for (i = 0; i < iconv_count; i++) {
422 iconv_close(*iconv_cd[i]);
436 /* no buffers in used memory? */
439 /* pad percentages to decimals? */
440 static int pad_percents = 0;
442 #ifdef TCP_PORT_MONITOR
443 tcp_port_monitor_args_t tcp_port_monitor_args;
446 static char *global_text = 0;
447 long global_text_lines;
449 static int total_updates;
452 static int blockdepth = 0;
453 static int if_jumped = 0;
454 static int blockstart[MAX_IF_BLOCK_DEPTH];
456 int check_contains(char *f, char *s)
459 FILE *where = fopen(f, "r");
462 char buf1[256], buf2[256];
464 while (fgets(buf1, 256, where)) {
465 sscanf(buf1, "%255s", buf2);
466 if (strstr(buf2, s)) {
473 ERR("Could not open the file");
479 static inline int calc_text_width(const char *s, int l)
486 XftTextExtentsUtf8(display, fonts[selected_font].xftfont,
487 (const FcChar8 *) s, l, &gi);
489 XftTextExtents8(display, fonts[selected_font].xftfont,
490 (const FcChar8 *) s, l, &gi);
496 return XTextWidth(fonts[selected_font].font, s, l);
501 /* formatted text to render on screen, generated in generate_text(),
502 * drawn in draw_stuff() */
504 static char *text_buffer;
506 /* special stuff in text_buffer */
508 #define SPECIAL_CHAR '\x01'
537 unsigned long first_colour; // for graph gradient
538 unsigned long last_colour;
542 /* create specials array on heap instead of stack with introduction of
544 static struct special_t *specials = NULL;
546 static unsigned int special_count;
549 static unsigned int special_index; /* used when drawing */
552 /* why 256? cause an array of more then 256 doubles seems excessive,
553 * and who needs that kind of precision anyway? */
554 #define MAX_GRAPH_DEPTH 256
556 static struct special_t *new_special(char *buf, enum special_types t)
558 if (special_count >= max_specials) {
559 CRIT_ERR("too many special things in text");
562 buf[0] = SPECIAL_CHAR;
564 specials[special_count].type = t;
565 return &specials[special_count++];
568 long fwd_fcharfind(FILE *fp, char val, unsigned int step)
572 unsigned int count = 0;
573 static char buf[BUFSZ];
574 long orig_pos = ftell(fp);
576 long buf_size = BUFSZ;
577 char *cur_found = NULL;
579 while (count < step) {
580 if (cur_found == NULL) {
581 buf_size = fread(buf, 1, buf_size, fp);
584 cur_found = memchr(buf + buf_pos, val, buf_size - buf_pos);
585 if (cur_found != NULL) {
586 buf_pos = cur_found - buf + 1;
595 ret = ftell(fp) - buf_size + buf_pos - 1;
597 fseek(fp, orig_pos, SEEK_SET);
602 void *memrchr(const void *buffer, char c, size_t n)
604 const unsigned char *p = buffer;
606 for (p += n; n; n--) {
615 long rev_fcharfind(FILE *fp, char val, unsigned int step)
619 unsigned int count = 0;
620 static char buf[BUFSZ];
621 long orig_pos = ftell(fp);
623 long file_pos = orig_pos;
624 long buf_size = BUFSZ;
627 while (count < step) {
629 if (file_pos > BUFSZ) {
630 fseek(fp, file_pos - BUFSZ, SEEK_SET);
633 fseek(fp, 0, SEEK_SET);
635 file_pos = ftell(fp);
636 buf_pos = fread(buf, 1, buf_size, fp);
638 cur_found = memrchr(buf, val, (size_t) buf_pos);
639 if (cur_found != NULL) {
640 buf_pos = cur_found - buf;
649 fseek(fp, orig_pos, SEEK_SET);
651 ret = file_pos + buf_pos;
656 static void new_bar(char *buf, int w, int h, int usage)
658 struct special_t *s = new_special(buf, BAR);
660 s->arg = (usage > 255) ? 255 : ((usage < 0) ? 0 : usage);
665 static const char *scan_bar(const char *args, int *w, int *h)
667 /* zero width means all space that is available */
670 /* bar's argument is either height or height,width */
674 if (sscanf(args, "%d,%d %n", h, w, &n) <= 1) {
675 sscanf(args, "%d %n", h, &n);
683 static char *scan_font(const char *args)
686 return strndup(args, DEFAULT_TEXT_BUFFER_SIZE);
693 static void new_font(char *buf, char *args)
696 struct special_t *s = new_special(buf, FONT);
698 if (s->font_added > font_count || !s->font_added || (strncmp(args, fonts[s->font_added].name, DEFAULT_TEXT_BUFFER_SIZE) != EQUAL) ) {
699 int tmp = selected_font;
701 selected_font = s->font_added = addfont(args);
706 struct special_t *s = new_special(buf, FONT);
707 int tmp = selected_font;
709 selected_font = s->font_added = 0;
714 void graph_append(struct special_t *graph, double f, char showaslog)
724 if (!graph->scaled && f > graph->graph_scale) {
725 f = graph->graph_scale;
728 /* Already happens in new_graph
730 graph->graph_scale = 1;
733 graph->graph[0] = f; /* add new data */
734 /* shift all the data by 1 */
735 for (i = graph->graph_width - 1; i > 0; i--) {
736 graph->graph[i] = graph->graph[i - 1];
737 if (graph->scaled && graph->graph[i] > graph->graph_scale) {
738 /* check if we need to update the scale */
739 graph->graph_scale = graph->graph[i];
744 short colour_depth = 0;
745 void set_up_gradient(void);
747 /* precalculated: 31/255, and 63/255 */
748 #define CONST_8_TO_5_BITS 0.12156862745098
749 #define CONST_8_TO_6_BITS 0.247058823529412
751 /* adjust color values depending on color depth */
752 static unsigned int adjust_colors(unsigned int color)
756 if (colour_depth == 0) {
759 if (colour_depth == 16) {
760 r = (color & 0xff0000) >> 16;
761 g = (color & 0xff00) >> 8;
763 color = (int) (r * CONST_8_TO_5_BITS) << 11;
764 color |= (int) (g * CONST_8_TO_6_BITS) << 5;
765 color |= (int) (b * CONST_8_TO_5_BITS);
770 static void new_graph(char *buf, int w, int h, unsigned int first_colour,
771 unsigned int second_colour, double i, int scale, int append, char showaslog)
773 struct special_t *s = new_special(buf, GRAPH);
776 if (s->graph == NULL) {
777 if (s->width > 0 && s->width < MAX_GRAPH_DEPTH) {
778 // subtract 2 for the box
779 s->graph_width = s->width /* - 2 */;
781 s->graph_width = MAX_GRAPH_DEPTH - 2;
783 s->graph = malloc(s->graph_width * sizeof(double));
784 memset(s->graph, 0, s->graph_width * sizeof(double));
785 s->graph_scale = 100;
788 s->first_colour = adjust_colors(first_colour);
789 s->last_colour = adjust_colors(second_colour);
792 s->graph_scale = scale;
800 s->graph_width = s->width - 2; // subtract 2 for rectangle around
804 s->graph_scale = log10(s->graph_scale + 1);
808 graph_append(s, i, showaslog);
812 //don't use spaces in LOGGRAPH or NORMGRAPH if you change them
813 #define LOGGRAPH "log"
814 #define NORMGRAPH "normal"
816 static char *scan_graph(const char *args, int *w, int *h,
817 unsigned int *first_colour, unsigned int *last_colour,
818 unsigned int *scale, char *showaslog)
820 const char *nographtype;
824 /* zero width means all space that is available */
831 //set showaslog and place the rest of the args in nographtype
832 if(strcasecmp(args, LOGGRAPH) == EQUAL) {
835 }else if(strcasecmp(args, NORMGRAPH) == EQUAL) {
838 }else if(strncasecmp(args, LOGGRAPH" ", strlen(LOGGRAPH) + 1 ) == EQUAL) {
840 nographtype = &args[strlen(LOGGRAPH) + 1];
841 }else if(strncasecmp(args, NORMGRAPH" ", strlen(NORMGRAPH) + 1 ) == EQUAL) {
843 nographtype = &args[strlen(NORMGRAPH) + 1];
848 //check the rest of the args
849 if (sscanf(nographtype, "%d,%d %x %x %u", h, w, first_colour, last_colour, scale) == 5) {
853 if (sscanf(nographtype, "%d,%d %x %x", h, w, first_colour, last_colour) == 4) {
856 if (sscanf(nographtype, "%63s %d,%d %x %x %u", buf, h, w, first_colour, last_colour, scale) == 6) {
857 return strndup(buf, text_buffer_size);
860 if (sscanf(nographtype, "%63s %d,%d %x %x", buf, h, w, first_colour, last_colour) == 5) {
861 return strndup(buf, text_buffer_size);
866 if (sscanf(nographtype, "%x %x %u", first_colour, last_colour, scale) == 3) {
870 if (sscanf(nographtype, "%x %x", first_colour, last_colour) == 2) {
873 if (sscanf(nographtype, "%63s %x %x %u", buf, first_colour, last_colour, scale) == 4) {
874 return strndup(buf, text_buffer_size);
877 if (sscanf(nographtype, "%63s %x %x", buf, first_colour, last_colour) == 3) {
878 return strndup(buf, text_buffer_size);
883 if (sscanf(nographtype, "%d,%d %u", h, w, scale) == 3) {
887 if (sscanf(nographtype, "%d,%d", h, w) == 2) {
890 if (sscanf(nographtype, "%63s %d,%d %u", buf, h, w, scale) < 4) {
892 //TODO: check the return value and throw an error?
893 sscanf(nographtype, "%63s %d,%d", buf, h, w);
896 return strndup(buf, text_buffer_size);
899 if (buf[0] == '\0') {
902 return strndup(buf, text_buffer_size);
906 static inline void new_hr(char *buf, int a)
908 new_special(buf, HORIZONTAL_LINE)->height = a;
911 static inline void new_stippled_hr(char *buf, int a, int b)
913 struct special_t *s = new_special(buf, STIPPLED_HR);
919 static inline void new_fg(char *buf, long c)
921 new_special(buf, FG)->arg = c;
924 static inline void new_bg(char *buf, long c)
926 new_special(buf, BG)->arg = c;
929 static inline void new_outline(char *buf, long c)
931 new_special(buf, OUTLINE)->arg = c;
934 static inline void new_offset(char *buf, long c)
936 new_special(buf, OFFSET)->arg = c;
939 static inline void new_voffset(char *buf, long c)
941 new_special(buf, VOFFSET)->arg = c;
944 static inline void new_alignr(char *buf, long c)
946 new_special(buf, ALIGNR)->arg = c;
949 // A postive offset pushes the text further left
950 static inline void new_alignc(char *buf, long c)
952 new_special(buf, ALIGNC)->arg = c;
955 static inline void new_goto(char *buf, long c)
957 new_special(buf, GOTO)->arg = c;
960 static inline void new_tab(char *buf, int a, int b)
962 struct special_t *s = new_special(buf, TAB);
968 /* quite boring functions */
970 static inline void for_each_line(char *b, void f(char *))
974 for (ps = b, pe = b; *pe; pe++) {
988 static void convert_escapes(char *buf)
990 char *p = buf, *s = buf;
997 } else if (*s == '\\') {
1008 /* Prints anything normally printed with snprintf according to the current value
1009 * of use_spacer. Actually slightly more flexible than snprintf, as you can
1010 * safely specify the destination buffer as one of your inputs. */
1011 static int spaced_print(char *, int, const char *, int, const char *, ...)
1012 __attribute__((format(printf, 3, 6)));
1014 static int spaced_print(char *buf, int size, const char *format, int width,
1015 const char *func_name, ...) {
1023 tempbuf = malloc(size * sizeof(char));
1025 // Passes the varargs along to vsnprintf
1026 va_start(argp, func_name);
1027 vsnprintf(tempbuf, size, format, argp);
1030 switch (use_spacer) {
1032 len = snprintf(buf, size, "%s", tempbuf);
1035 len = snprintf(buf, size, "%*s", width - 1, tempbuf);
1038 len = snprintf(buf, size, "%-*s", width - 1, tempbuf);
1041 CRIT_ERR("%s encountered invalid use_spacer value (%d)", func_name,
1050 /* converts from bytes to human readable format (k, M, G, T) */
1051 static void human_readable(long long num, char *buf, int size, const char *func_name)
1053 const char **suffix = suffixes;
1056 static const int WIDTH = 10, SHORT_WIDTH = 8;
1060 spaced_print(buf, size, "%lld%c", SHORT_WIDTH, func_name, num,
1063 spaced_print(buf, size, "%lld%s", WIDTH, func_name, num, *suffix);
1068 while (num / 1024 >= 1000LL && **(suffix + 2)) {
1074 fnum = num / 1024.0;
1079 if (precision < 0) {
1083 len = spaced_print(buf, size, "%.*f%c", SHORT_WIDTH, func_name,
1084 precision, fnum, **suffix);
1086 len = spaced_print(buf, size, "%.*f%s", WIDTH, func_name, precision,
1089 } while (len >= (short_units ? SHORT_WIDTH : WIDTH) || len >= size);
1094 enum text_object_type {
1096 #if defined(__linux__)
1098 #endif /* __linux__ */
1108 OBJ_battery_percent,
1110 #endif /* !__OpenBSD__ */
1125 OBJ_conky_build_date,
1126 OBJ_conky_build_arch,
1136 OBJ_diskiograph_read,
1137 OBJ_diskiograph_write,
1175 #if defined(__linux__)
1182 OBJ_i8k_left_fan_status,
1183 OBJ_i8k_right_fan_status,
1184 OBJ_i8k_left_fan_rpm,
1185 OBJ_i8k_right_fan_rpm,
1187 OBJ_i8k_buttons_status,
1203 OBJ_wireless_bitrate,
1205 OBJ_wireless_link_qual,
1206 OBJ_wireless_link_qual_max,
1207 OBJ_wireless_link_qual_perc,
1208 OBJ_wireless_link_bar,
1209 #endif /* __linux__ */
1250 OBJ_running_processes,
1259 OBJ_temp1, /* i2c is used instead in these */
1283 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
1284 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
1286 OBJ_apm_battery_time,
1287 OBJ_apm_battery_life,
1288 #endif /* __FreeBSD__ __OpenBSD__ */
1290 OBJ_obsd_sensors_temp,
1291 OBJ_obsd_sensors_fan,
1292 OBJ_obsd_sensors_volt,
1295 #endif /* __OpenBSD__ */
1317 OBJ_music_player_interval,
1337 OBJ_xmms2_timesplayed,
1340 OBJ_audacious_status,
1341 OBJ_audacious_title,
1342 OBJ_audacious_length,
1343 OBJ_audacious_length_seconds,
1344 OBJ_audacious_position,
1345 OBJ_audacious_position_seconds,
1346 OBJ_audacious_bitrate,
1347 OBJ_audacious_frequency,
1348 OBJ_audacious_channels,
1349 OBJ_audacious_filename,
1350 OBJ_audacious_playlist_length,
1351 OBJ_audacious_playlist_position,
1368 #ifdef TCP_PORT_MONITOR
1383 OBJ_smapi_bat_power,
1384 OBJ_if_smapi_bat_installed,
1388 OBJ_entropy_poolsize,
1392 struct text_object {
1394 char *s; /* some string */
1395 int i; /* some integer */
1396 long l; /* some other integer */
1397 unsigned int sensor;
1398 struct net_stat *net;
1400 struct diskio_stat *diskio;
1401 unsigned char loadavg[3];
1402 unsigned int cpu_index;
1403 struct mail_s *mail;
1411 char *tz; /* timezone variable */
1412 char *fmt; /* time display formatting */
1450 /* If not -1, a file descriptor to read from when
1451 * logfile is a FIFO. */
1468 timed_thread *p_timed_thread;
1474 #ifdef TCP_PORT_MONITOR
1476 /* starting port to monitor */
1477 in_port_t port_range_begin;
1478 /* ending port to monitor */
1479 in_port_t port_range_end;
1480 /* enum from libtcp-portmon.h, e.g. COUNT, etc. */
1482 /* 0 to n-1 connections. */
1483 int connection_index;
1517 struct local_mail_s local_mail;
1519 struct nvidia_s nvidia;
1526 unsigned int c, d, e;
1532 struct text_object_list {
1533 unsigned int text_object_count;
1534 struct text_object *text_objects;
1537 static struct text_object_list *global_text_object_list;
1539 static void generate_text_internal(char *p, int p_max_size,
1540 struct text_object_list *text_object_list,
1541 struct information *cur);
1543 #define MAXDATASIZE 1000
1547 struct mail_s *parse_mail_args(char type, const char *arg)
1549 struct mail_s *mail;
1552 mail = malloc(sizeof(struct mail_s));
1553 memset(mail, 0, sizeof(struct mail_s));
1555 if (sscanf(arg, "%128s %128s %128s", mail->host, mail->user, mail->pass)
1558 ERR("Scanning IMAP args failed");
1559 } else if (type == IMAP) {
1560 ERR("Scanning POP3 args failed");
1563 // see if password needs prompting
1564 if (mail->pass[0] == '*' && mail->pass[1] == '\0') {
1565 int fp = fileno(stdin);
1566 struct termios term;
1568 tcgetattr(fp, &term);
1569 term.c_lflag &= ~ECHO;
1570 tcsetattr(fp, TCSANOW, &term);
1571 printf("Enter mailbox password (%s@%s): ", mail->user, mail->host);
1572 scanf("%128s", mail->pass);
1574 term.c_lflag |= ECHO;
1575 tcsetattr(fp, TCSANOW, &term);
1577 // now we check for optional args
1578 tmp = strstr(arg, "-r ");
1581 sscanf(tmp, "%u", &mail->retries);
1583 mail->retries = 5; // 5 retries after failure
1585 tmp = strstr(arg, "-i ");
1588 sscanf(tmp, "%f", &mail->interval);
1590 mail->interval = 300; // 5 minutes
1592 tmp = strstr(arg, "-p ");
1595 sscanf(tmp, "%lu", &mail->port);
1598 mail->port = 110; // default pop3 port
1599 } else if (type == IMAP) {
1600 mail->port = 143; // default imap port
1604 tmp = strstr(arg, "-f ");
1607 sscanf(tmp, "%s", mail->folder);
1609 strncpy(mail->folder, "INBOX", 128); // default imap inbox
1612 tmp = strstr(arg, "-e ");
1617 if (tmp[0] == '\'') {
1618 len = strstr(tmp + 1, "'") - tmp - 1;
1623 strncpy(mail->command, tmp + 1, len);
1625 mail->command[0] = '\0';
1627 mail->p_timed_thread = NULL;
1631 void *imap_thread(void *arg)
1633 int sockfd, numbytes;
1634 char recvbuf[MAXDATASIZE];
1635 char sendbuf[MAXDATASIZE];
1637 unsigned int fail = 0;
1638 unsigned int old_unseen = UINT_MAX;
1639 unsigned int old_messages = UINT_MAX;
1640 struct stat stat_buf;
1641 struct hostent he, *he_res = 0;
1643 char hostbuff[2048];
1644 struct sockaddr_in their_addr; // connector's address information
1645 struct mail_s *mail = (struct mail_s *)arg;
1647 #ifdef HAVE_GETHOSTBYNAME_R
1648 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1649 ERR("IMAP gethostbyname_r: %s", hstrerror(h_errno));
1652 #else /* HAVE_GETHOSTBYNAME_R */
1653 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1654 herror("gethostbyname");
1657 #endif /* HAVE_GETHOSTBYNAME_R */
1658 while (fail < mail->retries) {
1659 struct timeval timeout;
1664 ERR("Trying IMAP connection again for %s@%s (try %u/%u)",
1665 mail->user, mail->host, fail + 1, mail->retries);
1668 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1675 their_addr.sin_family = AF_INET;
1676 // short, network byte order
1677 their_addr.sin_port = htons(mail->port);
1678 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1679 // zero the rest of the struct
1680 memset(&(their_addr.sin_zero), '\0', 8);
1682 if (connect(sockfd, (struct sockaddr *) &their_addr,
1683 sizeof(struct sockaddr)) == -1) {
1689 timeout.tv_sec = 60; // 60 second timeout i guess
1690 timeout.tv_usec = 0;
1692 FD_SET(sockfd, &fdset);
1693 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1695 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1701 ERR("IMAP connection failed: timeout");
1705 recvbuf[numbytes] = '\0';
1706 if (strstr(recvbuf, "* OK") != recvbuf) {
1707 ERR("IMAP connection failed, probably not an IMAP server");
1711 strncpy(sendbuf, "a1 login ", MAXDATASIZE);
1712 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1713 strncat(sendbuf, " ", MAXDATASIZE - strlen(sendbuf) - 1);
1714 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1715 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1716 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1721 timeout.tv_sec = 60; // 60 second timeout i guess
1722 timeout.tv_usec = 0;
1724 FD_SET(sockfd, &fdset);
1725 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1727 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1733 recvbuf[numbytes] = '\0';
1734 if (strstr(recvbuf, "a1 OK") == NULL) {
1735 ERR("IMAP server login failed: %s", recvbuf);
1739 strncpy(sendbuf, "a2 STATUS ", MAXDATASIZE);
1740 strncat(sendbuf, mail->folder, MAXDATASIZE - strlen(sendbuf) - 1);
1741 strncat(sendbuf, " (MESSAGES UNSEEN)\r\n",
1742 MAXDATASIZE - strlen(sendbuf) - 1);
1743 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1748 timeout.tv_sec = 60; // 60 second timeout i guess
1749 timeout.tv_usec = 0;
1751 FD_SET(sockfd, &fdset);
1752 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1754 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1760 recvbuf[numbytes] = '\0';
1761 if (strstr(recvbuf, "a2 OK") == NULL) {
1762 ERR("IMAP status failed: %s", recvbuf);
1766 // now we get the data
1767 reply = strstr(recvbuf, " (MESSAGES ");
1769 *strchr(reply, ')') = '\0';
1770 if (reply == NULL) {
1771 ERR("Error parsing IMAP response: %s", recvbuf);
1775 timed_thread_lock(mail->p_timed_thread);
1776 sscanf(reply, "MESSAGES %lu UNSEEN %lu", &mail->messages,
1778 timed_thread_unlock(mail->p_timed_thread);
1780 strncpy(sendbuf, "a3 logout\r\n", MAXDATASIZE);
1781 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1786 timeout.tv_sec = 60; // 60 second timeout i guess
1787 timeout.tv_usec = 0;
1789 FD_SET(sockfd, &fdset);
1790 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1792 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1798 recvbuf[numbytes] = '\0';
1799 if (strstr(recvbuf, "a3 OK") == NULL) {
1800 ERR("IMAP logout failed: %s", recvbuf);
1804 if (strlen(mail->command) > 1 && (mail->unseen > old_unseen
1805 || (mail->messages > old_messages && mail->unseen > 0))) {
1807 if (system(mail->command) == -1) {
1812 old_unseen = mail->unseen;
1813 old_messages = mail->messages;
1815 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
1816 /* if a valid socket, close it */
1819 if (timed_thread_test(mail->p_timed_thread)) {
1820 timed_thread_exit(mail->p_timed_thread);
1828 void *pop3_thread(void *arg)
1830 int sockfd, numbytes;
1831 char recvbuf[MAXDATASIZE];
1832 char sendbuf[MAXDATASIZE];
1834 unsigned int fail = 0;
1835 unsigned int old_unseen = UINT_MAX;
1836 struct stat stat_buf;
1837 struct hostent he, *he_res = 0;
1839 char hostbuff[2048];
1840 struct sockaddr_in their_addr; // connector's address information
1841 struct mail_s *mail = (struct mail_s *)arg;
1843 #ifdef HAVE_GETHOSTBYNAME_R
1844 if (gethostbyname_r(mail->host, &he, hostbuff, sizeof(hostbuff), &he_res, &he_errno)) { // get the host info
1845 ERR("POP3 gethostbyname_r: %s", hstrerror(h_errno));
1848 #else /* HAVE_GETHOSTBYNAME_R */
1849 if ((he_res = gethostbyname(mail->host)) == NULL) { // get the host info
1850 herror("gethostbyname");
1853 #endif /* HAVE_GETHOSTBYNAME_R */
1854 while (fail < mail->retries) {
1855 struct timeval timeout;
1860 ERR("Trying POP3 connection again for %s@%s (try %u/%u)",
1861 mail->user, mail->host, fail + 1, mail->retries);
1864 if ((sockfd = socket(PF_INET, SOCK_STREAM, 0)) == -1) {
1871 their_addr.sin_family = AF_INET;
1872 // short, network byte order
1873 their_addr.sin_port = htons(mail->port);
1874 their_addr.sin_addr = *((struct in_addr *) he_res->h_addr);
1875 // zero the rest of the struct
1876 memset(&(their_addr.sin_zero), '\0', 8);
1878 if (connect(sockfd, (struct sockaddr *) &their_addr,
1879 sizeof(struct sockaddr)) == -1) {
1885 timeout.tv_sec = 60; // 60 second timeout i guess
1886 timeout.tv_usec = 0;
1888 FD_SET(sockfd, &fdset);
1889 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1891 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1897 ERR("POP3 connection failed: timeout\n");
1901 recvbuf[numbytes] = '\0';
1902 if (strstr(recvbuf, "+OK ") != recvbuf) {
1903 ERR("POP3 connection failed, probably not a POP3 server");
1907 strncpy(sendbuf, "USER ", MAXDATASIZE);
1908 strncat(sendbuf, mail->user, MAXDATASIZE - strlen(sendbuf) - 1);
1909 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1910 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1911 perror("send USER");
1915 timeout.tv_sec = 60; // 60 second timeout i guess
1916 timeout.tv_usec = 0;
1918 FD_SET(sockfd, &fdset);
1919 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1921 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1922 perror("recv USER");
1927 recvbuf[numbytes] = '\0';
1928 if (strstr(recvbuf, "+OK ") == NULL) {
1929 ERR("POP3 server login failed: %s", recvbuf);
1933 strncpy(sendbuf, "PASS ", MAXDATASIZE);
1934 strncat(sendbuf, mail->pass, MAXDATASIZE - strlen(sendbuf) - 1);
1935 strncat(sendbuf, "\r\n", MAXDATASIZE - strlen(sendbuf) - 1);
1936 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1937 perror("send PASS");
1941 timeout.tv_sec = 60; // 60 second timeout i guess
1942 timeout.tv_usec = 0;
1944 FD_SET(sockfd, &fdset);
1945 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1947 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1948 perror("recv PASS");
1953 recvbuf[numbytes] = '\0';
1954 if (strstr(recvbuf, "+OK ") == NULL) {
1955 ERR("POP3 server login failed: %s", recvbuf);
1959 strncpy(sendbuf, "STAT\r\n", MAXDATASIZE);
1960 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1961 perror("send STAT");
1965 timeout.tv_sec = 60; // 60 second timeout i guess
1966 timeout.tv_usec = 0;
1968 FD_SET(sockfd, &fdset);
1969 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
1971 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
1972 perror("recv STAT");
1977 recvbuf[numbytes] = '\0';
1978 if (strstr(recvbuf, "+OK ") == NULL) {
1979 ERR("POP3 status failed: %s", recvbuf);
1983 // now we get the data
1984 reply = recvbuf + 4;
1985 if (reply == NULL) {
1986 ERR("Error parsing POP3 response: %s", recvbuf);
1990 timed_thread_lock(mail->p_timed_thread);
1991 sscanf(reply, "%lu %lu", &mail->unseen, &mail->used);
1992 timed_thread_unlock(mail->p_timed_thread);
1994 strncpy(sendbuf, "QUIT\r\n", MAXDATASIZE);
1995 if (send(sockfd, sendbuf, strlen(sendbuf), 0) == -1) {
1996 perror("send QUIT");
2000 timeout.tv_sec = 60; // 60 second timeout i guess
2001 timeout.tv_usec = 0;
2003 FD_SET(sockfd, &fdset);
2004 res = select(sockfd + 1, &fdset, NULL, NULL, &timeout);
2006 if ((numbytes = recv(sockfd, recvbuf, MAXDATASIZE - 1, 0)) == -1) {
2007 perror("recv QUIT");
2012 recvbuf[numbytes] = '\0';
2013 if (strstr(recvbuf, "+OK") == NULL) {
2014 ERR("POP3 logout failed: %s", recvbuf);
2018 if (strlen(mail->command) > 1 && mail->unseen > old_unseen) {
2020 if (system(mail->command) == -1) {
2025 old_unseen = mail->unseen;
2027 if ((fstat(sockfd, &stat_buf) == 0) && S_ISSOCK(stat_buf.st_mode)) {
2028 /* if a valid socket, close it */
2031 if (timed_thread_test(mail->p_timed_thread)) {
2032 timed_thread_exit(mail->p_timed_thread);
2040 static inline void read_exec(const char *data, char *buf, const int size)
2042 FILE *fp = popen(data, "r");
2043 int length = fread(buf, 1, size, fp);
2047 if (length > 0 && buf[length - 1] == '\n') {
2048 buf[length - 1] = '\0';
2052 void *threaded_exec(void *) __attribute__((noreturn));
2054 void *threaded_exec(void *arg)
2057 struct text_object *obj = (struct text_object *)arg;
2060 p2 = obj->data.texeci.buffer;
2061 timed_thread_lock(obj->data.texeci.p_timed_thread);
2062 read_exec(obj->data.texeci.cmd, obj->data.texeci.buffer,
2065 if (*p2 == '\001') {
2070 timed_thread_unlock(obj->data.texeci.p_timed_thread);
2071 if (timed_thread_test(obj->data.texeci.p_timed_thread)) {
2072 timed_thread_exit(obj->data.texeci.p_timed_thread);
2078 static struct text_object *new_text_object_internal(void)
2080 struct text_object *obj = malloc(sizeof(struct text_object));
2081 memset(obj, 0, sizeof(struct text_object));
2086 * call with full == 0 when freeing after 'internal' evaluation of objects
2088 static void free_text_objects(struct text_object_list *text_object_list, char full)
2091 struct text_object *obj;
2093 if (text_object_list == NULL) {
2097 for (i = 0; i < text_object_list->text_object_count; i++) {
2098 obj = &text_object_list->text_objects[i];
2099 switch (obj->type) {
2108 close(obj->data.sysfs.fd);
2110 #endif /* !__OpenBSD__ */
2116 free(obj->data.tztime.tz);
2117 free(obj->data.tztime.fmt);
2120 free(obj->data.mboxscan.args);
2121 free(obj->data.mboxscan.output);
2125 free(obj->data.local_mail.box);
2130 case OBJ_imap_unseen:
2131 if (!obj->global_mode) {
2132 free(obj->data.mail);
2135 case OBJ_imap_messages:
2136 if (!obj->global_mode) {
2137 free(obj->data.mail);
2143 case OBJ_pop3_unseen:
2144 if (!obj->global_mode) {
2145 free(obj->data.mail);
2149 if (!obj->global_mode) {
2150 free(obj->data.mail);
2154 case OBJ_if_existing:
2155 case OBJ_if_mounted:
2156 case OBJ_if_running:
2157 free(obj->data.ifblock.s);
2158 free(obj->data.ifblock.str);
2161 free(obj->data.tail.logfile);
2162 free(obj->data.tail.buffer);
2174 case OBJ_iconv_start:
2179 case OBJ_disk_protect:
2180 free(objs[i].data.s);
2183 free(objs[i].data.ifblock.s);
2184 free(objs[i].data.ifblock.str);
2187 free(objs[i].data.ifblock.s);
2188 free(objs[i].data.ifblock.str);
2191 if (info.gw_info.iface) {
2192 free(info.gw_info.iface);
2193 info.gw_info.iface = 0;
2195 if (info.gw_info.ip) {
2196 free(info.gw_info.ip);
2197 info.gw_info.ip = 0;
2200 case OBJ_ioscheduler:
2202 free(objs[i].data.s);
2206 case OBJ_xmms2_artist:
2207 if (info.xmms2.artist) {
2208 free(info.xmms2.artist);
2209 info.xmms2.artist = 0;
2212 case OBJ_xmms2_album:
2213 if (info.xmms2.album) {
2214 free(info.xmms2.album);
2215 info.xmms2.album = 0;
2218 case OBJ_xmms2_title:
2219 if (info.xmms2.title) {
2220 free(info.xmms2.title);
2221 info.xmms2.title = 0;
2224 case OBJ_xmms2_genre:
2225 if (info.xmms2.genre) {
2226 free(info.xmms2.genre);
2227 info.xmms2.genre = 0;
2230 case OBJ_xmms2_comment:
2231 if (info.xmms2.comment) {
2232 free(info.xmms2.comment);
2233 info.xmms2.comment = 0;
2237 if (info.xmms2.url) {
2238 free(info.xmms2.url);
2242 case OBJ_xmms2_date:
2243 if (info.xmms2.date) {
2244 free(info.xmms2.date);
2245 info.xmms2.date = 0;
2248 case OBJ_xmms2_status:
2249 if (info.xmms2.status) {
2250 free(info.xmms2.status);
2251 info.xmms2.status = 0;
2254 case OBJ_xmms2_playlist:
2255 if (info.xmms2.playlist) {
2256 free(info.xmms2.playlist);
2257 info.xmms2.playlist = 0;
2260 case OBJ_xmms2_smart:
2261 if (info.xmms2.artist) {
2262 free(info.xmms2.artist);
2263 info.xmms2.artist = 0;
2265 if (info.xmms2.title) {
2266 free(info.xmms2.title);
2267 info.xmms2.title = 0;
2269 if (info.xmms2.url) {
2270 free(info.xmms2.url);
2276 case OBJ_bmpx_title:
2277 case OBJ_bmpx_artist:
2278 case OBJ_bmpx_album:
2279 case OBJ_bmpx_track:
2281 case OBJ_bmpx_bitrate:
2290 free(obj->data.rss.uri);
2291 free(obj->data.rss.action);
2300 case OBJ_battery_time:
2303 #endif /* !__OpenBSD__ */
2307 case OBJ_execigraph:
2308 free(obj->data.execi.cmd);
2309 free(obj->data.execi.buffer);
2312 free(obj->data.texeci.cmd);
2313 free(obj->data.texeci.buffer);
2315 case OBJ_nameserver:
2320 if (info.first_process) {
2321 free_all_processes();
2322 info.first_process = NULL;
2327 free(obj->data.hddtemp.dev);
2328 free(obj->data.hddtemp.addr);
2329 free(obj->data.hddtemp.temp);
2332 case OBJ_entropy_avail:
2333 case OBJ_entropy_poolsize:
2334 case OBJ_entropy_bar:
2336 case OBJ_user_names:
2337 if (info.users.names) {
2338 free(info.users.names);
2339 info.users.names = 0;
2342 case OBJ_user_terms:
2343 if (info.users.terms) {
2344 free(info.users.terms);
2345 info.users.terms = 0;
2348 case OBJ_user_times:
2349 if (info.users.times) {
2350 free(info.users.times);
2351 info.users.times = 0;
2356 case OBJ_smapi_bat_perc:
2357 case OBJ_smapi_bat_temp:
2358 case OBJ_smapi_bat_power:
2361 case OBJ_if_smapi_bat_installed:
2362 free(obj->data.ifblock.s);
2363 free(obj->data.ifblock.str);
2372 case OBJ_mpd_artist:
2374 case OBJ_mpd_random:
2375 case OBJ_mpd_repeat:
2377 case OBJ_mpd_bitrate:
2378 case OBJ_mpd_status:
2381 case OBJ_mpd_password:
2383 case OBJ_mpd_elapsed:
2384 case OBJ_mpd_length:
2388 case OBJ_mpd_percent:
2391 free_mpd_vars(&info.mpd);
2396 free(obj->data.scroll.text);
2400 free(text_object_list->text_objects);
2401 text_object_list->text_objects = NULL;
2402 text_object_list->text_object_count = 0;
2405 void scan_mixer_bar(const char *arg, int *a, int *w, int *h)
2410 if (arg && sscanf(arg, "%63s %n", buf1, &n) >= 1) {
2411 *a = mixer_init(buf1);
2412 scan_bar(arg + n, w, h);
2414 *a = mixer_init(NULL);
2415 scan_bar(arg, w, h);
2419 /* strip a leading /dev/ if any */
2420 #define DEV_NAME(x) x != NULL && strlen(x) > 5 && strncmp(x, "/dev/", 5) == 0 \
2423 /* construct_text_object() creates a new text_object */
2424 static struct text_object *construct_text_object(const char *s,
2425 const char *arg, unsigned int object_count,
2426 struct text_object *text_objects, long line, char allow_threaded)
2428 // struct text_object *obj = new_text_object();
2429 struct text_object *obj = new_text_object_internal();
2433 #define OBJ(a, n) if (strcmp(s, #a) == 0) { \
2434 obj->type = OBJ_##a; need_mask |= (1 << n); {
2435 #define OBJ_THREAD(a, n) if (strcmp(s, #a) == 0 && allow_threaded) { \
2436 obj->type = OBJ_##a; need_mask |= (1 << n); {
2437 #define END } } else
2441 obj->type = OBJ_color;
2442 obj->data.l = get_x11_color(s);
2446 OBJ(freq, INFO_FREQ)
2449 obj->data.i = open_acpi_temperature(arg);
2450 END OBJ(acpitempf, 0)
2451 obj->data.i = open_acpi_temperature(arg);
2452 END OBJ(acpiacadapter, 0)
2453 END OBJ(freq, INFO_FREQ)
2454 #endif /* !__OpenBSD__ */
2456 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2457 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2458 obj->data.cpu_index = 1;
2459 /* ERR("freq: Invalid CPU number or you don't have that many CPUs! "
2460 "Displaying the clock for CPU 1."); */
2462 obj->data.cpu_index = atoi(&arg[0]);
2465 END OBJ(freq_g, INFO_FREQ)
2467 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2468 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2469 obj->data.cpu_index = 1;
2470 /* ERR("freq_g: Invalid CPU number or you don't have that many "
2471 "CPUs! Displaying the clock for CPU 1."); */
2473 obj->data.cpu_index = atoi(&arg[0]);
2476 #if defined(__linux__)
2477 END OBJ(voltage_mv, 0)
2479 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2480 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2481 obj->data.cpu_index = 1;
2482 /* ERR("voltage_mv: Invalid CPU number or you don't have that many "
2483 "CPUs! Displaying voltage for CPU 1."); */
2485 obj->data.cpu_index = atoi(&arg[0]);
2488 END OBJ(voltage_v, 0)
2490 if (!arg || !isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) == 0
2491 || (unsigned int) atoi(&arg[0]) > info.cpu_count) {
2492 obj->data.cpu_index = 1;
2493 /* ERR("voltage_v: Invalid CPU number or you don't have that many "
2494 "CPUs! Displaying voltage for CPU 1."); */
2496 obj->data.cpu_index = atoi(&arg[0]);
2501 END OBJ(wireless_essid, INFO_NET)
2503 obj->data.net = get_net_stat(arg);
2505 CRIT_ERR("wireless_essid: needs an argument");
2507 END OBJ(wireless_mode, INFO_NET)
2509 obj->data.net = get_net_stat(arg);
2511 CRIT_ERR("wireless_mode: needs an argument");
2513 END OBJ(wireless_bitrate, INFO_NET)
2515 obj->data.net = get_net_stat(arg);
2517 CRIT_ERR("wireless_bitrate: needs an argument");
2519 END OBJ(wireless_ap, INFO_NET)
2521 obj->data.net = get_net_stat(arg);
2523 CRIT_ERR("wireless_ap: needs an argument");
2525 END OBJ(wireless_link_qual, INFO_NET)
2527 obj->data.net = get_net_stat(arg);
2529 CRIT_ERR("wireless_link_qual: needs an argument");
2531 END OBJ(wireless_link_qual_max, INFO_NET)
2533 obj->data.net = get_net_stat(arg);
2535 CRIT_ERR("wireless_link_qual_max: needs an argument");
2537 END OBJ(wireless_link_qual_perc, INFO_NET)
2539 obj->data.net = get_net_stat(arg);
2541 CRIT_ERR("wireless_link_qual_perc: needs an argument");
2543 END OBJ(wireless_link_bar, INFO_NET)
2545 arg = scan_bar(arg, &obj->a, &obj->b);
2546 obj->data.net = get_net_stat(arg);
2548 CRIT_ERR("wireless_link_bar: needs an argument");
2550 #endif /* HAVE_IWLIB */
2552 #endif /* __linux__ */
2553 END OBJ(freq_dyn, 0)
2554 END OBJ(freq_dyn_g, 0)
2562 sscanf(arg, "%63s", bat);
2564 strcpy(bat, "BAT0");
2566 obj->data.s = strndup(bat, text_buffer_size);
2567 END OBJ(battery_time, 0)
2571 sscanf(arg, "%63s", bat);
2573 strcpy(bat, "BAT0");
2575 obj->data.s = strndup(bat, text_buffer_size);
2576 END OBJ(battery_percent, 0)
2580 sscanf(arg, "%63s", bat);
2582 strcpy(bat, "BAT0");
2584 obj->data.s = strndup(bat, text_buffer_size);
2585 END OBJ(battery_bar, 0)
2589 arg = scan_bar(arg, &obj->a, &obj->b);
2590 sscanf(arg, "%63s", bat);
2592 strcpy(bat, "BAT0");
2594 obj->data.s = strndup(bat, text_buffer_size);
2595 #endif /* !__OpenBSD__ */
2597 #if defined(__linux__)
2598 END OBJ(disk_protect, 0)
2600 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2602 CRIT_ERR("disk_protect needs an argument");
2603 END OBJ(i8k_version, INFO_I8K)
2604 END OBJ(i8k_bios, INFO_I8K)
2605 END OBJ(i8k_serial, INFO_I8K)
2606 END OBJ(i8k_cpu_temp, INFO_I8K)
2607 END OBJ(i8k_cpu_tempf, INFO_I8K)
2608 END OBJ(i8k_left_fan_status, INFO_I8K)
2609 END OBJ(i8k_right_fan_status, INFO_I8K)
2610 END OBJ(i8k_left_fan_rpm, INFO_I8K)
2611 END OBJ(i8k_right_fan_rpm, INFO_I8K)
2612 END OBJ(i8k_ac_status, INFO_I8K)
2613 END OBJ(i8k_buttons_status, INFO_I8K)
2615 END OBJ(ibm_temps, 0)
2617 CRIT_ERR("ibm_temps: needs an argument");
2619 if (!isdigit(arg[0]) || strlen(arg) >= 2 || atoi(&arg[0]) >= 8) {
2620 obj->data.sensor = 0;
2621 ERR("Invalid temperature sensor! Sensor number must be 0 to 7. "
2622 "Using 0 (CPU temp sensor).");
2624 obj->data.sensor = atoi(&arg[0]);
2625 END OBJ(ibm_volume, 0)
2626 END OBJ(ibm_brightness, 0)
2628 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2629 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2632 ERR("if_up needs an argument");
2633 obj->data.ifblock.s = 0;
2635 obj->data.ifblock.s = strndup(arg, text_buffer_size);
2636 blockstart[blockdepth] = object_count;
2637 obj->data.ifblock.pos = object_count + 2;
2640 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
2641 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
2643 blockstart[blockdepth] = object_count;
2644 obj->data.ifblock.pos = object_count + 2;
2646 END OBJ(ioscheduler, 0)
2648 CRIT_ERR("get_ioscheduler needs an argument (e.g. hda)");
2651 obj->data.s = strndup(DEV_NAME(arg), text_buffer_size);
2652 END OBJ(laptop_mode, 0)
2653 END OBJ(pb_battery, 0)
2654 if (arg && strcmp(arg, "status") == EQUAL) {
2655 obj->data.i = PB_BATT_STATUS;
2656 } else if (arg && strcmp(arg, "percent") == EQUAL) {
2657 obj->data.i = PB_BATT_PERCENT;
2658 } else if (arg && strcmp(arg, "time") == EQUAL) {
2659 obj->data.i = PB_BATT_TIME;
2661 ERR("pb_battery: needs one argument: status, percent or time");
2666 #endif /* __linux__ */
2667 #if defined(__OpenBSD__)
2668 END OBJ(obsd_sensors_temp, 0)
2670 CRIT_ERR("obsd_sensors_temp: needs an argument");
2672 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2673 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2674 obj->data.sensor = 0;
2675 ERR("Invalid temperature sensor number!");
2677 obj->data.sensor = atoi(&arg[0]);
2678 END OBJ(obsd_sensors_fan, 0)
2680 CRIT_ERR("obsd_sensors_fan: needs 2 arguments (device and sensor "
2683 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2684 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2685 obj->data.sensor = 0;
2686 ERR("Invalid fan sensor number!");
2688 obj->data.sensor = atoi(&arg[0]);
2689 END OBJ(obsd_sensors_volt, 0)
2691 CRIT_ERR("obsd_sensors_volt: needs 2 arguments (device and sensor "
2694 if (!isdigit(arg[0]) || atoi(&arg[0]) < 0
2695 || atoi(&arg[0]) > OBSD_MAX_SENSORS - 1) {
2696 obj->data.sensor = 0;
2697 ERR("Invalid voltage sensor number!");
2699 obj->data.sensor = atoi(&arg[0]);
2700 END OBJ(obsd_vendor, 0)
2701 END OBJ(obsd_product, 0)
2702 #endif /* __OpenBSD__ */
2703 END OBJ(buffers, INFO_BUFFERS)
2704 END OBJ(cached, INFO_BUFFERS)
2705 END OBJ(cpu, INFO_CPU)
2707 if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
2708 obj->data.cpu_index = atoi(&arg[3]);
2711 obj->data.cpu_index = 0;
2714 obj->data.cpu_index = 0;
2716 END OBJ(cpubar, INFO_CPU)
2718 if (strncmp(arg, "cpu", 3) == EQUAL && isdigit(arg[3])) {
2719 obj->data.cpu_index = atoi(&arg[3]);
2722 obj->data.cpu_index = 0;
2724 scan_bar(arg, &obj->a, &obj->b);
2726 scan_bar(arg, &obj->a, &obj->b);
2727 obj->data.cpu_index = 0;
2729 END OBJ(cpugraph, INFO_CPU)
2730 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2731 &obj->e, &obj->showaslog);
2734 if (strncmp(buf, "cpu", 3) == EQUAL && isdigit(buf[3])) {
2735 obj->data.cpu_index = atoi(&buf[3]);
2737 obj->data.cpu_index = 0;
2741 END OBJ(loadgraph, INFO_LOADAVG)
2742 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2743 &obj->e, &obj->showaslog);
2747 r = sscanf(arg, "%d", &a);
2749 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
2752 #if defined(__linux__)
2753 END OBJ(diskio, INFO_DISKIO)
2755 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2757 obj->data.diskio = NULL;
2759 END OBJ(diskio_read, INFO_DISKIO)
2761 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2763 obj->data.diskio = NULL;
2765 END OBJ(diskio_write, INFO_DISKIO)
2767 obj->data.diskio = prepare_diskio_stat(DEV_NAME(arg));
2769 obj->data.diskio = NULL;
2771 END OBJ(diskiograph, INFO_DISKIO)
2772 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2773 &obj->e, &obj->showaslog);
2776 obj->data.diskio = prepare_diskio_stat(buf);
2779 obj->data.diskio = NULL;
2781 END OBJ(diskiograph_read, INFO_DISKIO)
2782 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2783 &obj->e, &obj->showaslog);
2786 obj->data.diskio = prepare_diskio_stat(buf);
2789 obj->data.diskio = NULL;
2791 END OBJ(diskiograph_write, INFO_DISKIO)
2792 char *buf = scan_graph(DEV_NAME(arg), &obj->a, &obj->b, &obj->c, &obj->d,
2793 &obj->e, &obj->showaslog);
2796 obj->data.diskio = prepare_diskio_stat(buf);
2799 obj->data.diskio = NULL;
2804 obj->data.l = arg ? get_x11_color(arg) : default_fg_color;
2807 obj->data.l = color0;
2809 obj->data.l = color1;
2811 obj->data.l = color2;
2813 obj->data.l = color3;
2815 obj->data.l = color4;
2817 obj->data.l = color5;
2819 obj->data.l = color6;
2821 obj->data.l = color7;
2823 obj->data.l = color8;
2825 obj->data.l = color9;
2827 obj->data.s = scan_font(arg);
2828 END OBJ(conky_version, 0)
2829 END OBJ(conky_build_date, 0)
2830 END OBJ(conky_build_arch, 0)
2831 END OBJ(downspeed, INFO_NET)
2833 obj->data.net = get_net_stat(arg);
2835 CRIT_ERR("downspeed needs argument");
2837 END OBJ(downspeedf, INFO_NET)
2839 obj->data.net = get_net_stat(arg);
2841 CRIT_ERR("downspeedf needs argument");
2843 END OBJ(downspeedgraph, INFO_NET)
2844 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
2845 &obj->e, &obj->showaslog);
2847 // default to DEFAULTNETDEV
2848 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
2849 obj->data.net = get_net_stat(buf);
2853 (text_objects[blockstart[blockdepth - 1]]).data.ifblock.pos =
2855 blockstart[blockdepth - 1] = object_count;
2856 obj->data.ifblock.pos = object_count + 2;
2858 ERR("$else: no matching $if_*");
2863 text_objects[blockstart[blockdepth]].data.ifblock.pos =
2866 ERR("$endif: no matching $if_*");
2869 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2872 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2874 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2876 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2877 END OBJ(execgraph, 0)
2878 obj->data.s = strndup(arg ? arg : "", text_buffer_size);
2879 END OBJ(execibar, 0)
2882 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2885 ERR("${execibar <interval> command}");
2886 obj->type = OBJ_text;
2887 snprintf(buf, 256, "${%s}", s);
2888 obj->data.s = strndup(buf, text_buffer_size);
2890 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2892 END OBJ(execigraph, 0)
2895 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2898 ERR("${execigraph <interval> command}");
2899 obj->type = OBJ_text;
2900 snprintf(buf, 256, "${%s}", s);
2901 obj->data.s = strndup(buf, text_buffer_size);
2903 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2908 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2911 ERR("${execi <interval> command}");
2912 obj->type = OBJ_text;
2913 snprintf(buf, 256, "${%s}", s);
2914 obj->data.s = strndup(buf, text_buffer_size);
2916 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2917 obj->data.execi.buffer = malloc(text_buffer_size);
2922 if (!arg || sscanf(arg, "%f %n", &obj->data.execi.interval, &n) <= 0) {
2925 ERR("${execi <interval> command}");
2926 obj->type = OBJ_text;
2927 snprintf(buf, 256, "${%s}", s);
2928 obj->data.s = strndup(buf, text_buffer_size);
2930 obj->data.execi.cmd = strndup(arg + n, text_buffer_size);
2931 obj->data.execi.buffer = malloc(text_buffer_size);
2933 END OBJ_THREAD(texeci, 0)
2936 if (!arg || sscanf(arg, "%f %n", &obj->data.texeci.interval, &n) <= 0) {
2939 ERR("${texeci <interval> command}");
2940 obj->type = OBJ_text;
2941 snprintf(buf, 256, "${%s}", s);
2942 obj->data.s = strndup(buf, text_buffer_size);
2944 obj->data.texeci.cmd = strndup(arg + n, text_buffer_size);
2945 obj->data.texeci.buffer = malloc(text_buffer_size);
2947 obj->data.texeci.p_timed_thread = NULL;
2948 END OBJ(pre_exec, 0)
2949 obj->type = OBJ_text;
2953 read_exec(arg, buf, sizeof(buf));
2954 obj->data.s = strndup(buf, text_buffer_size);
2956 obj->data.s = strndup("", text_buffer_size);
2959 END OBJ(fs_bar, INFO_FS)
2960 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2962 while (isspace(*arg)) {
2971 obj->data.fsbar.fs = prepare_fs_stat(arg);
2972 END OBJ(fs_bar_free, INFO_FS)
2973 arg = scan_bar(arg, &obj->data.fsbar.w, &obj->data.fsbar.h);
2975 while (isspace(*arg)) {
2985 obj->data.fsbar.fs = prepare_fs_stat(arg);
2986 END OBJ(fs_free, INFO_FS)
2990 obj->data.fs = prepare_fs_stat(arg);
2991 END OBJ(fs_used_perc, INFO_FS)
2995 obj->data.fs = prepare_fs_stat(arg);
2996 END OBJ(fs_free_perc, INFO_FS)
3000 obj->data.fs = prepare_fs_stat(arg);
3001 END OBJ(fs_size, INFO_FS)
3005 obj->data.fs = prepare_fs_stat(arg);
3006 END OBJ(fs_type, INFO_FS)
3010 obj->data.fs = prepare_fs_stat(arg);
3011 END OBJ(fs_used, INFO_FS)
3015 obj->data.fs = prepare_fs_stat(arg);
3017 obj->data.i = arg ? atoi(arg) : 1;
3018 END OBJ(nameserver, INFO_DNS)
3019 obj->data.i = arg ? atoi(arg) : 0;
3021 obj->data.i = arg ? atoi(arg) : 1;
3023 obj->data.i = arg ? atoi(arg) : 1;
3027 ERR("goto needs arguments");
3028 obj->type = OBJ_text;
3029 obj->data.s = strndup("${goto}", text_buffer_size);
3033 obj->data.i = atoi(arg);
3039 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3040 sscanf(arg, "%d", &b);
3046 obj->data.pair.a = a;
3047 obj->data.pair.b = b;
3050 END OBJ(i2c, INFO_SYSFS)
3051 char buf1[64], buf2[64];
3055 ERR("i2c needs arguments");
3056 obj->type = OBJ_text;
3057 // obj->data.s = strndup("${i2c}", text_buffer_size);
3061 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3062 /* if scanf couldn't read three values, read type and num and use
3064 sscanf(arg, "%63s %d", buf2, &n);
3065 obj->data.sysfs.fd = open_i2c_sensor(0, buf2, n,
3066 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3067 strncpy(obj->data.sysfs.type, buf2, 63);
3069 obj->data.sysfs.fd = open_i2c_sensor(buf1, buf2, n,
3070 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3071 strncpy(obj->data.sysfs.type, buf2, 63);
3074 END OBJ(platform, INFO_SYSFS)
3075 char buf1[64], buf2[64];
3079 ERR("platform needs arguments");
3080 obj->type = OBJ_text;
3084 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3085 /* if scanf couldn't read three values, read type and num and use
3087 sscanf(arg, "%63s %d", buf2, &n);
3088 obj->data.sysfs.fd = open_platform_sensor(0, buf2, n,
3089 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3090 strncpy(obj->data.sysfs.type, buf2, 63);
3092 obj->data.sysfs.fd = open_platform_sensor(buf1, buf2, n,
3093 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3094 strncpy(obj->data.sysfs.type, buf2, 63);
3097 END OBJ(hwmon, INFO_SYSFS)
3098 char buf1[64], buf2[64];
3102 ERR("hwmon needs argumanets");
3103 obj->type = OBJ_text;
3107 if (sscanf(arg, "%63s %63s %d", buf1, buf2, &n) != 3) {
3108 /* if scanf couldn't read three values, read type and num and use
3110 sscanf(arg, "%63s %d", buf2, &n);
3111 obj->data.sysfs.fd = open_hwmon_sensor(0, buf2, n,
3112 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3113 strncpy(obj->data.sysfs.type, buf2, 63);
3115 obj->data.sysfs.fd = open_hwmon_sensor(buf1, buf2, n,
3116 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3117 strncpy(obj->data.sysfs.type, buf2, 63);
3119 #endif /* !__OpenBSD__ */
3121 END OBJ(top, INFO_TOP)
3126 ERR("top needs arguments");
3127 obj->type = OBJ_text;
3128 // obj->data.s = strndup("${top}", text_buffer_size);
3131 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3132 if (strcmp(buf, "name") == EQUAL) {
3133 obj->data.top.type = TOP_NAME;
3134 } else if (strcmp(buf, "cpu") == EQUAL) {
3135 obj->data.top.type = TOP_CPU;
3136 } else if (strcmp(buf, "pid") == EQUAL) {
3137 obj->data.top.type = TOP_PID;
3138 } else if (strcmp(buf, "mem") == EQUAL) {
3139 obj->data.top.type = TOP_MEM;
3140 } else if (strcmp(buf, "time") == EQUAL) {
3141 obj->data.top.type = TOP_TIME;
3142 } else if (strcmp(buf, "mem_res") == EQUAL) {
3143 obj->data.top.type = TOP_MEM_RES;
3144 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
3145 obj->data.top.type = TOP_MEM_VSIZE;
3147 ERR("invalid arg for top");
3150 if (n < 1 || n > 10) {
3151 CRIT_ERR("invalid arg for top");
3154 obj->data.top.num = n - 1;
3158 ERR("invalid args given for top");
3161 END OBJ(top_mem, INFO_TOP)
3166 ERR("top_mem needs arguments");
3167 obj->type = OBJ_text;
3168 obj->data.s = strndup("${top_mem}", text_buffer_size);
3171 if (sscanf(arg, "%63s %i", buf, &n) == 2) {
3172 if (strcmp(buf, "name") == EQUAL) {
3173 obj->data.top.type = TOP_NAME;
3174 } else if (strcmp(buf, "cpu") == EQUAL) {
3175 obj->data.top.type = TOP_CPU;
3176 } else if (strcmp(buf, "pid") == EQUAL) {
3177 obj->data.top.type = TOP_PID;
3178 } else if (strcmp(buf, "mem") == EQUAL) {
3179 obj->data.top.type = TOP_MEM;
3180 } else if (strcmp(buf, "time") == EQUAL) {
3181 obj->data.top.type = TOP_TIME;
3182 } else if (strcmp(buf, "mem_res") == EQUAL) {
3183 obj->data.top.type = TOP_MEM_RES;
3184 } else if (strcmp(buf, "mem_vsize") == EQUAL) {
3185 obj->data.top.type = TOP_MEM_VSIZE;
3187 ERR("invalid arg for top");
3190 if (n < 1 || n > 10) {
3191 CRIT_ERR("invalid arg for top");
3194 obj->data.top.num = n - 1;
3198 ERR("invalid args given for top");
3201 END OBJ(addr, INFO_NET)
3203 obj->data.net = get_net_stat(arg);
3205 CRIT_ERR("addr needs argument");
3207 #if defined(__linux__)
3208 END OBJ(addrs, INFO_NET)
3210 obj->data.net = get_net_stat(arg);
3212 CRIT_ERR("addrs needs argument");
3214 #endif /* __linux__ */
3221 ERR("tail needs arguments");
3222 obj->type = OBJ_text;
3223 obj->data.s = strndup("${tail}", text_buffer_size);
3226 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3227 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3228 CRIT_ERR("invalid arg for tail, number of lines must be "
3229 "between 1 and %i", MAX_TAIL_LINES);
3235 obj->data.tail.fd = -1;
3237 if (stat(buf, &st) == 0) {
3238 if (S_ISFIFO(st.st_mode)) {
3239 fd = open(buf, O_RDONLY | O_NONBLOCK);
3242 CRIT_ERR("tail logfile does not exist, or you do "
3243 "not have correct permissions");
3246 obj->data.tail.fd = fd;
3248 fp = fopen(buf, "r");
3252 if (fp || obj->data.tail.fd != -1) {
3253 obj->data.tail.logfile = malloc(text_buffer_size);
3254 strcpy(obj->data.tail.logfile, buf);
3255 obj->data.tail.wantedlines = n1;
3256 obj->data.tail.interval = update_interval * 2;
3258 if (obj->data.tail.fd == -1) {
3263 CRIT_ERR("tail logfile does not exist, or you do not have "
3264 "correct permissions");
3267 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3268 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3269 CRIT_ERR("invalid arg for tail, number of lines must be "
3270 "between 1 and %i", MAX_TAIL_LINES);
3272 } else if (n2 < 1 || n2 < update_interval) {
3273 CRIT_ERR("invalid arg for tail, interval must be greater than "
3274 "0 and "PACKAGE_NAME"'s interval");
3280 obj->data.tail.fd = -1;
3282 if (stat(buf, &st) == 0) {
3283 if (S_ISFIFO(st.st_mode)) {
3284 fd = open(buf, O_RDONLY | O_NONBLOCK);
3287 CRIT_ERR("tail logfile does not exist, or you do "
3288 "not have correct permissions");
3291 obj->data.tail.fd = fd;
3293 fp = fopen(buf, "r");
3297 if (fp || obj->data.tail.fd != -1) {
3298 obj->data.tail.logfile = malloc(text_buffer_size);
3299 strcpy(obj->data.tail.logfile, buf);
3300 obj->data.tail.wantedlines = n1;
3301 obj->data.tail.interval = n2;
3303 if (obj->data.tail.fd == -1) {
3308 CRIT_ERR("tail logfile does not exist, or you do not have "
3309 "correct permissions");
3313 ERR("invalid args given for tail");
3316 /* asumming all else worked */
3317 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3323 ERR("head needs arguments");
3324 obj->type = OBJ_text;
3325 obj->data.s = strndup("${head}", text_buffer_size);
3328 if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 2) {
3329 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3330 CRIT_ERR("invalid arg for head, number of lines must be "
3331 "between 1 and %i", MAX_TAIL_LINES);
3336 fp = fopen(buf, "r");
3338 obj->data.tail.logfile = malloc(text_buffer_size);
3339 strcpy(obj->data.tail.logfile, buf);
3340 obj->data.tail.wantedlines = n1;
3341 obj->data.tail.interval = update_interval * 2;
3345 CRIT_ERR("head logfile does not exist, or you do not have "
3346 "correct permissions");
3349 } else if (sscanf(arg, "%63s %i %i", buf, &n1, &n2) == 3) {
3350 if (n1 < 1 || n1 > MAX_TAIL_LINES) {
3351 CRIT_ERR("invalid arg for head, number of lines must be "
3352 "between 1 and %i", MAX_TAIL_LINES);
3354 } else if (n2 < 1 || n2 < update_interval) {
3355 CRIT_ERR("invalid arg for head, interval must be greater than "
3356 "0 and "PACKAGE_NAME"'s interval");
3361 fp = fopen(buf, "r");
3363 obj->data.tail.logfile = malloc(text_buffer_size);
3364 strcpy(obj->data.tail.logfile, buf);
3365 obj->data.tail.wantedlines = n1;
3366 obj->data.tail.interval = n2;
3370 CRIT_ERR("head logfile does not exist, or you do not have "
3371 "correct permissions");
3375 ERR("invalid args given for head");
3378 /* asumming all else worked */
3379 obj->data.tail.buffer = malloc(text_buffer_size * 20);
3382 obj->data.s = strdup(arg);
3384 CRIT_ERR("lines needs a argument");
3388 obj->data.s = strdup(arg);
3390 CRIT_ERR("words needs a argument");
3392 END OBJ(loadavg, INFO_LOADAVG)
3393 int a = 1, b = 2, c = 3, r = 3;
3396 r = sscanf(arg, "%d %d %d", &a, &b, &c);
3397 if (r >= 3 && (c < 1 || c > 3)) {
3400 if (r >= 2 && (b < 1 || b > 3)) {
3403 if (r >= 1 && (a < 1 || a > 3)) {
3407 obj->data.loadavg[0] = (r >= 1) ? (unsigned char) a : 0;
3408 obj->data.loadavg[1] = (r >= 2) ? (unsigned char) b : 0;
3409 obj->data.loadavg[2] = (r >= 3) ? (unsigned char) c : 0;
3410 END OBJ(if_empty, 0)
3411 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3412 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3415 ERR("if_empty needs an argument");
3416 obj->data.ifblock.s = 0;
3418 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3420 blockstart[blockdepth] = object_count;
3421 obj->data.ifblock.pos = object_count + 2;
3423 END OBJ(if_existing, 0)
3424 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3425 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3428 ERR("if_existing needs an argument or two");
3429 obj->data.ifblock.s = NULL;
3430 obj->data.ifblock.str = NULL;
3432 char buf1[256], buf2[256];
3433 int r = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3436 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3437 obj->data.ifblock.str = NULL;
3439 obj->data.ifblock.s = strndup(buf1, text_buffer_size);
3440 obj->data.ifblock.str = strndup(buf2, text_buffer_size);
3443 blockstart[blockdepth] = object_count;
3444 obj->data.ifblock.pos = object_count + 2;
3446 END OBJ(if_mounted, 0)
3447 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3448 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3451 ERR("if_mounted needs an argument");
3452 obj->data.ifblock.s = 0;
3454 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3456 blockstart[blockdepth] = object_count;
3457 obj->data.ifblock.pos = object_count + 2;
3459 END OBJ(if_running, 0)
3460 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3461 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3466 snprintf(buf, 256, "pidof %s >/dev/null", arg);
3467 obj->data.ifblock.s = strndup(buf, text_buffer_size);
3469 ERR("if_running needs an argument");
3470 obj->data.ifblock.s = 0;
3472 blockstart[blockdepth] = object_count;
3473 obj->data.ifblock.pos = object_count + 2;
3479 char box[256], dst[256];
3483 /* Kapil: Changed from MAIL_FILE to
3484 current_mail_spool since the latter
3485 is a copy of the former if undefined
3486 but the latter should take precedence
3488 strncpy(box, current_mail_spool, sizeof(box));
3490 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3492 strncpy(box, arg, sizeof(box));
3496 variable_substitute(box, dst, sizeof(dst));
3497 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3498 obj->data.local_mail.interval = n1;
3499 END OBJ(mboxscan, 0)
3500 obj->data.mboxscan.args = (char *) malloc(text_buffer_size);
3501 obj->data.mboxscan.output = (char *) malloc(text_buffer_size);
3502 /* if '1' (in mboxscan.c) then there was SIGUSR1, hmm */
3503 obj->data.mboxscan.output[0] = 1;
3504 strncpy(obj->data.mboxscan.args, arg, text_buffer_size);
3505 END OBJ(mem, INFO_MEM)
3506 END OBJ(memeasyfree, INFO_MEM)
3507 END OBJ(memfree, INFO_MEM)
3508 END OBJ(memmax, INFO_MEM)
3509 END OBJ(memperc, INFO_MEM)
3510 END OBJ(membar, INFO_MEM)
3511 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3512 END OBJ(memgraph, INFO_MEM)
3513 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3514 &obj->e, &obj->showaslog);
3519 END OBJ(mixer, INFO_MIXER)
3520 obj->data.l = mixer_init(arg);
3521 END OBJ(mixerl, INFO_MIXER)
3522 obj->data.l = mixer_init(arg);
3523 END OBJ(mixerr, INFO_MIXER)
3524 obj->data.l = mixer_init(arg);
3525 END OBJ(mixerbar, INFO_MIXER)
3526 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3527 &obj->data.mixerbar.h);
3528 END OBJ(mixerlbar, INFO_MIXER)
3529 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3530 &obj->data.mixerbar.h);
3531 END OBJ(mixerrbar, INFO_MIXER)
3532 scan_mixer_bar(arg, &obj->data.mixerbar.l, &obj->data.mixerbar.w,
3533 &obj->data.mixerbar.h);
3535 END OBJ(monitor, INFO_X11)
3536 END OBJ(monitor_number, INFO_X11)
3538 END OBJ(new_mails, 0)
3540 char box[256], dst[256];
3544 /* Kapil: Changed from MAIL_FILE to
3545 current_mail_spool since the latter
3546 is a copy of the former if undefined
3547 but the latter should take precedence
3549 strncpy(box, current_mail_spool, sizeof(box));
3551 if (sscanf(arg, "%s %f", box, &n1) != 2) {
3553 strncpy(box, arg, sizeof(box));
3557 variable_substitute(box, dst, sizeof(dst));
3558 obj->data.local_mail.box = strndup(dst, text_buffer_size);
3559 obj->data.local_mail.interval = n1;
3560 END OBJ(nodename, 0)
3561 END OBJ(processes, INFO_PROCS)
3562 END OBJ(running_processes, INFO_RUN_PROCS)
3563 END OBJ(shadecolor, 0)
3565 obj->data.l = arg ? get_x11_color(arg) : default_bg_color;
3567 END OBJ(outlinecolor, 0)
3569 obj->data.l = arg ? get_x11_color(arg) : default_out_color;
3571 END OBJ(stippled_hr, 0)
3573 int a = stippled_borders, b = 1;
3576 if (sscanf(arg, "%d %d", &a, &b) != 2) {
3577 sscanf(arg, "%d", &b);
3583 obj->data.pair.a = a;
3584 obj->data.pair.b = b;
3586 END OBJ(swap, INFO_MEM)
3587 END OBJ(swapmax, INFO_MEM)
3588 END OBJ(swapperc, INFO_MEM)
3589 END OBJ(swapbar, INFO_MEM)
3590 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3593 END OBJ(temp1, INFO_SYSFS)
3594 obj->type = OBJ_i2c;
3595 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 1,
3596 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3597 END OBJ(temp2, INFO_SYSFS)
3598 obj->type = OBJ_i2c;
3599 obj->data.sysfs.fd = open_i2c_sensor(0, "temp", 2,
3600 &obj->data.sysfs.arg, obj->data.sysfs.devtype);
3603 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3605 obj->data.s = strndup(arg ? arg : "%F %T", text_buffer_size);
3607 char buf1[256], buf2[256], *fmt, *tz;
3611 int nArgs = sscanf(arg, "%255s %255[^\n]", buf1, buf2);
3621 obj->data.tztime.fmt = strndup(fmt ? fmt : "%F %T", text_buffer_size);
3622 obj->data.tztime.tz = tz ? strndup(tz, text_buffer_size) : NULL;
3624 END OBJ(iconv_start, 0)
3625 if (iconv_converting) {
3626 CRIT_ERR("You must stop your last iconv conversion before "
3627 "starting another");
3630 char iconv_from[CODEPAGE_LENGTH];
3631 char iconv_to[CODEPAGE_LENGTH];
3633 if (sscanf(arg, "%s %s", iconv_from, iconv_to) != 2) {
3634 CRIT_ERR("Invalid arguments for iconv_start");
3638 new_iconv = iconv_open(iconv_to, iconv_from);
3639 if (new_iconv == (iconv_t) (-1)) {
3640 ERR("Can't convert from %s to %s.", iconv_from, iconv_to);
3642 obj->a = register_iconv(&new_iconv);
3643 iconv_converting = 1;
3647 CRIT_ERR("Iconv requires arguments");
3649 END OBJ(iconv_stop, 0)
3650 iconv_converting = 0;
3653 END OBJ(totaldown, INFO_NET)
3655 obj->data.net = get_net_stat(arg);
3657 CRIT_ERR("totaldown needs argument");
3659 END OBJ(totalup, INFO_NET)
3660 obj->data.net = get_net_stat(arg);
3662 obj->data.net = get_net_stat(arg);
3664 CRIT_ERR("totalup needs argument");
3668 obj->data.i = arg ? atoi(arg) : 0;
3670 obj->data.i = arg ? atoi(arg) : 0;
3671 END OBJ(upspeed, INFO_NET)
3673 obj->data.net = get_net_stat(arg);
3675 CRIT_ERR("upspeed needs argument");
3677 END OBJ(upspeedf, INFO_NET)
3679 obj->data.net = get_net_stat(arg);
3681 CRIT_ERR("upspeedf needs argument");
3684 END OBJ(upspeedgraph, INFO_NET)
3685 char *buf = scan_graph(arg, &obj->a, &obj->b, &obj->c, &obj->d,
3686 &obj->e, &obj->showaslog);
3688 // default to DEFAULTNETDEV
3689 buf = strndup(buf ? buf : "DEFAULTNETDEV", text_buffer_size);
3690 obj->data.net = get_net_stat(buf);
3692 END OBJ(uptime_short, INFO_UPTIME)
3693 END OBJ(uptime, INFO_UPTIME)
3694 END OBJ(user_names, INFO_USERS)
3695 END OBJ(user_times, INFO_USERS)
3696 END OBJ(user_terms, INFO_USERS)
3697 END OBJ(user_number, INFO_USERS)
3698 #if defined(__linux__)
3699 END OBJ(gw_iface, INFO_GW)
3700 END OBJ(gw_ip, INFO_GW)
3701 END OBJ(if_gw, INFO_GW)
3702 #endif /* !__linux__ */
3704 END OBJ(adt746xcpu, 0)
3705 END OBJ(adt746xfan, 0)
3706 #endif /* !__OpenBSD__ */
3707 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
3708 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
3709 END OBJ(apm_adapter, 0)
3710 END OBJ(apm_battery_life, 0)
3711 END OBJ(apm_battery_time, 0)
3712 #endif /* __FreeBSD__ */
3713 END OBJ_THREAD(imap_unseen, 0)
3716 obj->data.mail = parse_mail_args(IMAP, arg);
3717 obj->global_mode = 0;
3719 obj->global_mode = 1;
3721 END OBJ_THREAD(imap_messages, 0)
3724 obj->data.mail = parse_mail_args(IMAP, arg);
3725 obj->global_mode = 0;
3727 obj->global_mode = 1;
3729 END OBJ_THREAD(pop3_unseen, 0)
3732 obj->data.mail = parse_mail_args(POP3, arg);
3733 obj->global_mode = 0;
3735 obj->global_mode = 1;
3737 END OBJ_THREAD(pop3_used, 0)
3740 obj->data.mail = parse_mail_args(POP3, arg);
3741 obj->global_mode = 0;
3743 obj->global_mode = 1;
3749 obj->data.s = strndup(arg, text_buffer_size);
3751 ERR("smapi needs an argument");
3752 END OBJ(if_smapi_bat_installed, 0)
3753 if (blockdepth >= MAX_IF_BLOCK_DEPTH) {
3754 CRIT_ERR("MAX_IF_BLOCK_DEPTH exceeded");
3757 ERR("if_smapi_bat_installed needs an argument");
3758 obj->data.ifblock.s = 0;
3760 obj->data.ifblock.s = strndup(arg, text_buffer_size);
3761 blockstart[blockdepth] = object_count;
3762 obj->data.ifblock.pos = object_count + 2;
3764 END OBJ(smapi_bat_perc, 0)
3766 obj->data.s = strndup(arg, text_buffer_size);
3768 ERR("smapi_bat_perc needs an argument");
3769 END OBJ(smapi_bat_temp, 0)
3771 obj->data.s = strndup(arg, text_buffer_size);
3773 ERR("smapi_bat_temp needs an argument");
3774 END OBJ(smapi_bat_power, 0)
3776 obj->data.s = strndup(arg, text_buffer_size);
3778 ERR("smapi_bat_power needs an argument");
3779 END OBJ(smapi_bat_bar, 0)
3782 if(sscanf(arg, "%i %n", &obj->data.i, &cnt) <= 0) {
3783 ERR("first argument to smapi_bat_bar must be an integer value");
3787 arg = scan_bar(arg + cnt, &obj->a, &obj->b);
3790 ERR("if_smapi_bat_bar needs an argument");
3794 OBJ_THREAD(mpd_artist, INFO_MPD)
3795 END OBJ_THREAD(mpd_title, INFO_MPD)
3797 sscanf(arg, "%d", &info.mpd.max_title_len);
3798 if (info.mpd.max_title_len > 0) {
3799 info.mpd.max_title_len++;
3801 CRIT_ERR("mpd_title: invalid length argument");
3804 info.mpd.max_title_len = 0;
3806 END OBJ_THREAD(mpd_random, INFO_MPD)
3807 END OBJ_THREAD(mpd_repeat, INFO_MPD)
3808 END OBJ_THREAD(mpd_elapsed, INFO_MPD)
3809 END OBJ_THREAD(mpd_length, INFO_MPD)
3810 END OBJ_THREAD(mpd_track, INFO_MPD)
3811 END OBJ_THREAD(mpd_name, INFO_MPD)
3812 END OBJ_THREAD(mpd_file, INFO_MPD)
3813 END OBJ_THREAD(mpd_percent, INFO_MPD)
3814 END OBJ_THREAD(mpd_album, INFO_MPD)
3815 END OBJ_THREAD(mpd_vol, INFO_MPD)
3816 END OBJ_THREAD(mpd_bitrate, INFO_MPD)
3817 END OBJ_THREAD(mpd_status, INFO_MPD)
3818 END OBJ_THREAD(mpd_bar, INFO_MPD)
3819 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3820 END OBJ_THREAD(mpd_smart, INFO_MPD)
3823 OBJ(xmms2_artist, INFO_XMMS2)
3824 END OBJ(xmms2_album, INFO_XMMS2)
3825 END OBJ(xmms2_title, INFO_XMMS2)
3826 END OBJ(xmms2_genre, INFO_XMMS2)
3827 END OBJ(xmms2_comment, INFO_XMMS2)
3828 END OBJ(xmms2_url, INFO_XMMS2)
3829 END OBJ(xmms2_tracknr, INFO_XMMS2)
3830 END OBJ(xmms2_bitrate, INFO_XMMS2)
3831 END OBJ(xmms2_date, INFO_XMMS2)
3832 END OBJ(xmms2_id, INFO_XMMS2)
3833 END OBJ(xmms2_duration, INFO_XMMS2)
3834 END OBJ(xmms2_elapsed, INFO_XMMS2)
3835 END OBJ(xmms2_size, INFO_XMMS2)
3836 END OBJ(xmms2_status, INFO_XMMS2)
3837 END OBJ(xmms2_percent, INFO_XMMS2)
3838 END OBJ(xmms2_bar, INFO_XMMS2)
3839 scan_bar(arg, &obj->data.pair.a, &obj->data.pair.b);
3840 END OBJ(xmms2_smart, INFO_XMMS2)
3841 END OBJ(xmms2_playlist, INFO_XMMS2)
3842 END OBJ(xmms2_timesplayed, INFO_XMMS2)
3845 END OBJ(audacious_status, INFO_AUDACIOUS)
3846 END OBJ(audacious_title, INFO_AUDACIOUS)
3848 sscanf(arg, "%d", &info.audacious.max_title_len);
3849 if (info.audacious.max_title_len > 0) {
3850 info.audacious.max_title_len++;
3852 CRIT_ERR("audacious_title: invalid length argument");
3855 END OBJ(audacious_length, INFO_AUDACIOUS)
3856 END OBJ(audacious_length_seconds, INFO_AUDACIOUS)
3857 END OBJ(audacious_position, INFO_AUDACIOUS)
3858 END OBJ(audacious_position_seconds, INFO_AUDACIOUS)
3859 END OBJ(audacious_bitrate, INFO_AUDACIOUS)
3860 END OBJ(audacious_frequency, INFO_AUDACIOUS)
3861 END OBJ(audacious_channels, INFO_AUDACIOUS)
3862 END OBJ(audacious_filename, INFO_AUDACIOUS)
3863 END OBJ(audacious_playlist_length, INFO_AUDACIOUS)
3864 END OBJ(audacious_playlist_position, INFO_AUDACIOUS)
3865 END OBJ(audacious_bar, INFO_AUDACIOUS)
3866 scan_bar(arg, &obj->a, &obj->b);
3869 END OBJ(bmpx_title, INFO_BMPX)
3870 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3871 END OBJ(bmpx_artist, INFO_BMPX)
3872 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3873 END OBJ(bmpx_album, INFO_BMPX)
3874 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3875 END OBJ(bmpx_track, INFO_BMPX)
3876 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3877 END OBJ(bmpx_uri, INFO_BMPX)
3878 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3879 END OBJ(bmpx_bitrate, INFO_BMPX)
3880 memset(&(info.bmpx), 0, sizeof(struct bmpx_s));
3886 char *userid = (char *) malloc(20 * sizeof(char));
3887 char *apikey = (char *) malloc(64 * sizeof(char));
3888 char *charid = (char *) malloc(20 * sizeof(char));
3890 argc = sscanf(arg, "%20s %64s %20s", userid, apikey, charid);
3891 obj->data.eve.charid = charid;
3892 obj->data.eve.userid = userid;
3893 obj->data.eve.apikey = apikey;
3897 CRIT_ERR("eve needs arguments: <userid> <apikey> <characterid>");
3903 int argc, delay, act_par;
3904 char *uri = (char *) malloc(128 * sizeof(char));
3905 char *action = (char *) malloc(64 * sizeof(char));
3907 argc = sscanf(arg, "%127s %d %63s %d", uri, &delay, action,
3909 obj->data.rss.uri = uri;
3910 obj->data.rss.delay = delay;
3911 obj->data.rss.action = action;
3912 obj->data.rss.act_par = act_par;
3916 CRIT_ERR("rss needs arguments: <uri> <delay in minutes> <action> "
3922 if (!arg || scan_hddtemp(arg, &obj->data.hddtemp.dev,
3923 &obj->data.hddtemp.addr, &obj->data.hddtemp.port, &obj->data.hddtemp.temp)) {
3924 ERR("hddtemp needs arguments");
3925 obj->type = OBJ_text;
3926 obj->data.s = strndup("${hddtemp}", text_buffer_size);
3927 obj->data.hddtemp.update_time = 0;
3931 #ifdef TCP_PORT_MONITOR
3932 END OBJ(tcp_portmon, INFO_TCP_PORT_MONITOR)
3933 int argc, port_begin, port_end, item, connection_index;
3936 memset(itembuf, 0, sizeof(itembuf));
3937 connection_index = 0;
3938 /* massive argument checking */
3940 CRIT_ERR("tcp_portmon: needs arguments");
3942 argc = sscanf(arg, "%d %d %31s %d", &port_begin, &port_end, itembuf,
3944 if ((argc != 3) && (argc != 4)) {
3945 CRIT_ERR("tcp_portmon: requires 3 or 4 arguments");
3947 if ((port_begin < 1) || (port_begin > 65535) || (port_end < 1)
3948 || (port_end > 65535)) {
3949 CRIT_ERR("tcp_portmon: port values must be from 1 to 65535");
3951 if (port_begin > port_end) {
3952 CRIT_ERR("tcp_portmon: starting port must be <= ending port");
3954 if (strncmp(itembuf, "count", 31) == EQUAL) {
3956 } else if (strncmp(itembuf, "rip", 31) == EQUAL) {
3958 } else if (strncmp(itembuf, "rhost", 31) == EQUAL) {
3960 } else if (strncmp(itembuf, "rport", 31) == EQUAL) {
3962 } else if (strncmp(itembuf, "rservice", 31) == EQUAL) {
3963 item = REMOTESERVICE;
3964 } else if (strncmp(itembuf, "lip", 31) == EQUAL) {
3966 } else if (strncmp(itembuf, "lhost", 31) == EQUAL) {
3968 } else if (strncmp(itembuf, "lport", 31) == EQUAL) {
3970 } else if (strncmp(itembuf, "lservice", 31) == EQUAL) {
3971 item = LOCALSERVICE;
3973 CRIT_ERR("tcp_portmon: invalid item specified");
3975 if ((argc == 3) && (item != COUNT)) {
3976 CRIT_ERR("tcp_portmon: 3 argument form valid only for \"count\" "
3979 if ((argc == 4) && (connection_index < 0)) {
3980 CRIT_ERR("tcp_portmon: connection index must be non-negative");
3982 /* ok, args looks good. save the text object data */
3983 obj->data.tcp_port_monitor.port_range_begin = (in_port_t) port_begin;
3984 obj->data.tcp_port_monitor.port_range_end = (in_port_t) port_end;
3985 obj->data.tcp_port_monitor.item = item;
3986 obj->data.tcp_port_monitor.connection_index = connection_index;
3988 /* if the port monitor collection hasn't been created,
3989 * we must create it */
3990 if (!info.p_tcp_port_monitor_collection) {
3991 info.p_tcp_port_monitor_collection =
3992 create_tcp_port_monitor_collection();
3993 if (!info.p_tcp_port_monitor_collection) {
3994 CRIT_ERR("tcp_portmon: unable to create port monitor "
3999 /* if a port monitor for this port does not exist,
4000 * create one and add it to the collection */
4001 if (find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
4002 port_begin, port_end) == NULL) {
4003 tcp_port_monitor_t *p_monitor = create_tcp_port_monitor(port_begin,
4004 port_end, &tcp_port_monitor_args);
4007 CRIT_ERR("tcp_portmon: unable to create port monitor");
4009 /* add the newly created monitor to the collection */
4010 if (insert_tcp_port_monitor_into_collection(
4011 info.p_tcp_port_monitor_collection, p_monitor) != 0) {
4012 CRIT_ERR("tcp_portmon: unable to add port monitor to "
4017 END OBJ(entropy_avail, INFO_ENTROPY)
4018 END OBJ(entropy_poolsize, INFO_ENTROPY)
4019 END OBJ(entropy_bar, INFO_ENTROPY)
4020 scan_bar(arg, &obj->a, &obj->b);
4024 if (arg && sscanf(arg, "%u %n", &obj->data.scroll.show, &n) > 0) {
4025 obj->data.scroll.text = strndup(arg + n, text_buffer_size);
4026 obj->data.scroll.start = 0;
4028 CRIT_ERR("scroll needs arguments: <length> <text>");
4033 CRIT_ERR("nvidia needs an argument\n");
4034 } else if (set_nvidia_type(&obj->data.nvidia, arg)) {
4035 CRIT_ERR("nvidia: invalid argument"
4036 " specified: '%s'\n", arg);
4042 ERR("unknown variable %s", s);
4043 obj->type = OBJ_text;
4044 snprintf(buf, 256, "${%s}", s);
4045 obj->data.s = strndup(buf, text_buffer_size);
4052 static struct text_object *create_plain_text(const char *s)
4054 struct text_object *obj;
4056 if (s == NULL || *s == '\0') {
4060 obj = new_text_object_internal();
4062 obj->type = OBJ_text;
4063 obj->data.s = strndup(s, text_buffer_size);
4067 static struct text_object_list *extract_variable_text_internal(const char *const_p, char allow_threaded)
4069 struct text_object_list *retval;
4070 struct text_object *obj;
4071 char *p, *s, *orig_p;
4074 p = strndup(const_p, max_user_text);
4077 retval = malloc(sizeof(struct text_object_list));
4078 memset(retval, 0, sizeof(struct text_object_list));
4079 retval->text_object_count = 0;
4081 line = global_text_lines;
4089 obj = create_plain_text(s);
4091 // allocate memory for the object
4092 retval->text_objects = realloc(retval->text_objects,
4093 sizeof(struct text_object) *
4094 (retval->text_object_count + 1));
4095 // assign the new object to the end of the list.
4096 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4097 sizeof(struct text_object));
4109 /* variable is either $foo or ${foo} */
4111 unsigned int brl = 1, brr = 0;
4115 while (*p && brl != brr) {
4130 while (*p && (isalnum((int) *p) || *p == '_')) {
4135 /* copy variable to buffer */
4136 len = (p - s > 255) ? 255 : (p - s);
4137 strncpy(buf, s, len);
4147 /* if variable wasn't found in environment, use some special */
4153 if (strchr(buf, ' ')) {
4154 arg = strchr(buf, ' ');
4157 while (isspace((int) *arg)) {
4165 /* lowercase variable name */
4168 *tmp_p = tolower(*tmp_p);
4172 // create new object
4173 obj = construct_text_object(buf, arg,
4174 retval->text_object_count, retval->text_objects, line, allow_threaded);
4176 // allocate memory for the object
4177 retval->text_objects = realloc(retval->text_objects,
4178 sizeof(struct text_object) *
4179 (retval->text_object_count + 1));
4180 // assign the new object to the end of the list.
4182 &retval->text_objects[retval->text_object_count++],
4183 obj, sizeof(struct text_object));
4189 obj = create_plain_text("$");
4191 // allocate memory for the object
4192 retval->text_objects = realloc(retval->text_objects,
4193 sizeof(struct text_object) *
4194 (retval->text_object_count + 1));
4195 // assign the new object to the end of the list.
4196 memcpy(&retval->text_objects[retval->text_object_count++],
4197 obj, sizeof(struct text_object));
4204 obj = create_plain_text(s);
4206 // allocate memory for the object
4207 retval->text_objects = realloc(retval->text_objects,
4208 sizeof(struct text_object) * (retval->text_object_count + 1));
4209 // assign the new object to the end of the list.
4210 memcpy(&retval->text_objects[retval->text_object_count++], obj,
4211 sizeof(struct text_object));
4216 ERR("one or more $endif's are missing");
4223 static void extract_variable_text(const char *p)
4225 free_text_objects(global_text_object_list, 1);
4226 free(global_text_object_list);
4240 global_text_object_list = extract_variable_text_internal(p, 1);
4243 struct text_object_list *parse_conky_vars(char *txt, char *p, struct information *cur)
4245 struct text_object_list *object_list =
4246 extract_variable_text_internal(txt, 0);
4248 generate_text_internal(p, max_user_text, object_list, cur);
4252 /* Allows reading from a FIFO (i.e., /dev/xconsole).
4253 * The file descriptor is set to non-blocking which makes this possible.
4255 * FIXME: Since lseek cannot seek a file descriptor long lines will break. */
4256 static void tail_pipe(struct text_object *obj, char *dst, size_t dst_size)
4258 #define TAIL_PIPE_BUFSIZE 4096
4262 int fd = obj->data.tail.fd;
4265 char buf[TAIL_PIPE_BUFSIZE];
4266 ssize_t len = read(fd, buf, sizeof(buf));
4270 if (errno != EAGAIN) {
4271 strcpy(obj->data.tail.buffer, "Logfile Read Error");
4272 snprintf(dst, dst_size, "Logfile Read Error");
4276 } else if (len == 0) {
4277 strcpy(obj->data.tail.buffer, "Logfile Empty");
4278 snprintf(dst, dst_size, "Logfile Empty");
4282 for (line_len = 0, i = 0; i < len; i++) {
4286 if (buf[i] == '\n') {
4289 if (obj->data.tail.readlines > 0) {
4294 for (n = 0; obj->data.tail.buffer[n]; n++) {
4295 if (obj->data.tail.buffer[n] == '\n') {
4300 if (++olines < obj->data.tail.wantedlines) {
4306 p = obj->data.tail.buffer + first_line;
4307 pos = n - first_line;
4308 memmove(obj->data.tail.buffer,
4309 obj->data.tail.buffer + first_line, strlen(p));
4310 obj->data.tail.buffer[pos] = 0;
4316 p = buf + last_line;
4318 memcpy(&(obj->data.tail.buffer[pos]), p, line_len);
4319 obj->data.tail.buffer[pos + line_len] = 0;
4322 obj->data.tail.readlines = lines;
4330 snprintf(dst, dst_size, "%s", obj->data.tail.buffer);
4333 static inline struct mail_s *ensure_mail_thread(struct text_object *obj,
4334 void *thread(void *), const char *text)
4336 if (obj->global_mode && info.mail) {
4337 // this means we use info
4338 if (!info.mail->p_timed_thread) {
4339 info.mail->p_timed_thread =
4340 timed_thread_create(thread,
4341 (void *) info.mail, info.mail->interval * 1000000);
4342 if (!info.mail->p_timed_thread) {
4343 ERR("Error creating %s timed thread", text);
4345 timed_thread_register(info.mail->p_timed_thread,
4346 &info.mail->p_timed_thread);
4347 if (timed_thread_run(info.mail->p_timed_thread)) {
4348 ERR("Error running %s timed thread", text);
4352 } else if (obj->data.mail) {
4353 // this means we use obj
4354 if (!obj->data.mail->p_timed_thread) {
4355 obj->data.mail->p_timed_thread =
4356 timed_thread_create(thread,
4357 (void *) obj->data.mail,
4358 obj->data.mail->interval * 1000000);
4359 if (!obj->data.mail->p_timed_thread) {
4360 ERR("Error creating %s timed thread", text);
4362 timed_thread_register(obj->data.mail->p_timed_thread,
4363 &obj->data.mail->p_timed_thread);
4364 if (timed_thread_run(obj->data.mail->p_timed_thread)) {
4365 ERR("Error running %s timed thread", text);
4368 return obj->data.mail;
4369 } else if (!obj->a) {
4370 // something is wrong, warn once then stop
4371 ERR("Theres a problem with your %s_unseen settings. "
4372 "Check that the global %s settings are defined "
4373 "properly (line %li).", global_text, global_text, obj->line);
4379 char *format_time(unsigned long timeval, const int width)
4382 unsigned long nt; // narrow time, for speed on 32-bit
4383 unsigned cc; // centiseconds
4384 unsigned nn; // multi-purpose whatever
4387 cc = nt % 100; // centiseconds past second
4388 nt /= 100; // total seconds
4389 nn = nt % 60; // seconds past the minute
4390 nt /= 60; // total minutes
4391 if (width >= snprintf(buf, sizeof buf, "%lu:%02u.%02u",
4393 return strndup(buf, text_buffer_size);
4395 if (width >= snprintf(buf, sizeof buf, "%lu:%02u", nt, nn)) {
4396 return strndup(buf, text_buffer_size);
4398 nn = nt % 60; // minutes past the hour
4399 nt /= 60; // total hours
4400 if (width >= snprintf(buf, sizeof buf, "%lu,%02u", nt, nn)) {
4401 return strndup(buf, text_buffer_size);
4403 nn = nt; // now also hours
4404 if (width >= snprintf(buf, sizeof buf, "%uh", nn)) {
4405 return strndup(buf, text_buffer_size);
4407 nn /= 24; // now days
4408 if (width >= snprintf(buf, sizeof buf, "%ud", nn)) {
4409 return strndup(buf, text_buffer_size);
4411 nn /= 7; // now weeks
4412 if (width >= snprintf(buf, sizeof buf, "%uw", nn)) {
4413 return strndup(buf, text_buffer_size);
4415 // well shoot, this outta' fit...
4416 return strndup("<inf>", text_buffer_size);
4419 //remove backspaced chars, example: "dog^H^H^Hcat" becomes "cat"
4420 //string has to end with \0 and it's length should fit in a int
4422 void remove_deleted_chars(char *string){
4424 while(string[i] != 0){
4425 if(string[i] == BACKSPACE){
4427 strcpy( &(string[i-1]), &(string[i+1]) );
4429 }else strcpy( &(string[i]), &(string[i+1]) ); //necessary for ^H's at the start of a string
4434 static inline void format_media_player_time(char *buf, const int size,
4437 int days, hours, minutes;
4439 days = seconds / (24 * 60 * 60);
4440 seconds %= (24 * 60 * 60);
4441 hours = seconds / (60 * 60);
4442 seconds %= (60 * 60);
4443 minutes = seconds / 60;
4447 snprintf(buf, size, "%i days %i:%02i:%02i", days,
4448 hours, minutes, seconds);
4449 } else if (hours > 0) {
4450 snprintf(buf, size, "%i:%02i:%02i", hours, minutes,
4453 snprintf(buf, size, "%i:%02i", minutes, seconds);
4457 static inline double get_barnum(char *buf)
4469 if (sscanf(buf, "%lf", &barnum) == 0) {
4470 ERR("reading execbar value failed (perhaps it's not the "
4471 "correct format?)");
4474 if (barnum > 100.0 || barnum < 0.0) {
4475 ERR("your execbar value is not between 0 and 100, "
4476 "therefore it will be ignored");
4482 static void generate_text_internal(char *p, int p_max_size,
4483 struct text_object_list *text_object_list,
4484 struct information *cur)
4489 char buff_in[p_max_size];
4491 iconv_converting = 0;
4495 for (i = 0; i < text_object_list->text_object_count; i++) {
4496 struct text_object *obj = &(text_object_list->text_objects[i]);
4498 if (p_max_size < 1) {
4502 #define OBJ(a) break; case OBJ_##a:
4504 switch (obj->type) {
4506 ERR("not implemented obj type %d", obj->type);
4509 /* does anyone have decimals in acpi temperature? */
4510 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4511 round_to_int(get_acpi_temperature(obj->data.i)));
4514 /* does anyone have decimals in acpi temperature? */
4515 spaced_print(p, p_max_size, "%d", 5, "acpitemp",
4516 round_to_int((get_acpi_temperature(obj->data.i) + 40) *
4519 #endif /* !__OpenBSD__ */
4522 obj->a = get_freq(p, p_max_size, "%.0f", 1,
4523 obj->data.cpu_index);
4529 obj->a = get_freq(p, p_max_size, "%'.2f", 1000,
4530 obj->data.cpu_index);
4532 /* OpenBSD has no such flag (SUSv2) */
4533 obj->a = get_freq(p, p_max_size, "%.2f", 1000,
4534 obj->data.cpu_index);
4538 #if defined(__linux__)
4541 obj->a = get_voltage(p, p_max_size, "%.0f", 1,
4542 obj->data.cpu_index);
4547 obj->a = get_voltage(p, p_max_size, "%'.3f", 1000,
4548 obj->data.cpu_index);
4553 OBJ(wireless_essid) {
4554 snprintf(p, p_max_size, "%s", obj->data.net->essid);
4556 OBJ(wireless_mode) {
4557 snprintf(p, p_max_size, "%s", obj->data.net->mode);
4559 OBJ(wireless_bitrate) {
4560 snprintf(p, p_max_size, "%s", obj->data.net->bitrate);
4563 snprintf(p, p_max_size, "%s", obj->data.net->ap);
4565 OBJ(wireless_link_qual) {
4566 spaced_print(p, p_max_size, "%d", 4, "wireless_link_qual",
4567 obj->data.net->link_qual);
4569 OBJ(wireless_link_qual_max) {
4570 spaced_print(p, p_max_size, "%d", 4,
4571 "wireless_link_qual_max", obj->data.net->link_qual_max);
4573 OBJ(wireless_link_qual_perc) {
4574 if (obj->data.net->link_qual_max > 0) {
4575 spaced_print(p, p_max_size, "%.0f", 5,
4576 "wireless_link_qual_perc",
4577 (double) obj->data.net->link_qual /
4578 obj->data.net->link_qual_max * 100);
4580 spaced_print(p, p_max_size, "unk", 5,
4581 "wireless_link_qual_perc");
4584 OBJ(wireless_link_bar) {
4585 new_bar(p, obj->a, obj->b, ((double) obj->data.net->link_qual /
4586 obj->data.net->link_qual_max) * 255.0);
4588 #endif /* HAVE_IWLIB */
4590 #endif /* __linux__ */
4593 get_freq_dynamic(p, p_max_size, "%.0f", 1);
4594 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4598 get_freq_dynamic(p, p_max_size, "%'.2f", 1000);
4600 get_freq_dynamic(p, p_max_size, "%.2f", 1000);
4602 spaced_print(p, p_max_size, "%s", 6, "freq_dyn", p);
4607 get_adt746x_cpu(p, p_max_size);
4610 get_adt746x_fan(p, p_max_size);
4613 get_acpi_fan(p, p_max_size);
4615 OBJ(acpiacadapter) {
4616 get_acpi_ac_adapter(p, p_max_size);
4619 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_STATUS);
4622 get_battery_stuff(p, p_max_size, obj->data.s, BATTERY_TIME);
4624 OBJ(battery_percent) {
4625 spaced_print(p, p_max_size, "%*d", 4, "battery_percent",
4626 pad_percents, get_battery_perct(obj->data.s));
4629 new_bar(p, obj->a, obj->b, get_battery_perct_bar(obj->data.s));
4631 #endif /* __OpenBSD__ */
4634 human_readable(cur->buffers * 1024, p, 255, "buffers");
4637 human_readable(cur->cached * 1024, p, 255, "buffers");
4640 if (obj->data.cpu_index > info.cpu_count) {
4641 printf("obj->data.cpu_index %i info.cpu_count %i",
4642 obj->data.cpu_index, info.cpu_count);
4643 CRIT_ERR("attempting to use more CPUs than you have!");
4645 spaced_print(p, p_max_size, "%*d", 4, "cpu", pad_percents,
4646 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100.0));
4649 new_bar(p, obj->a, obj->b,
4650 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 255.0));
4653 new_graph(p, obj->a, obj->b, obj->c, obj->d, (unsigned int)
4654 round_to_int(cur->cpu_usage[obj->data.cpu_index] * 100),
4655 100, 1, obj->showaslog);
4658 new_graph(p, obj->a, obj->b, obj->c, obj->d, cur->loadavg[0],
4659 obj->e, 1, obj->showaslog);
4662 new_fg(p, obj->data.l);
4694 OBJ(conky_version) {
4695 snprintf(p, p_max_size, "%s", VERSION);
4697 OBJ(conky_build_date) {
4698 snprintf(p, p_max_size, "%s", BUILD_DATE);
4700 OBJ(conky_build_arch) {
4701 snprintf(p, p_max_size, "%s", BUILD_ARCH);
4703 #if defined(__linux__)
4705 snprintf(p, p_max_size, "%s",
4706 get_disk_protect_queue(obj->data.s));
4709 snprintf(p, p_max_size, "%s", i8k.version);
4712 snprintf(p, p_max_size, "%s", i8k.bios);
4715 snprintf(p, p_max_size, "%s", i8k.serial);
4718 snprintf(p, p_max_size, "%s", i8k.cpu_temp);
4720 OBJ(i8k_cpu_tempf) {
4723 sscanf(i8k.cpu_temp, "%d", &cpu_temp);
4724 snprintf(p, p_max_size, "%.1f", cpu_temp * (9.0 / 5.0) + 32.0);
4726 OBJ(i8k_left_fan_status) {
4727 int left_fan_status;
4729 sscanf(i8k.left_fan_status, "%d", &left_fan_status);
4730 if (left_fan_status == 0) {
4731 snprintf(p, p_max_size, "off");
4733 if (left_fan_status == 1) {
4734 snprintf(p, p_max_size, "low");
4736 if (left_fan_status == 2) {
4737 snprintf(p, p_max_size, "high");
4740 OBJ(i8k_right_fan_status) {
4741 int right_fan_status;
4743 sscanf(i8k.right_fan_status, "%d", &right_fan_status);
4744 if (right_fan_status == 0) {
4745 snprintf(p, p_max_size, "off");
4747 if (right_fan_status == 1) {
4748 snprintf(p, p_max_size, "low");
4750 if (right_fan_status == 2) {
4751 snprintf(p, p_max_size, "high");
4754 OBJ(i8k_left_fan_rpm) {
4755 snprintf(p, p_max_size, "%s", i8k.left_fan_rpm);
4757 OBJ(i8k_right_fan_rpm) {
4758 snprintf(p, p_max_size, "%s", i8k.right_fan_rpm);
4760 OBJ(i8k_ac_status) {
4763 sscanf(i8k.ac_status, "%d", &ac_status);
4764 if (ac_status == -1) {
4765 snprintf(p, p_max_size, "disabled (read i8k docs)");
4767 if (ac_status == 0) {
4768 snprintf(p, p_max_size, "off");
4770 if (ac_status == 1) {
4771 snprintf(p, p_max_size, "on");
4774 OBJ(i8k_buttons_status) {
4775 snprintf(p, p_max_size, "%s", i8k.buttons_status);
4778 get_ibm_acpi_fan(p, p_max_size);
4781 get_ibm_acpi_temps();
4782 snprintf(p, p_max_size, "%d", ibm_acpi.temps[obj->data.sensor]);
4785 get_ibm_acpi_volume(p, p_max_size);
4787 OBJ(ibm_brightness) {
4788 get_ibm_acpi_brightness(p, p_max_size);
4791 if ((obj->data.ifblock.s)
4792 && (!interface_up(obj->data.ifblock.s))) {
4793 i = obj->data.ifblock.pos;
4800 if (!cur->gw_info.count) {
4801 i = obj->data.ifblock.pos;
4808 snprintf(p, p_max_size, "%s", cur->gw_info.iface);
4811 snprintf(p, p_max_size, "%s", cur->gw_info.ip);
4814 snprintf(p, p_max_size, "%d", get_laptop_mode());
4817 get_powerbook_batt_info(p, p_max_size, obj->data.i);
4819 #endif /* __linux__ */
4822 OBJ(obsd_sensors_temp) {
4823 obsd_sensors.device = sensor_device;
4824 update_obsd_sensors();
4825 snprintf(p, p_max_size, "%.1f",
4826 obsd_sensors.temp[obsd_sensors.device][obj->data.sensor]);
4828 OBJ(obsd_sensors_fan) {
4829 obsd_sensors.device = sensor_device;
4830 update_obsd_sensors();
4831 snprintf(p, p_max_size, "%d",
4832 obsd_sensors.fan[obsd_sensors.device][obj->data.sensor]);
4834 OBJ(obsd_sensors_volt) {
4835 obsd_sensors.device = sensor_device;
4836 update_obsd_sensors();
4837 snprintf(p, p_max_size, "%.2f",
4838 obsd_sensors.volt[obsd_sensors.device][obj->data.sensor]);
4841 get_obsd_vendor(p, p_max_size);
4844 get_obsd_product(p, p_max_size);
4846 #endif /* __OpenBSD__ */
4850 new_font(p, obj->data.s);
4853 /* TODO: move this correction from kB to kB/s elsewhere
4854 * (or get rid of it??) */
4856 if (obj->data.diskio) {
4858 (obj->data.diskio->current / update_interval) * 1024LL,
4859 p, p_max_size, "diskio");
4861 human_readable(info.diskio_value * 1024LL, p, p_max_size,
4866 if (obj->data.diskio) {
4867 human_readable((obj->data.diskio->current_write / update_interval) * 1024LL, p, p_max_size,
4870 human_readable(info.diskio_write_value * 1024LL, p, p_max_size,
4875 if (obj->data.diskio) {
4876 human_readable((obj->data.diskio->current_read / update_interval) * 1024LL, p, p_max_size,
4879 human_readable(info.diskio_read_value * 1024LL, p, p_max_size,
4884 if (obj->data.diskio) {
4885 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4886 obj->data.diskio->current, obj->e, 1, obj->showaslog);
4888 new_graph(p, obj->a, obj->b, obj->c, obj->d, info.diskio_value,
4889 obj->e, 1, obj->showaslog);
4892 OBJ(diskiograph_read) {
4893 if (obj->data.diskio) {
4894 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4895 obj->data.diskio->current_read, obj->e, 1, obj->showaslog);
4897 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4898 info.diskio_read_value, obj->e, 1, obj->showaslog);
4901 OBJ(diskiograph_write) {
4902 if (obj->data.diskio) {
4903 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4904 obj->data.diskio->current_write, obj->e, 1, obj->showaslog);
4906 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4907 info.diskio_write_value, obj->e, 1, obj->showaslog);
4911 spaced_print(p, p_max_size, "%d", 6, "downspeed",
4912 round_to_int(obj->data.net->recv_speed / 1024));
4915 spaced_print(p, p_max_size, "%.1f", 8, "downspeedf",
4916 obj->data.net->recv_speed / 1024.0);
4918 OBJ(downspeedgraph) {
4919 new_graph(p, obj->a, obj->b, obj->c, obj->d,
4920 obj->data.net->recv_speed / 1024.0, obj->e, 1, obj->showaslog);
4924 i = obj->data.ifblock.pos - 1;
4934 if ((obj->data.net->addr.sa_data[2] & 255) == 0
4935 && (obj->data.net->addr.sa_data[3] & 255) == 0
4936 && (obj->data.net->addr.sa_data[4] & 255) == 0
4937 && (obj->data.net->addr.sa_data[5] & 255) == 0) {
4938 snprintf(p, p_max_size, "No Address");
4940 snprintf(p, p_max_size, "%u.%u.%u.%u",
4941 obj->data.net->addr.sa_data[2] & 255,
4942 obj->data.net->addr.sa_data[3] & 255,
4943 obj->data.net->addr.sa_data[4] & 255,
4944 obj->data.net->addr.sa_data[5] & 255);
4947 #if defined(__linux__)
4949 if(NULL != obj->data.net->addrs && strlen(obj->data.net->addrs) > 2)
4951 obj->data.net->addrs[strlen(obj->data.net->addrs) - 2] = 0; /* remove ", " from end of string */
4952 strcpy(p, obj->data.net->addrs);
4955 strcpy(p, "0.0.0.0");
4957 #endif /* __linux__ */
4959 #if defined(IMLIB2) && defined(X11)
4964 Imlib_Image image, buffer;
4966 image = imlib_load_image(obj->data.s);
4967 imlib_context_set_image(image);
4971 w = imlib_image_get_width();
4972 h = imlib_image_get_height();
4973 buffer = imlib_create_image(w, h);
4974 imlib_context_set_display(display);
4975 imlib_context_set_drawable(window.drawable);
4976 imlib_context_set_colormap(DefaultColormap(display,
4978 imlib_context_set_visual(DefaultVisual(display,
4980 imlib_context_set_image(buffer);
4981 imlib_blend_image_onto_image(image, 0, 0, 0, w, h,
4982 text_start_x, text_start_y, w, h);
4983 imlib_render_image_on_drawable(text_start_x,
4986 imlib_context_set_image(image);
4994 read_exec(obj->data.s, p, p_max_size);
4995 remove_deleted_chars(p);
4998 struct information *tmp_info;
4999 struct text_object_list *text_objects;
5001 read_exec(obj->data.s, p, p_max_size);
5003 tmp_info = malloc(sizeof(struct information));
5004 memcpy(tmp_info, cur, sizeof(struct information));
5005 text_objects = parse_conky_vars(p, p, tmp_info);
5007 free_text_objects(text_objects, 0);
5014 read_exec(obj->data.s, p, p_max_size);
5015 barnum = get_barnum(p);
5017 if (barnum >= 0.0) {
5018 new_bar(p, 0, 4, round_to_int(barnum * 255.0));
5022 char showaslog = FALSE;
5025 if(strncasecmp(obj->data.s, LOGGRAPH" ", strlen(LOGGRAPH" ")) == EQUAL) {
5027 read_exec(obj->data.s + strlen(LOGGRAPH" ") * sizeof(char), p, p_max_size);
5028 } else if(strncasecmp(obj->data.s, NORMGRAPH" ", strlen(NORMGRAPH" ")) == EQUAL) {
5029 read_exec(obj->data.s + strlen(NORMGRAPH" ") * sizeof(char), p, p_max_size);
5031 read_exec(obj->data.s, p, p_max_size);
5033 barnum = get_barnum(p);
5035 if (barnum >= 0.0) {
5036 new_graph(p, 0, 25, obj->c, obj->d, round_to_int(barnum),
5041 if (current_update_time - obj->data.execi.last_update
5042 >= obj->data.execi.interval) {
5045 read_exec(obj->data.execi.cmd, p, p_max_size);
5046 barnum = get_barnum(p);
5048 if (barnum >= 0.0) {
5049 obj->f = 255 * barnum / 100.0;
5051 obj->data.execi.last_update = current_update_time;
5053 new_bar(p, 0, 4, round_to_int(obj->f));
5056 if (current_update_time - obj->data.execi.last_update
5057 >= obj->data.execi.interval) {
5060 read_exec(obj->data.execi.cmd, p, p_max_size);
5061 barnum = get_barnum(p);
5063 if (barnum >= 0.0) {
5066 obj->data.execi.last_update = current_update_time;
5068 new_graph(p, 0, 25, obj->c, obj->d, (int) (obj->f), 100, 1, FALSE);
5071 if (current_update_time - obj->data.execi.last_update
5072 >= obj->data.execi.interval
5073 && obj->data.execi.interval != 0) {
5074 read_exec(obj->data.execi.cmd, obj->data.execi.buffer,
5076 obj->data.execi.last_update = current_update_time;
5078 snprintf(p, p_max_size, "%s", obj->data.execi.buffer);
5081 struct text_object_list *text_objects = 0;
5082 struct information *tmp_info =
5083 malloc(sizeof(struct information));
5084 memcpy(tmp_info, cur, sizeof(struct information));
5086 if (current_update_time - obj->data.execi.last_update
5087 < obj->data.execi.interval
5088 || obj->data.execi.interval == 0) {
5089 text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info);
5091 char *output = obj->data.execi.buffer;
5092 FILE *fp = popen(obj->data.execi.cmd, "r");
5093 int length = fread(output, 1, text_buffer_size, fp);
5097 output[length] = '\0';
5098 if (length > 0 && output[length - 1] == '\n') {
5099 output[length - 1] = '\0';
5102 text_objects = parse_conky_vars(obj->data.execi.buffer, p, tmp_info);
5103 obj->data.execi.last_update = current_update_time;
5105 free_text_objects(text_objects, 0);
5110 if (!obj->data.texeci.p_timed_thread) {
5111 obj->data.texeci.p_timed_thread =
5112 timed_thread_create(&threaded_exec,
5113 (void *) obj, obj->data.texeci.interval * 1000000);
5114 if (!obj->data.texeci.p_timed_thread) {
5115 ERR("Error creating texeci timed thread");
5117 timed_thread_register(obj->data.texeci.p_timed_thread,
5118 &obj->data.texeci.p_timed_thread);
5119 if (timed_thread_run(obj->data.texeci.p_timed_thread)) {
5120 ERR("Error running texeci timed thread");
5123 timed_thread_lock(obj->data.texeci.p_timed_thread);
5124 snprintf(p, p_max_size, "%s", obj->data.texeci.buffer);
5125 timed_thread_unlock(obj->data.texeci.p_timed_thread);
5127 #endif /* HAVE_POPEN */
5129 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
5131 if (mail && mail->p_timed_thread) {
5132 timed_thread_lock(mail->p_timed_thread);
5133 snprintf(p, p_max_size, "%lu", mail->unseen);
5134 timed_thread_unlock(mail->p_timed_thread);
5137 OBJ(imap_messages) {
5138 struct mail_s *mail = ensure_mail_thread(obj, imap_thread, "imap");
5140 if (mail && mail->p_timed_thread) {
5141 timed_thread_lock(mail->p_timed_thread);
5142 snprintf(p, p_max_size, "%lu", mail->messages);
5143 timed_thread_unlock(mail->p_timed_thread);
5147 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
5149 if (mail && mail->p_timed_thread) {
5150 timed_thread_lock(mail->p_timed_thread);
5151 snprintf(p, p_max_size, "%lu", mail->unseen);
5152 timed_thread_unlock(mail->p_timed_thread);
5156 struct mail_s *mail = ensure_mail_thread(obj, pop3_thread, "pop3");
5158 if (mail && mail->p_timed_thread) {
5159 timed_thread_lock(mail->p_timed_thread);
5160 snprintf(p, p_max_size, "%.1f",
5161 mail->used / 1024.0 / 1024.0);
5162 timed_thread_unlock(mail->p_timed_thread);
5166 if (obj->data.fs != NULL) {
5167 if (obj->data.fs->size == 0) {
5168 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5170 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5171 (int) (255 - obj->data.fsbar.fs->avail * 255 /
5172 obj->data.fs->size));
5177 if (obj->data.fs != NULL) {
5178 human_readable(obj->data.fs->avail, p, 255, "fs_free");
5182 if (obj->data.fs != NULL) {
5183 if (obj->data.fs->size) {
5184 spaced_print(p, p_max_size, "%*d", 4, "fs_free_perc",
5185 pad_percents, (int) ((obj->data.fs->avail * 100) /
5186 obj->data.fs->size));
5188 snprintf(p, p_max_size, "0");
5193 if (obj->data.fs != NULL) {
5194 human_readable(obj->data.fs->size, p, 255, "fs_size");
5198 if (obj->data.fs != NULL)
5199 snprintf(p, p_max_size, "%s", obj->data.fs->type);
5202 if (obj->data.fs != NULL) {
5203 human_readable(obj->data.fs->size - (obj->data.fs->free
5204 ? obj->data.fs->free : obj->data.fs->avail), p, 255,
5209 if (obj->data.fs != NULL) {
5210 if (obj->data.fs->size == 0) {
5211 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h, 255);
5213 new_bar(p, obj->data.fsbar.w, obj->data.fsbar.h,
5214 (int) (obj->data.fsbar.fs->avail * 255 /
5215 obj->data.fs->size));
5220 if (obj->data.fs != NULL) {
5221 if (obj->data.fs->size) {
5222 spaced_print(p, 4, "%*d", 4, "fs_used_perc",
5223 pad_percents, 100 - ((int) ((obj->data.fs->avail * 100) /
5224 obj->data.fs->size)));
5226 snprintf(p, p_max_size, "0");
5231 float *v = info.loadavg;
5233 if (obj->data.loadavg[2]) {
5234 snprintf(p, p_max_size, "%.2f %.2f %.2f",
5235 v[obj->data.loadavg[0] - 1],
5236 v[obj->data.loadavg[1] - 1],
5237 v[obj->data.loadavg[2] - 1]);
5238 } else if (obj->data.loadavg[1]) {
5239 snprintf(p, p_max_size, "%.2f %.2f",
5240 v[obj->data.loadavg[0] - 1],
5241 v[obj->data.loadavg[1] - 1]);
5242 } else if (obj->data.loadavg[0]) {
5243 snprintf(p, p_max_size, "%.2f",
5244 v[obj->data.loadavg[0] - 1]);
5248 new_goto(p, obj->data.i);
5251 new_tab(p, obj->data.pair.a, obj->data.pair.b);
5254 new_hr(p, obj->data.i);
5257 if (cur->nameserver_info.nscount > obj->data.i)
5258 snprintf(p, p_max_size, "%s",
5259 cur->nameserver_info.ns_list[obj->data.i]);
5263 char *skill = eve(obj->data.eve.userid, obj->data.eve.apikey, obj->data.eve.charid);
5264 snprintf(p, p_max_size, "%s", skill);
5269 PRSS *data = get_rss_info(obj->data.rss.uri,
5270 obj->data.rss.delay);
5274 snprintf(p, p_max_size, "prss: Error reading RSS data\n");
5276 if (strcmp(obj->data.rss.action, "feed_title") == EQUAL) {
5278 // remove trailing new line if one exists
5279 if (str[strlen(str) - 1] == '\n') {
5280 str[strlen(str) - 1] = 0;
5282 snprintf(p, p_max_size, "%s", str);
5283 } else if (strcmp(obj->data.rss.action, "item_title") == EQUAL) {
5284 if (obj->data.rss.act_par < data->item_count) {
5285 str = data->items[obj->data.rss.act_par].title;
5286 // remove trailing new line if one exists
5287 if (str[strlen(str) - 1] == '\n') {
5288 str[strlen(str) - 1] = 0;
5290 snprintf(p, p_max_size, "%s", str);
5292 } else if (strcmp(obj->data.rss.action, "item_desc") == EQUAL) {
5293 if (obj->data.rss.act_par < data->item_count) {
5295 data->items[obj->data.rss.act_par].description;
5296 // remove trailing new line if one exists
5297 if (str[strlen(str) - 1] == '\n') {
5298 str[strlen(str) - 1] = 0;
5300 snprintf(p, p_max_size, "%s", str);
5302 } else if (strcmp(obj->data.rss.action, "item_titles") == EQUAL) {
5303 if (data->item_count > 0) {
5309 if (obj->data.rss.act_par > data->item_count) {
5310 show = data->item_count;
5312 show = obj->data.rss.act_par;
5314 for (itmp = 0; itmp < show; itmp++) {
5315 PRSS_Item *item = &data->items[itmp];
5319 // don't add new line before first item
5321 strncat(p, "\n", p_max_size);
5323 /* remove trailing new line if one exists,
5324 * we have our own */
5325 if (str[strlen(str) - 1] == '\n') {
5326 str[strlen(str) - 1] = 0;
5328 strncat(p, str, p_max_size);
5338 if (obj->data.hddtemp.update_time < current_update_time - 30) {
5339 char *str = get_hddtemp_info(obj->data.hddtemp.dev,
5340 obj->data.hddtemp.addr, obj->data.hddtemp.port, &obj->data.hddtemp.unit);
5342 strncpy(obj->data.hddtemp.temp, str, text_buffer_size);
5344 obj->data.hddtemp.temp[0] = 0;
5346 obj->data.hddtemp.update_time = current_update_time;
5348 if (!obj->data.hddtemp.temp) {
5349 snprintf(p, p_max_size, "N/A");
5350 } else if (obj->data.hddtemp.unit == '*') {
5351 snprintf(p, p_max_size, "%s", obj->data.hddtemp.temp);
5353 snprintf(p, p_max_size, "%s%c", obj->data.hddtemp.temp, obj->data.hddtemp.unit);
5358 new_offset(p, obj->data.i);
5361 new_voffset(p, obj->data.i);
5367 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5368 obj->data.sysfs.devtype, obj->data.sysfs.type);
5370 if (r >= 100.0 || r == 0) {
5371 snprintf(p, p_max_size, "%d", (int) r);
5373 snprintf(p, p_max_size, "%.1f", r);
5379 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5380 obj->data.sysfs.devtype, obj->data.sysfs.type);
5382 if (r >= 100.0 || r == 0) {
5383 snprintf(p, p_max_size, "%d", (int) r);
5385 snprintf(p, p_max_size, "%.1f", r);
5391 r = get_sysfs_info(&obj->data.sysfs.fd, obj->data.sysfs.arg,
5392 obj->data.sysfs.devtype, obj->data.sysfs.type);
5394 if (r >= 100.0 || r == 0) {
5395 snprintf(p, p_max_size, "%d", (int) r);
5397 snprintf(p, p_max_size, "%.1f", r);
5400 #endif /* !__OpenBSD__ */
5402 new_alignr(p, obj->data.i);
5405 new_alignc(p, obj->data.i);
5408 struct text_object_list *text_objects;
5409 struct information *tmp_info =
5410 malloc(sizeof(struct information));
5411 memcpy(tmp_info, cur, sizeof(struct information));
5412 text_objects = parse_conky_vars(obj->data.ifblock.s, p, tmp_info);
5414 if (strlen(p) != 0) {
5415 i = obj->data.ifblock.pos;
5421 free_text_objects(text_objects, 0);
5428 if ((obj->data.ifblock.s)
5429 && (stat(obj->data.ifblock.s, &tmp) == -1)) {
5430 i = obj->data.ifblock.pos;
5433 if (obj->data.ifblock.str) {
5434 if (!check_contains(obj->data.ifblock.s,
5435 obj->data.ifblock.str)) {
5436 i = obj->data.ifblock.pos;
5447 if ((obj->data.ifblock.s)
5448 && (!check_mount(obj->data.ifblock.s))) {
5449 i = obj->data.ifblock.pos;
5456 if ((obj->data.ifblock.s) && system(obj->data.ifblock.s)) {
5457 i = obj->data.ifblock.pos;
5463 #if defined(__linux__)
5465 snprintf(p, p_max_size, "%s", get_ioscheduler(obj->data.s));
5469 snprintf(p, p_max_size, "%s", cur->uname_s.release);
5472 snprintf(p, p_max_size, "%s", cur->uname_s.machine);
5477 human_readable(cur->mem * 1024, p, 255, "mem");
5480 human_readable(cur->memeasyfree * 1024, p, 255, "memeasyfree");
5483 human_readable(cur->memfree * 1024, p, 255, "memfree");
5486 human_readable(cur->memmax * 1024, p, 255, "memmax");
5490 spaced_print(p, p_max_size, "%*llu", 4, "memperc",
5491 pad_percents, cur->mem * 100 / cur->memmax);
5495 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5496 cur->memmax ? (cur->mem * 255) / (cur->memmax) : 0);
5499 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5500 cur->memmax ? (cur->mem * 100.0) / (cur->memmax) : 0.0,
5501 100, 1, obj->showaslog);
5506 snprintf(p, p_max_size, "%d", mixer_get_avg(obj->data.l));
5509 snprintf(p, p_max_size, "%d", mixer_get_left(obj->data.l));
5512 snprintf(p, p_max_size, "%d", mixer_get_right(obj->data.l));
5515 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5516 mixer_get_avg(obj->data.mixerbar.l) * 255 / 100);
5519 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5520 mixer_get_left(obj->data.mixerbar.l) * 255 / 100);
5523 new_bar(p, obj->data.mixerbar.w, obj->data.mixerbar.h,
5524 mixer_get_right(obj->data.mixerbar.l) * 255 / 100);
5528 snprintf(p, p_max_size, "%d", cur->x11.monitor.current);
5530 OBJ(monitor_number) {
5531 snprintf(p, p_max_size, "%d", cur->x11.monitor.number);
5537 update_mail_count(&obj->data.local_mail);
5538 snprintf(p, p_max_size, "%d", obj->data.local_mail.mail_count);
5541 mbox_scan(obj->data.mboxscan.args, obj->data.mboxscan.output,
5543 snprintf(p, p_max_size, "%s", obj->data.mboxscan.output);
5546 update_mail_count(&obj->data.local_mail);
5547 snprintf(p, p_max_size, "%d",
5548 obj->data.local_mail.new_mail_count);
5551 snprintf(p, p_max_size, "%s", cur->uname_s.nodename);
5554 new_outline(p, obj->data.l);
5557 spaced_print(p, p_max_size, "%hu", 5, "processes", cur->procs);
5559 OBJ(running_processes) {
5560 spaced_print(p, p_max_size, "%hu", 3, "running_processes", cur->run_procs);
5563 snprintf(p, p_max_size, "%s", obj->data.s);
5566 new_bg(p, obj->data.l);
5569 new_stippled_hr(p, obj->data.pair.a, obj->data.pair.b);
5572 human_readable(cur->swap * 1024, p, 255, "swap");
5575 human_readable(cur->swapmax * 1024, p, 255, "swapmax");
5578 if (cur->swapmax == 0) {
5579 strncpy(p, "No swap", p_max_size);
5581 spaced_print(p, p_max_size, "%*llu", 4, "swapperc",
5582 pad_percents, cur->swap * 100 / cur->swapmax);
5586 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5587 cur->swapmax ? (cur->swap * 255) / (cur->swapmax) : 0);
5590 snprintf(p, p_max_size, "%s", cur->uname_s.sysname);
5593 time_t t = time(NULL);
5594 struct tm *tm = localtime(&t);
5596 setlocale(LC_TIME, "");
5597 strftime(p, p_max_size, obj->data.s, tm);
5600 time_t t = time(NULL);
5601 struct tm *tm = gmtime(&t);
5603 strftime(p, p_max_size, obj->data.s, tm);
5610 if (obj->data.tztime.tz) {
5611 oldTZ = getenv("TZ");
5612 setenv("TZ", obj->data.tztime.tz, 1);
5618 setlocale(LC_TIME, "");
5619 strftime(p, p_max_size, obj->data.tztime.fmt, tm);
5621 setenv("TZ", oldTZ, 1);
5626 // Needless to free oldTZ since getenv gives ptr to static data
5629 human_readable(obj->data.net->recv, p, 255, "totaldown");
5632 human_readable(obj->data.net->trans, p, 255, "totalup");
5635 snprintf(p, p_max_size, "%d", total_updates);
5638 spaced_print(p, p_max_size, "%d", 6, "upspeed",
5639 round_to_int(obj->data.net->trans_speed / 1024));
5642 spaced_print(p, p_max_size, "%.1f", 8, "upspeedf",
5643 obj->data.net->trans_speed / 1024.0);
5646 new_graph(p, obj->a, obj->b, obj->c, obj->d,
5647 obj->data.net->trans_speed / 1024.0, obj->e, 1, obj->showaslog);
5650 format_seconds_short(p, p_max_size, (int) cur->uptime);
5653 format_seconds(p, p_max_size, (int) cur->uptime);
5656 snprintf(p, p_max_size, "%s", cur->users.names);
5659 snprintf(p, p_max_size, "%s", cur->users.terms);
5662 snprintf(p, p_max_size, "%s", cur->users.times);
5665 snprintf(p, p_max_size, "%d", cur->users.number);
5667 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
5668 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
5672 msg = get_apm_adapter();
5673 snprintf(p, p_max_size, "%s", msg);
5676 OBJ(apm_battery_life) {
5679 msg = get_apm_battery_life();
5680 snprintf(p, p_max_size, "%s", msg);
5683 OBJ(apm_battery_time) {
5686 msg = get_apm_battery_time();
5687 snprintf(p, p_max_size, "%s", msg);
5690 #endif /* __FreeBSD__ __OpenBSD__ */
5694 snprintf(p, cur->mpd.max_title_len > 0
5695 ? cur->mpd.max_title_len : p_max_size, "%s",
5699 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5702 snprintf(p, p_max_size, "%s", cur->mpd.album);
5705 snprintf(p, p_max_size, "%s", cur->mpd.random);
5708 snprintf(p, p_max_size, "%s", cur->mpd.repeat);
5711 snprintf(p, p_max_size, "%s", cur->mpd.track);
5714 snprintf(p, p_max_size, "%s", cur->mpd.name);
5717 snprintf(p, p_max_size, "%s", cur->mpd.file);
5720 snprintf(p, p_max_size, "%i", cur->mpd.volume);
5723 snprintf(p, p_max_size, "%i", cur->mpd.bitrate);
5726 snprintf(p, p_max_size, "%s", cur->mpd.status);
5729 format_media_player_time(p, p_max_size, cur->mpd.elapsed);
5732 format_media_player_time(p, p_max_size, cur->mpd.length);
5735 spaced_print(p, p_max_size, "%*d", 4, "mpd_percent",
5736 pad_percents, (int) (cur->mpd.progress * 100));
5739 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5740 (int) (cur->mpd.progress * 255.0f));
5743 memset(p, 0, p_max_size);
5744 if (cur->mpd.artist && *cur->mpd.artist && cur->mpd.title
5745 && *cur->mpd.title) {
5746 snprintf(p, p_max_size, "%s - %s", cur->mpd.artist,
5748 } else if (cur->mpd.title && *cur->mpd.title) {
5749 snprintf(p, p_max_size, "%s", cur->mpd.title);
5750 } else if (cur->mpd.artist && *cur->mpd.artist) {
5751 snprintf(p, p_max_size, "%s", cur->mpd.artist);
5752 } else if (cur->mpd.file && *cur->mpd.file) {
5753 snprintf(p, p_max_size, "%s", cur->mpd.file);
5762 snprintf(p, p_max_size, "%s", cur->xmms2.artist);
5765 snprintf(p, p_max_size, "%s", cur->xmms2.album);
5768 snprintf(p, p_max_size, "%s", cur->xmms2.title);
5771 snprintf(p, p_max_size, "%s", cur->xmms2.genre);
5773 OBJ(xmms2_comment) {
5774 snprintf(p, p_max_size, "%s", cur->xmms2.comment);
5777 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5780 snprintf(p, p_max_size, "%s", cur->xmms2.status);
5783 snprintf(p, p_max_size, "%s", cur->xmms2.date);
5785 OBJ(xmms2_tracknr) {
5786 if (cur->xmms2.tracknr != -1) {
5787 snprintf(p, p_max_size, "%i", cur->xmms2.tracknr);
5790 OBJ(xmms2_bitrate) {
5791 snprintf(p, p_max_size, "%i", cur->xmms2.bitrate);
5794 snprintf(p, p_max_size, "%u", cur->xmms2.id);
5797 snprintf(p, p_max_size, "%2.1f", cur->xmms2.size);
5799 OBJ(xmms2_elapsed) {
5800 snprintf(p, p_max_size, "%02d:%02d", cur->xmms2.elapsed / 60000,
5801 (cur->xmms2.elapsed / 1000) % 60);
5803 OBJ(xmms2_duration) {
5804 snprintf(p, p_max_size, "%02d:%02d",
5805 cur->xmms2.duration / 60000,
5806 (cur->xmms2.duration / 1000) % 60);
5808 OBJ(xmms2_percent) {
5809 snprintf(p, p_max_size, "%2.0f", cur->xmms2.progress * 100);
5812 new_bar(p, obj->data.pair.a, obj->data.pair.b,
5813 (int) (cur->xmms2.progress * 255.0f));
5815 OBJ(xmms2_playlist) {
5816 snprintf(p, p_max_size, "%s", cur->xmms2.playlist);
5818 OBJ(xmms2_timesplayed) {
5819 snprintf(p, p_max_size, "%i", cur->xmms2.timesplayed);
5822 if (strlen(cur->xmms2.title) < 2
5823 && strlen(cur->xmms2.title) < 2) {
5824 snprintf(p, p_max_size, "%s", cur->xmms2.url);
5826 snprintf(p, p_max_size, "%s - %s", cur->xmms2.artist,
5832 OBJ(audacious_status) {
5833 snprintf(p, p_max_size, "%s",
5834 cur->audacious.items[AUDACIOUS_STATUS]);
5836 OBJ(audacious_title) {
5837 snprintf(p, cur->audacious.max_title_len > 0
5838 ? cur->audacious.max_title_len : p_max_size, "%s",
5839 cur->audacious.items[AUDACIOUS_TITLE]);
5841 OBJ(audacious_length) {
5842 snprintf(p, p_max_size, "%s",
5843 cur->audacious.items[AUDACIOUS_LENGTH]);
5845 OBJ(audacious_length_seconds) {
5846 snprintf(p, p_max_size, "%s",
5847 cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5849 OBJ(audacious_position) {
5850 snprintf(p, p_max_size, "%s",
5851 cur->audacious.items[AUDACIOUS_POSITION]);
5853 OBJ(audacious_position_seconds) {
5854 snprintf(p, p_max_size, "%s",
5855 cur->audacious.items[AUDACIOUS_POSITION_SECONDS]);
5857 OBJ(audacious_bitrate) {
5858 snprintf(p, p_max_size, "%s",
5859 cur->audacious.items[AUDACIOUS_BITRATE]);
5861 OBJ(audacious_frequency) {
5862 snprintf(p, p_max_size, "%s",
5863 cur->audacious.items[AUDACIOUS_FREQUENCY]);
5865 OBJ(audacious_channels) {
5866 snprintf(p, p_max_size, "%s",
5867 cur->audacious.items[AUDACIOUS_CHANNELS]);
5869 OBJ(audacious_filename) {
5870 snprintf(p, p_max_size, "%s",
5871 cur->audacious.items[AUDACIOUS_FILENAME]);
5873 OBJ(audacious_playlist_length) {
5874 snprintf(p, p_max_size, "%s",
5875 cur->audacious.items[AUDACIOUS_PLAYLIST_LENGTH]);
5877 OBJ(audacious_playlist_position) {
5878 snprintf(p, p_max_size, "%s",
5879 cur->audacious.items[AUDACIOUS_PLAYLIST_POSITION]);
5881 OBJ(audacious_bar) {
5885 atof(cur->audacious.items[AUDACIOUS_POSITION_SECONDS]) /
5886 atof(cur->audacious.items[AUDACIOUS_LENGTH_SECONDS]);
5887 new_bar(p, obj->a, obj->b, (int) (progress * 255.0f));
5893 snprintf(p, p_max_size, "%s", cur->bmpx.title);
5896 snprintf(p, p_max_size, "%s", cur->bmpx.artist);
5899 snprintf(p, p_max_size, "%s", cur->bmpx.album);
5902 snprintf(p, p_max_size, "%s", cur->bmpx.uri);
5905 snprintf(p, p_max_size, "%i", cur->bmpx.track);
5908 snprintf(p, p_max_size, "%i", cur->bmpx.bitrate);
5912 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5915 switch (obj->data.top.type) {
5917 snprintf(p, 16, "%-15s",
5918 cur->cpu[obj->data.top.num]->name);
5921 snprintf(p, 7, "%6.2f",
5922 cur->cpu[obj->data.top.num]->amount);
5925 snprintf(p, 6, "%5i",
5926 cur->cpu[obj->data.top.num]->pid);
5929 snprintf(p, 7, "%6.2f",
5930 cur->cpu[obj->data.top.num]->totalmem);
5933 timeval = format_time(
5934 cur->cpu[obj->data.top.num]->total_cpu_time, 9);
5935 snprintf(p, 10, "%9s", timeval);
5939 human_readable(cur->cpu[obj->data.top.num]->rss,
5943 human_readable(cur->cpu[obj->data.top.num]->vsize,
5947 ERR("Unhandled top data type: %d\n",
5948 obj->data.top.type);
5951 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5955 if (obj->data.top.num >= 0 && obj->data.top.num < 10) {
5958 switch (obj->data.top.type) {
5960 snprintf(p, 16, "%-15s",
5961 cur->memu[obj->data.top.num]->name);
5964 snprintf(p, 7, "%6.2f",
5965 cur->memu[obj->data.top.num]->amount);
5968 snprintf(p, 6, "%5i",
5969 cur->memu[obj->data.top.num]->pid);
5972 snprintf(p, 7, "%6.2f",
5973 cur->memu[obj->data.top.num]->totalmem);
5976 timeval = format_time(
5977 cur->memu[obj->data.top.num]->total_cpu_time,
5979 snprintf(p, 10, "%9s", timeval);
5983 human_readable(cur->cpu[obj->data.top.num]->rss,
5987 human_readable(cur->cpu[obj->data.top.num]->vsize,
5991 ERR("Unhandled top data type: %d\n",
5992 obj->data.top.type);
5995 ERR("Top index < 0 or > 10: %d\n", obj->data.top.num);
5999 if (current_update_time - obj->data.tail.last_update
6000 < obj->data.tail.interval) {
6001 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6007 obj->data.tail.last_update = current_update_time;
6009 if (obj->data.tail.fd != -1) {
6010 tail_pipe(obj, p, p_max_size);
6014 fp = fopen(obj->data.tail.logfile, "rt");
6017 /* Send one message, but do not consistently spam
6018 * on missing logfiles. */
6019 if (obj->data.tail.readlines != 0) {
6020 ERR("tail logfile failed to open");
6021 strcpy(obj->data.tail.buffer, "Logfile Missing");
6023 obj->data.tail.readlines = 0;
6024 snprintf(p, p_max_size, "Logfile Missing");
6026 obj->data.tail.readlines = 0;
6027 /* -1 instead of 0 to avoid counting a trailing
6029 fseek(fp, -1, SEEK_END);
6030 bsize = ftell(fp) + 1;
6031 for (iter = obj->data.tail.wantedlines; iter > 0;
6033 nl = rev_fcharfind(fp, '\n', iter);
6038 obj->data.tail.readlines = iter;
6039 if (obj->data.tail.readlines
6040 < obj->data.tail.wantedlines) {
6041 fseek(fp, 0, SEEK_SET);
6043 fseek(fp, nl + 1, SEEK_SET);
6046 /* Make sure bsize is at least 1 byte smaller than the
6047 * buffer max size. */
6048 if (bsize > (long) ((text_buffer_size * 20) - 1)) {
6049 fseek(fp, bsize - text_buffer_size * 20 - 1,
6051 bsize = text_buffer_size * 20 - 1;
6053 bsize = fread(obj->data.tail.buffer, 1, bsize, fp);
6056 /* Clean up trailing newline, make sure the
6057 * buffer is null terminated. */
6058 if (obj->data.tail.buffer[bsize - 1] == '\n') {
6059 obj->data.tail.buffer[bsize - 1] = '\0';
6061 obj->data.tail.buffer[bsize] = '\0';
6063 snprintf(p, p_max_size, "%s",
6064 obj->data.tail.buffer);
6066 strcpy(obj->data.tail.buffer, "Logfile Empty");
6067 snprintf(p, p_max_size, "Logfile Empty");
6070 } /* if cur_upd_time >= */
6071 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6075 if (current_update_time - obj->data.tail.last_update
6076 < obj->data.tail.interval) {
6077 snprintf(p, p_max_size, "%s", obj->data.tail.buffer);
6083 obj->data.tail.last_update = current_update_time;
6085 fp = fopen(obj->data.tail.logfile, "rt");
6087 /* Send one message, but do not consistently spam
6088 * on missing logfiles. */
6089 if (obj->data.tail.readlines != 0) {
6090 ERR("head logfile failed to open");
6091 strcpy(obj->data.tail.buffer, "Logfile Missing");
6093 obj->data.tail.readlines = 0;
6094 snprintf(p, p_max_size, "Logfile Missing");
6096 obj->data.tail.readlines = 0;
6097 for (iter = obj->data.tail.wantedlines; iter > 0;
6099 nl = fwd_fcharfind(fp, '\n', iter);
6104 obj->data.tail.readlines = iter;
6105 /* Make sure nl is at least 1 byte smaller than the
6106 * buffer max size. */
6107 if (nl > (long) ((text_buffer_size * 20) - 1)) {
6108 nl = text_buffer_size * 20 - 1;
6110 nl = fread(obj->data.tail.buffer, 1, nl, fp);
6113 /* Clean up trailing newline, make sure the buffer
6114 * is null terminated. */
6115 if (obj->data.tail.buffer[nl - 1] == '\n') {
6116 obj->data.tail.buffer[nl - 1] = '\0';
6118 obj->data.tail.buffer[nl] = '\0';
6120 snprintf(p, p_max_size, "%s",
6121 obj->data.tail.buffer);
6123 strcpy(obj->data.tail.buffer, "Logfile Empty");
6124 snprintf(p, p_max_size, "Logfile Empty");
6126 } /* if fp == null */
6127 } /* cur_upd_time >= */
6128 // parse_conky_vars(obj->data.tail.buffer, p, cur);
6132 FILE *fp = fopen(obj->data.s,"r");
6139 while(fgets(buf, BUFSZ, fp) != NULL){
6140 for(j = 0; buf[j] != 0; j++) {
6141 if(buf[j] == '\n') {
6146 sprintf(p, "%d", lines);
6149 sprintf(p, "File Unreadable");
6154 FILE *fp = fopen(obj->data.s,"r");
6159 char inword = FALSE;
6162 while(fgets(buf, BUFSZ, fp) != NULL){
6163 for(j = 0; buf[j] != 0; j++) {
6164 if(!isspace(buf[j])) {
6165 if(inword == FALSE) {
6174 sprintf(p, "%d", words);
6177 sprintf(p, "File Unreadable");
6180 #ifdef TCP_PORT_MONITOR
6182 /* grab a pointer to this port monitor */
6183 tcp_port_monitor_t *p_monitor =
6184 find_tcp_port_monitor(info.p_tcp_port_monitor_collection,
6185 obj->data.tcp_port_monitor.port_range_begin,
6186 obj->data.tcp_port_monitor.port_range_end);
6189 snprintf(p, p_max_size, "monitor not found");
6193 /* now grab the text of interest */
6194 if (peek_tcp_port_monitor(p_monitor,
6195 obj->data.tcp_port_monitor.item,
6196 obj->data.tcp_port_monitor.connection_index, p,
6198 snprintf(p, p_max_size, "monitor peek error");
6206 iconv_converting = 1;
6207 iconv_selected = obj->a;
6210 iconv_converting = 0;
6215 OBJ(entropy_avail) {
6216 snprintf(p, p_max_size, "%d", cur->entropy.entropy_avail);
6218 OBJ(entropy_poolsize) {
6219 snprintf(p, p_max_size, "%d", cur->entropy.poolsize);
6222 double entropy_perc;
6224 entropy_perc = (double) cur->entropy.entropy_avail /
6225 (double) cur->entropy.poolsize;
6226 new_bar(p, obj->a, obj->b, (int) (entropy_perc * 255.0f));
6232 s = smapi_get_val(obj->data.s);
6233 snprintf(p, p_max_size, "%s", s);
6237 OBJ(if_smapi_bat_installed) {
6239 if(obj->data.ifblock.s && sscanf(obj->data.ifblock.s, "%i", &idx) == 1) {
6240 if(!smapi_bat_installed(idx)) {
6241 i = obj->data.ifblock.pos;
6246 ERR("argument to if_smapi_bat_installed must be an integer");
6248 OBJ(smapi_bat_perc) {
6250 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6251 val = smapi_bat_installed(idx) ?
6252 smapi_get_bat_int(idx, "remaining_percent") : 0;
6253 spaced_print(p, p_max_size, "%*d", 4, "smapi_bat_perc", pad_percents, val);
6255 ERR("argument to smapi_bat_perc must be an integer");
6257 OBJ(smapi_bat_temp) {
6259 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6260 val = smapi_bat_installed(idx) ?
6261 smapi_get_bat_int(idx, "temperature") : 0;
6262 /* temperature is in milli degree celsius, round to degree celsius */
6263 snprintf(p, p_max_size, "%d", (int)((val / 1000) + 0.5));
6265 ERR("argument to smapi_bat_temp must be an integer");
6267 OBJ(smapi_bat_power) {
6269 if(obj->data.s && sscanf(obj->data.s, "%i", &idx) == 1) {
6270 val = smapi_bat_installed(idx) ?
6271 smapi_get_bat_int(idx, "power_now") : 0;
6272 /* power_now is in mW, set to W with one digit precision */
6273 snprintf(p, p_max_size, "%.1f", ((double)val / 1000));
6275 ERR("argument to smapi_bat_power must be an integer");
6277 OBJ(smapi_bat_bar) {
6278 if(obj->data.i >= 0 && smapi_bat_installed(obj->data.i))
6279 new_bar(p, obj->a, obj->b, (int)
6280 (255 * smapi_get_bat_int(obj->data.i, "remaining_percent") / 100));
6282 new_bar(p, obj->a, obj->b, 0);
6288 parse_conky_vars(obj->data.scroll.text, p, cur);
6289 #define LINESEPARATOR '|'
6290 //place all the lines behind each other with LINESEPARATOR between them
6291 for(j = 0; p[j] != 0; j++) {
6296 //scroll the output obj->data.scroll.start places by copying that many chars from
6297 //the front of the string to tmp, scrolling the rest to the front and placing tmp
6298 //at the back of the string
6299 tmp = calloc(obj->data.scroll.start + 1, sizeof(char));
6300 strncpy(tmp, p, obj->data.scroll.start); tmp[obj->data.scroll.start] = 0;
6301 for(j = obj->data.scroll.start; p[j] != 0; j++){
6302 p[j - obj->data.scroll.start] = p[j];
6304 strcpy(&p[j - obj->data.scroll.start], tmp);
6306 //only show the requested number of chars
6307 if(obj->data.scroll.show < j) {
6308 p[obj->data.scroll.show] = 0;
6310 //next time, scroll a place more or reset scrolling if we are at the end
6311 obj->data.scroll.start++;
6312 if(obj->data.scroll.start == j){
6313 obj->data.scroll.start = 0;
6318 int value = get_nvidia_value(obj->data.nvidia.type, display);
6320 snprintf(p, p_max_size, "N/A");
6321 else if (obj->data.nvidia.print_as_float &&
6322 value > 0 && value < 100)
6323 snprintf(p, p_max_size, "%.1f", (float)value);
6325 snprintf(p, p_max_size, "%d", value);
6333 unsigned int a = strlen(p);
6336 if (a > 0 && iconv_converting && iconv_selected > 0
6337 && (iconv_cd[iconv_selected - 1] != (iconv_t) (-1))) {
6339 size_t dummy1, dummy2;
6340 char *ptr = buff_in;
6343 dummy1 = dummy2 = a;
6345 strncpy(buff_in, p, p_max_size);
6347 iconv(*iconv_cd[iconv_selected - 1], NULL, NULL, NULL, NULL);
6348 while (dummy1 > 0) {
6349 bytes = iconv(*iconv_cd[iconv_selected - 1], &ptr, &dummy1,
6352 ERR("Iconv codeset conversion failed");
6357 /* It is nessecary when we are converting from multibyte to
6358 * singlebyte codepage */
6361 #endif /* HAVE_ICONV */
6368 double current_update_time, last_update_time;
6370 static void generate_text(void)
6372 struct information *cur = &info;
6379 current_update_time = get_time();
6382 /* fix diskio rates to b/s (use update_interval */
6383 info.diskio_read_value /= update_interval;
6384 info.diskio_write_value /= update_interval;
6385 info.diskio_value /= update_interval;
6387 /* add things to the buffer */
6393 generate_text_internal(p, max_user_text, global_text_object_list, cur);
6395 if (stuff_in_upper_case) {
6398 tmp_p = text_buffer;
6400 *tmp_p = toupper(*tmp_p);
6405 last_update_time = current_update_time;
6411 static void set_font(void)
6415 if (window.xftdraw != NULL) {
6416 XftDrawDestroy(window.xftdraw);
6418 window.xftdraw = XftDrawCreate(display, window.drawable,
6419 DefaultVisual(display, screen), DefaultColormap(display, screen));
6423 XSetFont(display, window.gc, fonts[selected_font].font->fid);
6429 static inline int get_string_width(const char *s)
6432 return *s ? calc_text_width(s, strlen(s)) : 0;
6438 static inline int get_string_width_special(char *s)
6450 p = strndup(s, text_buffer_size);
6454 if (*p == SPECIAL_CHAR) {
6455 /* shift everything over by 1 so that the special char
6456 * doesn't mess up the size calculation */
6457 for (i = 0; i < strlen(p); i++) {
6458 *(p + i) = *(p + i + 1);
6460 if (specials[special_index + idx].type == GRAPH
6461 || specials[special_index + idx].type == BAR) {
6462 width += specials[special_index + idx].width;
6469 if (strlen(final) > 1) {
6470 width += calc_text_width(final, strlen(final));
6475 return (s) ? strlen(s) : 0;
6480 static void text_size_updater(char *s);
6482 int last_font_height;
6483 static void update_text_area(void)
6487 /* update text size if it isn't fixed */
6492 text_width = minimum_width;
6495 last_font_height = font_height();
6496 for_each_line(text_buffer, text_size_updater);
6498 if (text_height < minimum_height) {
6499 text_height = minimum_height;
6501 if (text_width > maximum_width && maximum_width > 0) {
6502 text_width = maximum_width;
6506 /* get text position on workarea */
6507 switch (text_alignment) {
6514 x = workarea[2] - text_width - gap_x;
6519 x = workarea[2] / 2 - text_width / 2 - gap_x;
6526 y = workarea[3] - text_height - gap_y;
6530 x = workarea[2] - text_width - gap_x;
6531 y = workarea[3] - text_height - gap_y;
6535 x = workarea[2] / 2 - text_width / 2 - gap_x;
6536 y = workarea[3] - text_height - gap_y;
6541 y = workarea[3] / 2 - text_height / 2 - gap_y;
6545 x = workarea[2] - text_width - gap_x;
6546 y = workarea[3] / 2 - text_height / 2 - gap_y;
6550 case NONE: // Let the WM manage the window
6561 if (own_window && !fixed_pos) {
6564 text_start_x = border_margin + 1;
6565 text_start_y = border_margin + 1;
6566 window.x = x - border_margin - 1;
6567 window.y = y - border_margin - 1;
6571 /* If window size doesn't match to workarea's size,
6572 * then window probably includes panels (gnome).
6573 * Blah, doesn't work on KDE. */
6574 if (workarea[2] != window.width || workarea[3] != window.height) {
6586 static int cur_x, cur_y; /* current x and y for drawing */
6588 //draw_mode also without X11 because we only need to print to stdout with FG
6589 static int draw_mode; /* FG, BG or OUTLINE */
6591 static long current_color;
6594 static void text_size_updater(char *s)
6599 /* get string widths and skip specials */
6602 if (*p == SPECIAL_CHAR) {
6604 w += get_string_width(s);
6607 if (specials[special_index].type == BAR
6608 || specials[special_index].type == GRAPH) {
6609 w += specials[special_index].width;
6610 if (specials[special_index].height > last_font_height) {
6611 last_font_height = specials[special_index].height;
6612 last_font_height += font_ascent();
6614 } else if (specials[special_index].type == OFFSET) {
6615 if (specials[special_index].arg > 0) {
6616 w += specials[special_index].arg;
6618 } else if (specials[special_index].type == VOFFSET) {
6619 last_font_height += specials[special_index].arg;
6620 } else if (specials[special_index].type == GOTO) {
6621 if (specials[special_index].arg > cur_x) {
6622 w = (int) specials[special_index].arg;
6624 } else if (specials[special_index].type == TAB) {
6625 int start = specials[special_index].arg;
6626 int step = specials[special_index].width;
6628 if (!step || step < 0) {
6631 w += step - (cur_x - text_start_x - start) % step;
6632 } else if (specials[special_index].type == FONT) {
6633 selected_font = specials[special_index].font_added;
6634 if (font_height() > last_font_height) {
6635 last_font_height = font_height();
6644 w += get_string_width(s);
6645 if (w > text_width) {
6648 if (text_width > maximum_width && maximum_width) {
6649 text_width = maximum_width;
6652 text_height += last_font_height;
6653 last_font_height = font_height();
6657 static inline void set_foreground_color(long c)
6660 XSetForeground(display, window.gc, c);
6664 static void draw_string(const char *s)
6666 int i, i2, pos, width_of_s;
6674 width_of_s = get_string_width(s);
6675 if ((output_methods & TO_STDOUT) && draw_mode == FG) {
6677 fflush(stdout); /* output immediately, don't buffer */
6679 memset(tmpstring1, 0, text_buffer_size);
6680 memset(tmpstring2, 0, text_buffer_size);
6681 strncpy(tmpstring1, s, text_buffer_size - 1);
6686 max = ((text_width - width_of_s) / get_string_width(" "));
6688 /* This code looks for tabs in the text and coverts them to spaces.
6689 * The trick is getting the correct number of spaces, and not going
6690 * over the window's size without forcing the window larger. */
6691 for (i = 0; i < (int) text_buffer_size; i++) {
6692 if (tmpstring1[i] == '\t') {
6694 for (i2 = 0; i2 < (8 - (1 + pos) % 8) && added <= max; i2++) {
6695 /* guard against overrun */
6696 tmpstring2[MIN(pos + i2, (int)text_buffer_size - 1)] = ' ';
6701 /* guard against overrun */
6702 tmpstring2[MIN(pos, (int) text_buffer_size - 1)] = tmpstring1[i];
6707 if (text_width == maximum_width) {
6708 /* this means the text is probably pushing the limit,
6709 * so we'll chop it */
6710 while (cur_x + get_string_width(tmpstring2) - text_start_x
6711 > maximum_width && strlen(tmpstring2) > 0) {
6712 tmpstring2[strlen(tmpstring2) - 1] = '\0';
6723 c.pixel = current_color;
6724 XQueryColor(display, DefaultColormap(display, screen), &c);
6727 c2.color.red = c.red;
6728 c2.color.green = c.green;
6729 c2.color.blue = c.blue;
6730 c2.color.alpha = fonts[selected_font].font_alpha;
6732 XftDrawStringUtf8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6733 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6735 XftDrawString8(window.xftdraw, &c2, fonts[selected_font].xftfont,
6736 cur_x, cur_y, (const XftChar8 *) s, strlen(s));
6741 XDrawString(display, window.drawable, window.gc, cur_x, cur_y, s,
6744 cur_x += width_of_s;
6746 memcpy(tmpstring1, s, text_buffer_size);
6749 long redmask, greenmask, bluemask;
6751 void set_up_gradient(void)
6755 colour_depth = DisplayPlanes(display, screen);
6759 if (colour_depth != 24 && colour_depth != 16) {
6760 ERR("using non-standard colour depth, gradients may look like a "
6767 for (i = (colour_depth / 3) - 1; i >= 0; i--) {
6769 greenmask |= 1 << i;
6772 if (colour_depth % 3 == 1) {
6773 greenmask |= 1 << (colour_depth / 3);
6775 redmask = redmask << (2 * colour_depth / 3 + colour_depth % 3);
6776 greenmask = greenmask << (colour_depth / 3);
6779 /* this function returns the next colour between two colours for a gradient */
6780 unsigned long do_gradient(unsigned long first_colour,
6781 unsigned long last_colour)
6784 int red1, green1, blue1; // first colour
6785 int red2, green2, blue2; // second colour
6786 int red3 = 0, green3 = 0, blue3 = 0; // difference
6787 short redshift = (2 * colour_depth / 3 + colour_depth % 3);
6788 short greenshift = (colour_depth / 3);
6790 red1 = (first_colour & redmask) >> redshift;
6791 green1 = (first_colour & greenmask) >> greenshift;
6792 blue1 = first_colour & bluemask;
6793 red2 = (last_colour & redmask) >> redshift;
6794 green2 = (last_colour & greenmask) >> greenshift;
6795 blue2 = last_colour & bluemask;
6802 if (green1 > green2) {
6805 if (green1 < green2) {
6808 if (blue1 > blue2) {
6811 if (blue1 < blue2) {
6826 if (red1 > bluemask) {
6829 if (green1 > bluemask) {
6832 if (blue1 > bluemask) {
6835 tmp_color = (red1 << redshift) | (green1 << greenshift) | blue1;
6839 /* this function returns the max diff for a gradient */
6840 unsigned long gradient_max(unsigned long first_colour,
6841 unsigned long last_colour)
6843 int red1, green1, blue1; // first colour
6844 int red2, green2, blue2; // second colour
6845 int red3 = 0, green3 = 0, blue3 = 0; // difference
6846 long redshift, greenshift;
6849 if (colour_depth == 0) {
6852 redshift = (2 * colour_depth / 3 + colour_depth % 3);
6853 greenshift = (colour_depth / 3);
6855 red1 = (first_colour & redmask) >> redshift;
6856 green1 = (first_colour & greenmask) >> greenshift;
6857 blue1 = first_colour & bluemask;
6858 red2 = (last_colour & redmask) >> redshift;
6859 green2 = (last_colour & greenmask) >> greenshift;
6860 blue2 = last_colour & bluemask;
6861 red3 = abs(red1 - red2);
6862 green3 = abs(green1 - green2);
6863 blue3 = abs(blue1 - blue2);
6875 static void draw_line(char *s)
6883 cur_x = text_start_x;
6884 cur_y += font_ascent();
6885 font_h = font_height();
6887 /* find specials and draw stuff */
6890 if (*p == SPECIAL_CHAR) {
6893 /* draw string before special */
6900 switch (specials[special_index].type) {
6901 case HORIZONTAL_LINE:
6903 int h = specials[special_index].height;
6904 int mid = font_ascent() / 2;
6906 w = text_start_x + text_width - cur_x;
6908 XSetLineAttributes(display, window.gc, h, LineSolid,
6909 CapButt, JoinMiter);
6910 XDrawLine(display, window.drawable, window.gc, cur_x,
6911 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6917 int h = specials[special_index].height;
6918 int tmp_s = specials[special_index].arg;
6919 int mid = font_ascent() / 2;
6920 char ss[2] = { tmp_s, tmp_s };
6922 w = text_start_x + text_width - cur_x - 1;
6923 XSetLineAttributes(display, window.gc, h, LineOnOffDash,
6924 CapButt, JoinMiter);
6925 XSetDashes(display, window.gc, 0, ss, 2);
6926 XDrawLine(display, window.drawable, window.gc, cur_x,
6927 cur_y - mid / 2, cur_x + w, cur_y - mid / 2);
6933 int h, bar_usage, by;
6934 if (cur_x - text_start_x > maximum_width
6935 && maximum_width > 0) {
6938 h = specials[special_index].height;
6939 bar_usage = specials[special_index].arg;
6940 by = cur_y - (font_ascent() / 2) - 1;
6942 if (h < font_height()) {
6945 w = specials[special_index].width;
6947 w = text_start_x + text_width - cur_x - 1;
6953 XSetLineAttributes(display, window.gc, 1, LineSolid,
6954 CapButt, JoinMiter);
6956 XDrawRectangle(display, window.drawable, window.gc, cur_x,
6958 XFillRectangle(display, window.drawable, window.gc, cur_x,
6959 by, w * bar_usage / 255, h);
6960 if (specials[special_index].height > cur_y_add
6961 && specials[special_index].height > font_h) {
6962 cur_y_add = specials[special_index].height;
6969 int h, by, i, j = 0;
6970 int gradient_size = 0;
6971 float gradient_factor = 0;
6972 float gradient_update = 0;
6973 unsigned long last_colour = current_color;
6974 unsigned long tmpcolour = current_color;
6975 if (cur_x - text_start_x > maximum_width
6976 && maximum_width > 0) {
6979 h = specials[special_index].height;
6980 by = cur_y - (font_ascent() / 2) - 1;
6982 if (h < font_height()) {
6985 w = specials[special_index].width;
6987 w = text_start_x + text_width - cur_x - 1;
6992 if (draw_graph_borders) {
6993 XSetLineAttributes(display, window.gc, 1, LineSolid,
6994 CapButt, JoinMiter);
6995 XDrawRectangle(display, window.drawable, window.gc,
6998 XSetLineAttributes(display, window.gc, 1, LineSolid,
6999 CapButt, JoinMiter);
7001 if (specials[special_index].last_colour != 0
7002 || specials[special_index].first_colour != 0) {
7003 tmpcolour = specials[special_index].last_colour;
7005 gradient_max(specials[special_index].last_colour,
7006 specials[special_index].first_colour);
7007 gradient_factor = (float) gradient_size / (w - 2);
7009 for (i = w - 2; i > -1; i--) {
7010 if (specials[special_index].last_colour != 0
7011 || specials[special_index].first_colour != 0) {
7012 XSetForeground(display, window.gc, tmpcolour);
7013 gradient_update += gradient_factor;
7014 while (gradient_update > 0) {
7015 tmpcolour = do_gradient(tmpcolour,
7016 specials[special_index].first_colour);
7020 if ((w - i) / ((float) (w - 2) /
7021 (specials[special_index].graph_width)) > j
7022 && j < MAX_GRAPH_DEPTH - 3) {
7025 /* this is mugfugly, but it works */
7026 XDrawLine(display, window.drawable, window.gc,
7027 cur_x + i + 1, by + h, cur_x + i + 1,
7028 by + h - specials[special_index].graph[j] *
7029 (h - 1) / specials[special_index].graph_scale);
7031 if (specials[special_index].height > cur_y_add
7032 && specials[special_index].height > font_h) {
7033 cur_y_add = specials[special_index].height;
7035 /* if (draw_mode == BG) {
7036 set_foreground_color(default_bg_color);
7037 } else if (draw_mode == OUTLINE) {
7038 set_foreground_color(default_out_color);
7040 set_foreground_color(default_fg_color);
7042 if (show_graph_range) {
7045 unsigned short int seconds = update_interval * w;
7050 unsigned short int timeunits;
7052 timeunits = seconds / 86400; seconds %= 86400;
7053 if( timeunits > 0 ) {
7054 asprintf(&tmp_day_str, "%dd", timeunits);
7056 tmp_day_str = strdup("");
7058 timeunits = seconds / 3600; seconds %= 3600;
7059 if( timeunits > 0 ) {
7060 asprintf(&tmp_hour_str, "%dh", timeunits);
7062 tmp_hour_str = strdup("");
7064 timeunits = seconds / 60; seconds %= 60;
7066 asprintf(&tmp_min_str, "%dm", timeunits);
7068 tmp_min_str = strdup("");
7071 asprintf(&tmp_sec_str, "%ds", seconds);
7073 tmp_sec_str = strdup("");
7075 asprintf(&tmp_str, "%s%s%s%s", tmp_day_str, tmp_hour_str, tmp_min_str, tmp_sec_str);
7076 free(tmp_day_str); free(tmp_hour_str); free(tmp_min_str); free(tmp_sec_str);
7078 asprintf(&tmp_str, "Range not possible"); //should never happen, but better safe then sorry
7080 cur_x += (w / 2) - (font_ascent() * (strlen(tmp_str) / 2));
7081 cur_y += font_height() / 2;
7082 draw_string(tmp_str);
7088 if (show_graph_scale && (specials[special_index].show_scale == 1)) {
7091 cur_x += font_ascent() / 2;
7092 cur_y += font_height() / 2;
7094 calloc(log10(floor(specials[special_index].graph_scale)) + 4,
7096 sprintf(tmp_str, "%.1f", specials[special_index].graph_scale);
7097 draw_string(tmp_str);
7103 set_foreground_color(last_colour);
7109 int old = font_ascent();
7111 cur_y -= font_ascent();
7112 selected_font = specials[special_index].font_added;
7113 if (cur_y + font_ascent() < cur_y + old) {
7116 cur_y += font_ascent();
7122 if (draw_mode == FG) {
7123 set_foreground_color(specials[special_index].arg);
7128 if (draw_mode == BG) {
7129 set_foreground_color(specials[special_index].arg);
7134 if (draw_mode == OUTLINE) {
7135 set_foreground_color(specials[special_index].arg);
7140 w += specials[special_index].arg;
7144 cur_y += specials[special_index].arg;
7148 if (specials[special_index].arg >= 0) {
7149 cur_x = (int) specials[special_index].arg;
7155 int start = specials[special_index].arg;
7156 int step = specials[special_index].width;
7158 if (!step || step < 0) {
7161 w = step - (cur_x - text_start_x - start) % step;
7167 /* TODO: add back in "+ border_margin" to the end of
7169 int pos_x = text_start_x + text_width -
7170 get_string_width_special(s);
7172 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
7173 "get_string_width(p) %i gap_x %i "
7174 "specials[special_index].arg %i border_margin %i "
7175 "border_width %i\n", pos_x, text_start_x, text_width,
7176 cur_x, get_string_width_special(s), gap_x,
7177 specials[special_index].arg, border_margin,
7179 if (pos_x > specials[special_index].arg && pos_x > cur_x) {
7180 cur_x = pos_x - specials[special_index].arg;
7187 int pos_x = (text_width) / 2 - get_string_width_special(s) /
7188 2 - (cur_x - text_start_x);
7189 /* int pos_x = text_start_x + text_width / 2 -
7190 get_string_width_special(s) / 2; */
7192 /* printf("pos_x %i text_start_x %i text_width %i cur_x %i "
7193 "get_string_width(p) %i gap_x %i "
7194 "specials[special_index].arg %i\n", pos_x, text_start_x,
7195 text_width, cur_x, get_string_width(s), gap_x,
7196 specials[special_index].arg); */
7197 if (pos_x > specials[special_index].arg) {
7198 w = pos_x - specials[special_index].arg;
7215 if (cur_y_add > 0) {
7217 cur_y -= font_descent();
7222 cur_y += font_descent();
7226 static void draw_text(void)
7229 cur_y = text_start_y;
7232 if (draw_borders && border_width > 0) {
7233 unsigned int b = (border_width + 1) / 2;
7235 if (stippled_borders) {
7236 char ss[2] = { stippled_borders, stippled_borders };
7237 XSetLineAttributes(display, window.gc, border_width, LineOnOffDash,
7238 CapButt, JoinMiter);
7239 XSetDashes(display, window.gc, 0, ss, 2);
7241 XSetLineAttributes(display, window.gc, border_width, LineSolid,
7242 CapButt, JoinMiter);
7245 XDrawRectangle(display, window.drawable, window.gc,
7246 text_start_x - border_margin + b, text_start_y - border_margin + b,
7247 text_width + border_margin * 2 - 1 - b * 2,
7248 text_height + border_margin * 2 - 1 - b * 2);
7254 for_each_line(text_buffer, draw_line);
7257 static void draw_stuff(void)
7261 if (draw_shades && !draw_outline) {
7264 set_foreground_color(default_bg_color);
7275 for (i = -1; i < 2; i++) {
7276 for (j = -1; j < 2; j++) {
7277 if (i == 0 && j == 0) {
7282 set_foreground_color(default_out_color);
7283 draw_mode = OUTLINE;
7291 set_foreground_color(default_fg_color);
7300 swap.swap_window = window.window;
7301 swap.swap_action = XdbeBackground;
7302 XdbeSwapBuffers(display, &swap, 1);
7309 static void clear_text(int exposures)
7313 /* The swap action is XdbeBackground, which clears */
7318 /* there is some extra space for borders and outlines */
7319 XClearArea(display, window.window, text_start_x - border_margin - 1,
7320 text_start_y - border_margin - 1,
7321 text_width + border_margin * 2 + 2,
7322 text_height + border_margin * 2 + 2, exposures ? True : 0);
7327 static int need_to_update;
7329 /* update_text() generates new text and clears old text area */
7330 static void update_text(void)
7339 static void main_loop(void)
7341 #ifdef SIGNAL_BLOCKING
7342 sigset_t newmask, oldmask;
7345 Region region = XCreateRegion();
7349 XserverRegion region2, part;
7350 int event_base, error_base;
7352 if (!XDamageQueryExtension(display, &event_base, &error_base)) {
7353 ERR("Xdamage extension unavailable");
7355 damage = XDamageCreate(display, window.window, XDamageReportNonEmpty);
7356 region2 = XFixesCreateRegionFromWindow(display, window.window, 0);
7357 part = XFixesCreateRegionFromWindow(display, window.window, 0);
7358 #endif /* HAVE_XDAMAGE */
7361 #ifdef SIGNAL_BLOCKING
7362 sigemptyset(&newmask);
7363 sigaddset(&newmask, SIGINT);
7364 sigaddset(&newmask, SIGTERM);
7365 sigaddset(&newmask, SIGUSR1);
7369 while (total_run_times == 0 || info.looped < total_run_times) {
7372 #ifdef SIGNAL_BLOCKING
7373 /* block signals. we will inspect for pending signals later */
7374 if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
7375 CRIT_ERR("unable to sigprocmask()");
7382 /* wait for X event or timeout */
7384 if (!XPending(display)) {
7388 double t = update_interval - (get_time() - last_update_time);
7394 tv.tv_sec = (long) t;
7395 tv.tv_usec = (long) (t * 1000000) % 1000000;
7397 FD_SET(ConnectionNumber(display), &fdsr);
7399 s = select(ConnectionNumber(display) + 1, &fdsr, 0, 0, &tv);
7401 if (errno != EINTR) {
7402 ERR("can't select(): %s", strerror(errno));
7408 /* FIXME just sleep for the interval time if no X11 */
7409 usleep(update_interval * 1000000);
7417 if (need_to_update) {
7419 int wx = window.x, wy = window.y;
7427 /* resize window if it isn't right size */
7429 && (text_width + border_margin * 2 + 1 != window.width
7430 || text_height + border_margin * 2 + 1 != window.height)) {
7431 window.width = text_width + border_margin * 2 + 1;
7432 window.height = text_height + border_margin * 2 + 1;
7433 XResizeWindow(display, window.window, window.width,
7436 set_transparent_background(window.window);
7440 /* move window if it isn't in right position */
7441 if (!fixed_pos && (window.x != wx || window.y != wy)) {
7442 XMoveWindow(display, window.window, window.x, window.y);
7453 r.x = text_start_x - border_margin;
7454 r.y = text_start_y - border_margin;
7455 r.width = text_width + border_margin * 2;
7456 r.height = text_height + border_margin * 2;
7457 XUnionRectWithRegion(&r, region, region);
7462 /* handle X events */
7463 while (XPending(display)) {
7466 XNextEvent(display, &ev);
7474 r.width = ev.xexpose.width;
7475 r.height = ev.xexpose.height;
7476 XUnionRectWithRegion(&r, region, region);
7481 case ReparentNotify:
7482 /* set background to ParentRelative for all parents */
7484 set_transparent_background(window.window);
7488 case ConfigureNotify:
7490 /* if window size isn't what expected, set fixed size */
7491 if (ev.xconfigure.width != window.width
7492 || ev.xconfigure.height != window.height) {
7493 if (window.width != 0 && window.height != 0) {
7497 /* clear old stuff before screwing up
7502 XWindowAttributes attrs;
7504 if (XGetWindowAttributes(display,
7505 window.window, &attrs)) {
7506 window.width = attrs.width;
7507 window.height = attrs.height;
7511 text_width = window.width - border_margin * 2 - 1;
7512 text_height = window.height - border_margin * 2 - 1;
7513 if (text_width > maximum_width
7514 && maximum_width > 0) {
7515 text_width = maximum_width;
7519 /* if position isn't what expected, set fixed pos
7520 * total_updates avoids setting fixed_pos when window
7521 * is set to weird locations when started */
7522 /* // this is broken
7523 if (total_updates >= 2 && !fixed_pos
7524 && (window.x != ev.xconfigure.x
7525 || window.y != ev.xconfigure.y)
7526 && (ev.xconfigure.x != 0
7527 || ev.xconfigure.y != 0)) {
7536 /* if an ordinary window with decorations */
7537 if ((window.type == TYPE_NORMAL)
7538 && (!TEST_HINT(window.hints,
7539 HINT_UNDECORATED))) {
7540 /* allow conky to hold input focus. */
7543 /* forward the click to the desktop window */
7544 XUngrabPointer(display, ev.xbutton.time);
7545 ev.xbutton.window = window.desktop;
7546 XSendEvent(display, ev.xbutton.window, False,
7547 ButtonPressMask, &ev);
7548 XSetInputFocus(display, ev.xbutton.window,
7549 RevertToParent, ev.xbutton.time);
7556 /* if an ordinary window with decorations */
7557 if ((window.type == TYPE_NORMAL)
7558 && (!TEST_HINT(window.hints,
7559 HINT_UNDECORATED))) {
7560 /* allow conky to hold input focus. */
7563 /* forward the release to the desktop window */
7564 ev.xbutton.window = window.desktop;
7565 XSendEvent(display, ev.xbutton.window, False,
7566 ButtonReleaseMask, &ev);
7575 if (ev.type == event_base + XDamageNotify) {
7576 XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &ev;
7578 XFixesSetRegion(display, part, &dev->area, 1);
7579 XFixesUnionRegion(display, region2, region2, part);
7581 #endif /* HAVE_XDAMAGE */
7587 XDamageSubtract(display, damage, region2, None);
7588 XFixesSetRegion(display, region2, 0, 0);
7589 #endif /* HAVE_XDAMAGE */
7591 /* XDBE doesn't seem to provide a way to clear the back buffer without
7592 * interfering with the front buffer, other than passing XdbeBackground
7593 * to XdbeSwapBuffers. That means that if we're using XDBE, we need to
7594 * redraw the text even if it wasn't part of the exposed area. OTOH,
7595 * if we're not going to call draw_stuff at all, then no swap happens
7596 * and we can safely do nothing. */
7598 if (!XEmptyRegion(region)) {
7603 r.x = text_start_x - border_margin;
7604 r.y = text_start_y - border_margin;
7605 r.width = text_width + border_margin * 2;
7606 r.height = text_height + border_margin * 2;
7607 XUnionRectWithRegion(&r, region, region);
7610 XSetRegion(display, window.gc, region);
7613 XftDrawSetClip(window.xftdraw, region);
7619 XDestroyRegion(region);
7620 region = XCreateRegion();
7624 #ifdef SIGNAL_BLOCKING
7625 /* unblock signals of interest and let handler fly */
7626 if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
7627 CRIT_ERR("unable to sigprocmask()");
7631 switch (g_signal_pending) {
7634 ERR("received SIGHUP or SIGUSR1. reloading the config file.");
7639 ERR("received SIGINT or SIGTERM to terminate. bye!");
7642 XDestroyRegion(region);
7645 XDamageDestroy(display, damage);
7646 XFixesDestroyRegion(display, region2);
7647 XFixesDestroyRegion(display, part);
7648 #endif /* HAVE_XDAMAGE */
7650 return; /* return from main_loop */
7653 /* Reaching here means someone set a signal
7654 * (SIGXXXX, signal_handler), but didn't write any code
7656 * If you don't want to handle a signal, don't set a handler on
7657 * it in the first place. */
7658 if (g_signal_pending) {
7659 ERR("ignoring signal (%d)", g_signal_pending);
7663 g_signal_pending = 0;
7666 #if defined(X11) && defined(HAVE_XDAMAGE)
7667 XDamageDestroy(display, damage);
7668 XFixesDestroyRegion(display, region2);
7669 XFixesDestroyRegion(display, part);
7670 XDestroyRegion(region);
7672 #endif /* X11 && HAVE_XDAMAGE */
7675 static void load_config_file(const char *);
7677 /* reload the config file */
7678 void reload_config(void)
7680 timed_thread_destroy_registered_threads();
7682 if (info.cpu_usage) {
7683 free(info.cpu_usage);
7684 info.cpu_usage = NULL;
7692 if (info.mpd.title) {
7693 free(info.mpd.title);
7694 info.mpd.title = NULL;
7696 if (info.mpd.artist) {
7697 free(info.mpd.artist);
7698 info.mpd.artist = NULL;
7700 if (info.mpd.album) {
7701 free(info.mpd.album);
7702 info.mpd.album = NULL;
7704 if (info.mpd.random) {
7705 free(info.mpd.random);
7706 info.mpd.random = NULL;
7708 if (info.mpd.repeat) {
7709 free(info.mpd.repeat);
7710 info.mpd.repeat = NULL;
7712 if (info.mpd.track) {
7713 free(info.mpd.track);
7714 info.mpd.track = NULL;
7716 if (info.mpd.name) {
7717 free(info.mpd.name);
7718 info.mpd.name = NULL;
7720 if (info.mpd.file) {
7721 free(info.mpd.file);
7722 info.mpd.file = NULL;
7724 if (info.mpd.status) {
7725 free(info.mpd.status);
7726 info.mpd.status = NULL;
7734 #ifdef TCP_PORT_MONITOR
7735 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7738 if (current_config) {
7740 load_config_file(current_config);
7742 /* re-init specials array */
7743 if ((specials = realloc((void *) specials,
7744 sizeof(struct special_t) * max_specials)) == 0) {
7745 ERR("failed to realloc specials array");
7751 // clear the window first
7752 XClearWindow(display, RootWindow(display, screen));
7755 #ifdef TCP_PORT_MONITOR
7756 info.p_tcp_port_monitor_collection = NULL;
7758 extract_variable_text(global_text);
7764 tmpstring1 = malloc(text_buffer_size);
7765 memset(tmpstring1, 0, text_buffer_size);
7769 tmpstring2 = malloc(text_buffer_size);
7770 memset(tmpstring2, 0, text_buffer_size);
7774 text_buffer = malloc(max_user_text);
7775 memset(text_buffer, 0, max_user_text);
7782 timed_thread_destroy_registered_threads();
7784 if (info.cpu_usage) {
7785 free(info.cpu_usage);
7786 info.cpu_usage = NULL;
7791 XdbeDeallocateBackBufferName(display, window.back_buffer);
7796 XDestroyWindow(display, window.window);
7797 XClearWindow(display, RootWindow(display, screen));
7802 XClearWindow(display, RootWindow(display, screen));
7807 XFreeGC(display, window.gc);
7811 free_text_objects(global_text_object_list, 1);
7812 free(global_text_object_list);
7813 global_text_object_list = NULL;
7832 free(current_config);
7834 #ifdef TCP_PORT_MONITOR
7835 destroy_tcp_port_monitor_collection(info.p_tcp_port_monitor_collection);
7836 info.p_tcp_port_monitor_collection = NULL;
7845 for (i = 0; i < special_count; i++) {
7846 if (specials[i].type == GRAPH) {
7847 free(specials[i].graph);
7854 clear_diskio_stats();
7857 static int string_to_bool(const char *s)
7860 // Assumes an option without a true/false means true
7862 } else if (strcasecmp(s, "yes") == EQUAL) {
7864 } else if (strcasecmp(s, "true") == EQUAL) {
7866 } else if (strcasecmp(s, "1") == EQUAL) {
7873 static enum alignment string_to_alignment(const char *s)
7875 if (strcasecmp(s, "top_left") == EQUAL) {
7877 } else if (strcasecmp(s, "top_right") == EQUAL) {
7879 } else if (strcasecmp(s, "top_middle") == EQUAL) {
7881 } else if (strcasecmp(s, "bottom_left") == EQUAL) {
7883 } else if (strcasecmp(s, "bottom_right") == EQUAL) {
7884 return BOTTOM_RIGHT;
7885 } else if (strcasecmp(s, "bottom_middle") == EQUAL) {
7886 return BOTTOM_MIDDLE;
7887 } else if (strcasecmp(s, "middle_left") == EQUAL) {
7889 } else if (strcasecmp(s, "middle_right") == EQUAL) {
7890 return MIDDLE_RIGHT;
7891 } else if (strcasecmp(s, "tl") == EQUAL) {
7893 } else if (strcasecmp(s, "tr") == EQUAL) {
7895 } else if (strcasecmp(s, "tm") == EQUAL) {
7897 } else if (strcasecmp(s, "bl") == EQUAL) {
7899 } else if (strcasecmp(s, "br") == EQUAL) {
7900 return BOTTOM_RIGHT;
7901 } else if (strcasecmp(s, "bm") == EQUAL) {
7902 return BOTTOM_MIDDLE;
7903 } else if (strcasecmp(s, "ml") == EQUAL) {
7905 } else if (strcasecmp(s, "mr") == EQUAL) {
7906 return MIDDLE_RIGHT;
7907 } else if (strcasecmp(s, "none") == EQUAL) {
7914 static void set_default_configurations(void)
7916 fork_to_background = 0;
7917 total_run_times = 0;
7918 info.cpu_avg_samples = 2;
7919 info.net_avg_samples = 2;
7926 strcpy(info.mpd.host, "localhost");
7927 info.mpd.port = 6600;
7928 info.mpd.status = NULL;
7929 info.mpd.artist = NULL;
7930 info.mpd.album = NULL;
7931 info.mpd.title = NULL;
7932 info.mpd.random = NULL;
7933 info.mpd.track = NULL;
7934 info.mpd.name = NULL;
7935 info.mpd.file = NULL;
7938 info.xmms2.artist = NULL;
7939 info.xmms2.album = NULL;
7940 info.xmms2.title = NULL;
7941 info.xmms2.genre = NULL;
7942 info.xmms2.comment = NULL;
7943 info.xmms2.url = NULL;
7944 info.xmms2.status = NULL;
7945 info.xmms2.playlist = NULL;
7947 use_spacer = NO_SPACER;
7949 output_methods = TO_X;
7951 output_methods = TO_STDOUT;
7954 show_graph_scale = 0;
7955 show_graph_range = 0;
7956 default_fg_color = WhitePixel(display, screen);
7957 default_bg_color = BlackPixel(display, screen);
7958 default_out_color = BlackPixel(display, screen);
7959 color0 = default_fg_color;
7960 color1 = default_fg_color;
7961 color2 = default_fg_color;
7962 color3 = default_fg_color;
7963 color4 = default_fg_color;
7964 color5 = default_fg_color;
7965 color6 = default_fg_color;
7966 color7 = default_fg_color;
7967 color8 = default_fg_color;
7968 color9 = default_fg_color;
7971 draw_graph_borders = 1;
7973 set_first_font("6x10");
7981 window.type = TYPE_NORMAL;
7983 strcpy(window.class_name, PACKAGE_NAME);
7985 sprintf(window.title, PACKAGE_NAME" (%s)", info.uname_s.nodename);
7987 stippled_borders = 0;
7990 text_alignment = BOTTOM_LEFT;
7991 info.x11.monitor.number = 1;
7992 info.x11.monitor.current = 0;
7995 free(current_mail_spool);
7999 variable_substitute(MAIL_FILE, buf, 256);
8000 if (buf[0] != '\0') {
8001 current_mail_spool = strndup(buf, text_buffer_size);
8006 update_interval = 3.0;
8007 info.music_player_interval = 1.0;
8008 stuff_in_upper_case = 0;
8009 info.users.number = 1;
8011 #ifdef TCP_PORT_MONITOR
8012 tcp_port_monitor_args.max_port_monitor_connections =
8013 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8017 static void load_config_file(const char *f)
8019 #define CONF_ERR ERR("%s: %d: config file error", f, line)
8023 set_default_configurations();
8030 char buf[256], *p, *p2, *name, *value;
8033 if (fgets(buf, 256, fp) == NULL) {
8039 /* break at comment */
8040 p2 = strchr(p, '#');
8046 while (*p && isspace((int) *p)) {
8050 continue; /* empty line */
8057 while (*p2 && !isspace((int) *p2)) {
8061 *p2 = '\0'; /* break at name's end */
8068 while (*p && isspace((int) *p)) {
8074 p2 = value + strlen(value);
8075 while (isspace((int) *(p2 - 1))) {
8082 #define CONF2(a) if (strcasecmp(name, a) == 0)
8083 #define CONF(a) else CONF2(a)
8084 #define CONF3(a, b) else if (strcasecmp(name, a) == 0 \
8085 || strcasecmp(name, b) == 0)
8088 CONF2("alignment") {
8090 int a = string_to_alignment(value);
8101 CONF("background") {
8102 fork_to_background = string_to_bool(value);
8105 CONF2("background") {
8106 fork_to_background = string_to_bool(value);
8110 CONF("show_graph_scale") {
8111 show_graph_scale = string_to_bool(value);
8113 CONF("show_graph_range") {
8114 show_graph_range = string_to_bool(value);
8116 CONF("border_margin") {
8118 border_margin = strtol(value, 0, 0);
8123 CONF("border_width") {
8125 border_width = strtol(value, 0, 0);
8132 color0 = get_x11_color(value);
8139 color1 = get_x11_color(value);
8146 color2 = get_x11_color(value);
8153 color3 = get_x11_color(value);
8160 color4 = get_x11_color(value);
8167 color5 = get_x11_color(value);
8174 color6 = get_x11_color(value);
8181 color7 = get_x11_color(value);
8188 color8 = get_x11_color(value);
8195 color9 = get_x11_color(value);
8200 CONF("default_color") {
8202 default_fg_color = get_x11_color(value);
8207 CONF3("default_shade_color", "default_shadecolor") {
8209 default_bg_color = get_x11_color(value);
8214 CONF3("default_outline_color", "default_outlinecolor") {
8216 default_out_color = get_x11_color(value);
8224 info.mail = parse_mail_args(IMAP, value);
8231 info.mail = parse_mail_args(POP3, value);
8239 strncpy(info.mpd.host, value, 127);
8246 info.mpd.port = strtol(value, 0, 0);
8247 if (info.mpd.port < 1 || info.mpd.port > 0xffff) {
8252 CONF("mpd_password") {
8254 strncpy(info.mpd.password, value, 127);
8260 CONF("music_player_interval") {
8262 info.music_player_interval = strtod(value, 0);
8268 CONF("sensor_device") {
8270 sensor_device = strtol(value, 0, 0);
8276 CONF("cpu_avg_samples") {
8278 cpu_avg_samples = strtol(value, 0, 0);
8279 if (cpu_avg_samples < 1 || cpu_avg_samples > 14) {
8282 info.cpu_avg_samples = cpu_avg_samples;
8288 CONF("net_avg_samples") {
8290 net_avg_samples = strtol(value, 0, 0);
8291 if (net_avg_samples < 1 || net_avg_samples > 14) {
8294 info.net_avg_samples = net_avg_samples;
8302 CONF("double_buffer") {
8303 use_xdbe = string_to_bool(value);
8307 CONF("override_utf8_locale") {
8308 utf8_mode = string_to_bool(value);
8310 CONF("draw_borders") {
8311 draw_borders = string_to_bool(value);
8313 CONF("draw_graph_borders") {
8314 draw_graph_borders = string_to_bool(value);
8316 CONF("draw_shades") {
8317 draw_shades = string_to_bool(value);
8319 CONF("draw_outline") {
8320 draw_outline = string_to_bool(value);
8323 CONF("out_to_console") {
8324 if(string_to_bool(value)) output_methods |= TO_STDOUT;
8326 CONF("use_spacer") {
8328 if (strcasecmp(value, "left") == EQUAL) {
8329 use_spacer = LEFT_SPACER;
8330 } else if (strcasecmp(value, "right") == EQUAL) {
8331 use_spacer = RIGHT_SPACER;
8332 } else if (strcasecmp(value, "none") == EQUAL) {
8333 use_spacer = NO_SPACER;
8335 use_spacer = string_to_bool(value);
8336 ERR("use_spacer should have an argument of left, right, or"
8337 " none. '%s' seems to be some form of '%s', so"
8338 " defaulting to %s.", value,
8339 use_spacer ? "true" : "false",
8340 use_spacer ? "right" : "none");
8342 use_spacer = RIGHT_SPACER;
8344 use_spacer = NO_SPACER;
8348 ERR("use_spacer should have an argument. Defaulting to right.");
8349 use_spacer = RIGHT_SPACER;
8355 use_xft = string_to_bool(value);
8359 set_first_font(value);
8365 if (value && font_count >= 0) {
8366 fonts[0].font_alpha = atof(value) * 65535.0;
8375 if (string_to_bool(value)) {
8376 ERR("Xft not enabled");
8380 /* xftfont silently ignored when no Xft */
8383 /* xftalpha is silently ignored when no Xft */
8388 set_first_font(value);
8398 gap_x = atoi(value);
8405 gap_y = atoi(value);
8411 CONF("mail_spool") {
8415 variable_substitute(value, buffer, 256);
8417 if (buffer[0] != '\0') {
8418 if (current_mail_spool) {
8419 free(current_mail_spool);
8421 current_mail_spool = strndup(buffer, text_buffer_size);
8428 CONF("minimum_size") {
8430 if (sscanf(value, "%d %d", &minimum_width, &minimum_height)
8432 if (sscanf(value, "%d", &minimum_width) != 1) {
8440 CONF("maximum_width") {
8442 if (sscanf(value, "%d", &maximum_width) != 1) {
8450 CONF("no_buffers") {
8451 no_buffers = string_to_bool(value);
8453 CONF("top_cpu_separate") {
8454 cpu_separate = string_to_bool(value);
8456 CONF("short_units") {
8457 short_units = string_to_bool(value);
8459 CONF("pad_percents") {
8460 pad_percents = atoi(value);
8464 CONF("own_window") {
8466 own_window = string_to_bool(value);
8471 CONF("own_window_class") {
8473 memset(window.class_name, 0, sizeof(window.class_name));
8474 strncpy(window.class_name, value,
8475 sizeof(window.class_name) - 1);
8480 CONF("own_window_title") {
8482 memset(window.title, 0, sizeof(window.title));
8483 strncpy(window.title, value, sizeof(window.title) - 1);
8488 CONF("own_window_transparent") {
8490 set_transparent = string_to_bool(value);
8495 CONF("own_window_colour") {
8497 background_colour = get_x11_color(value);
8499 ERR("Invalid colour for own_window_colour (try omitting the "
8500 "'#' for hex colours");
8503 CONF("own_window_hints") {
8505 char *p_hint, *p_save;
8506 char delim[] = ", ";
8508 /* tokenize the value into individual hints */
8509 if ((p_hint = strtok_r(value, delim, &p_save)) != NULL) {
8511 /* fprintf(stderr, "hint [%s] parsed\n", p_hint); */
8512 if (strncmp(p_hint, "undecorate", 10) == EQUAL) {
8513 SET_HINT(window.hints, HINT_UNDECORATED);
8514 } else if (strncmp(p_hint, "below", 5) == EQUAL) {
8515 SET_HINT(window.hints, HINT_BELOW);
8516 } else if (strncmp(p_hint, "above", 5) == EQUAL) {
8517 SET_HINT(window.hints, HINT_ABOVE);
8518 } else if (strncmp(p_hint, "sticky", 6) == EQUAL) {
8519 SET_HINT(window.hints, HINT_STICKY);
8520 } else if (strncmp(p_hint, "skip_taskbar", 12) == EQUAL) {
8521 SET_HINT(window.hints, HINT_SKIP_TASKBAR);
8522 } else if (strncmp(p_hint, "skip_pager", 10) == EQUAL) {
8523 SET_HINT(window.hints, HINT_SKIP_PAGER);
8528 p_hint = strtok_r(NULL, delim, &p_save);
8529 } while (p_hint != NULL);
8535 CONF("own_window_type") {
8537 if (strncmp(value, "normal", 6) == EQUAL) {
8538 window.type = TYPE_NORMAL;
8539 } else if (strncmp(value, "desktop", 7) == EQUAL) {
8540 window.type = TYPE_DESKTOP;
8541 } else if (strncmp(value, "dock", 7) == EQUAL) {
8542 window.type = TYPE_DOCK;
8543 } else if (strncmp(value, "override", 8) == EQUAL) {
8544 window.type = TYPE_OVERRIDE;
8553 CONF("stippled_borders") {
8555 stippled_borders = strtol(value, 0, 0);
8557 stippled_borders = 4;
8562 ERR("temp1 configuration is obsolete, use ${i2c <i2c device here> "
8566 ERR("temp2 configuration is obsolete, use ${i2c <i2c device here> "
8569 CONF("update_interval") {
8571 update_interval = strtod(value, 0);
8575 if (info.music_player_interval == 0) {
8576 // default to update_interval
8577 info.music_player_interval = update_interval;
8580 CONF("total_run_times") {
8582 total_run_times = strtod(value, 0);
8588 stuff_in_upper_case = string_to_bool(value);
8590 CONF("max_specials") {
8592 max_specials = atoi(value);
8597 CONF("max_user_text") {
8599 max_user_text = atoi(value);
8604 CONF("text_buffer_size") {
8606 text_buffer_size = atoi(value);
8607 if (text_buffer_size < DEFAULT_TEXT_BUFFER_SIZE) {
8608 ERR("text_buffer_size must be >=%i bytes", DEFAULT_TEXT_BUFFER_SIZE);
8609 text_buffer_size = DEFAULT_TEXT_BUFFER_SIZE;
8621 global_text = (char *) malloc(1);
8622 global_text[0] = '\0';
8625 unsigned int l = strlen(global_text);
8627 if (fgets(buf, 256, fp) == NULL) {
8630 global_text = (char *) realloc(global_text, l + strlen(buf) + 1);
8631 strcat(global_text, buf);
8633 if (strlen(global_text) > max_user_text) {
8638 if (strlen(global_text) < 1) {
8639 CRIT_ERR("no text supplied in configuration; exiting");
8641 global_text_lines = line + 1;
8644 #ifdef TCP_PORT_MONITOR
8645 CONF("max_port_monitor_connections") {
8646 if (!value || (sscanf(value, "%d",
8647 &tcp_port_monitor_args.max_port_monitor_connections) != 1)
8648 || tcp_port_monitor_args.max_port_monitor_connections < 0) {
8649 /* an error. use default, warn and continue. */
8650 tcp_port_monitor_args.max_port_monitor_connections =
8651 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8653 } else if (tcp_port_monitor_args.max_port_monitor_connections
8655 /* no error, just use default */
8656 tcp_port_monitor_args.max_port_monitor_connections =
8657 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8659 /* else tcp_port_monitor_args.max_port_monitor_connections > 0
8663 CONF("if_up_strictness") {
8665 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8666 ifup_strictness = IFUP_UP;
8667 } else if (strcasecmp(value, "up") == EQUAL) {
8668 ifup_strictness = IFUP_UP;
8669 } else if (strcasecmp(value, "link") == EQUAL) {
8670 ifup_strictness = IFUP_LINK;
8671 } else if (strcasecmp(value, "address") == EQUAL) {
8672 ifup_strictness = IFUP_ADDR;
8674 ERR("incorrect if_up_strictness value, defaulting to 'up'");
8675 ifup_strictness = IFUP_UP;
8679 ERR("%s: %d: no such configuration: '%s'", f, line, name);
8690 if (info.music_player_interval == 0) {
8691 // default to update_interval
8692 info.music_player_interval = update_interval;
8694 if (!global_text) { // didn't supply any text
8695 CRIT_ERR("missing text block in configuration; exiting");
8699 static void print_help(const char *prog_name) {
8700 printf("Usage: %s [OPTION]...\n"
8701 PACKAGE_NAME" is a system monitor that renders text on desktop or to own transparent\n"
8702 "window. Command line options will override configurations defined in config\n"
8704 " -v, --version version\n"
8705 " -q, --quiet quiet mode\n"
8706 " -c, --config=FILE config file to load\n"
8707 " -d, --daemonize daemonize, fork to background\n"
8708 " -h, --help help\n"
8710 " -a, --alignment=ALIGNMENT text alignment on screen, {top,bottom,middle}_{left,right,middle}\n"
8711 " -f, --font=FONT font to use\n"
8713 " -o, --own-window create own window to draw\n"
8716 " -b, --double-buffer double buffer (prevents flickering)\n"
8718 " -w, --window-id=WIN_ID window id to draw\n"
8719 " -x X x position\n"
8720 " -y Y y position\n"
8722 " -t, --text=TEXT text to render, remember single quotes, like -t '$uptime'\n"
8723 " -u, --interval=SECS update interval\n"
8724 " -i COUNT number of times to update "PACKAGE_NAME" (and quit)\n",
8729 /* : means that character before that takes an argument */
8730 static const char *getopt_string = "vVqdt:u:i:hc:"
8742 static const struct option longopts[] = {
8743 { "help", 0, NULL, 'h' },
8744 { "version", 0, NULL, 'V' },
8745 { "config", 1, NULL, 'c' },
8746 { "daemonize", 0, NULL, 'd' },
8748 { "alignment", 1, NULL, 'a' },
8749 { "font", 1, NULL, 'f' },
8751 { "own-window", 0, NULL, 'o' },
8754 { "double-buffer", 0, NULL, 'b' },
8756 { "window-id", 1, NULL, 'w' },
8758 { "text", 1, NULL, 't' },
8759 { "interval", 0, NULL, 'u' },
8763 int main(int argc, char **argv)
8769 struct sigaction act, oact;
8771 g_signal_pending = 0;
8772 memset(&info, 0, sizeof(info));
8774 #ifdef TCP_PORT_MONITOR
8775 tcp_port_monitor_args.max_port_monitor_connections =
8776 MAX_PORT_MONITOR_CONNECTIONS_DEFAULT;
8779 /* handle command line parameters that don't change configs */
8781 if (((s = getenv("LC_ALL")) && *s) || ((s = getenv("LC_CTYPE")) && *s)
8782 || ((s = getenv("LANG")) && *s)) {
8783 temp = (char *) malloc((strlen(s) + 1) * sizeof(char));
8785 ERR("malloc failed");
8787 for (x = 0; x < strlen(s); x++) {
8788 temp[x] = tolower(s[x]);
8791 if (strstr(temp, "utf-8") || strstr(temp, "utf8")) {
8797 if (!setlocale(LC_CTYPE, "")) {
8798 ERR("Can't set the specified locale!\nCheck LANG, LC_CTYPE, LC_ALL.");
8802 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8813 if (current_config) {
8814 free(current_config);
8816 current_config = strndup(optarg, max_user_text);
8819 freopen("/dev/null", "w", stderr);
8822 print_help(argv[0]);
8826 window.window = strtol(optarg, 0, 0);
8835 /* initalize X BEFORE we load config.
8836 * (we need to so that 'screen' is set) */
8840 /* check if specified config file is valid */
8841 if (current_config) {
8843 if (stat(current_config, &sb) ||
8844 (!S_ISREG(sb.st_mode) && !S_ISLNK(sb.st_mode))) {
8845 ERR("invalid configuration file '%s'\n", current_config);
8846 free(current_config);
8851 /* load current_config, CONFIG_FILE or SYSTEM_CONFIG_FILE */
8853 if (!current_config) {
8854 /* load default config file */
8858 /* Try to use personal config file first */
8859 variable_substitute(CONFIG_FILE, buf, sizeof(buf));
8860 if (buf[0] && (fp = fopen(buf, "r"))) {
8861 current_config = strndup(buf, max_user_text);
8865 /* Try to use system config file if personal config not readable */
8866 if (!current_config && (fp = fopen(SYSTEM_CONFIG_FILE, "r"))) {
8867 current_config = strndup(SYSTEM_CONFIG_FILE, max_user_text);
8871 /* No readable config found */
8872 if (!current_config) {
8873 CRIT_ERR("no readable personal or system-wide config file found");
8877 load_config_file(current_config);
8879 /* init specials array */
8880 if ((specials = calloc(sizeof(struct special_t), max_specials)) == 0) {
8881 ERR("failed to create specials array");
8885 if (current_mail_spool == NULL) {
8888 variable_substitute(MAIL_FILE, buf, 256);
8890 if (buf[0] != '\0') {
8891 current_mail_spool = strndup(buf, text_buffer_size);
8896 /* handle other command line arguments */
8898 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__OpenBSD__) \
8899 || defined(__NetBSD__)
8900 optind = optreset = 1;
8905 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
8906 if ((kd = kvm_open("/dev/null", "/dev/null", "/dev/null", O_RDONLY,
8907 "kvm_open")) == NULL) {
8908 CRIT_ERR("cannot read kvm");
8913 int c = getopt_long(argc, argv, getopt_string, longopts, NULL);
8921 fork_to_background = 1;
8926 set_first_font(optarg);
8929 text_alignment = string_to_alignment(optarg);
8948 global_text = strndup(optarg, max_user_text);
8949 convert_escapes(global_text);
8953 update_interval = strtod(optarg, 0);
8954 if (info.music_player_interval == 0) {
8955 // default to update_interval
8956 info.music_player_interval = update_interval;
8961 total_run_times = strtod(optarg, 0);
8965 gap_x = atoi(optarg);
8969 gap_y = atoi(optarg);
8983 /* generate text and get initial size */
8984 extract_variable_text(global_text);
8991 if (fork_to_background) {
8996 ERR(PACKAGE_NAME": couldn't fork() to background: %s",
9003 fprintf(stderr, "\n");
9008 /* parent process */
9009 fprintf(stderr, PACKAGE_NAME": forked to background, pid is %d\n",
9016 text_buffer = malloc(max_user_text);
9017 memset(text_buffer, 0, max_user_text);
9018 tmpstring1 = malloc(text_buffer_size);
9019 memset(tmpstring1, 0, text_buffer_size);
9020 tmpstring2 = malloc(text_buffer_size);
9021 memset(tmpstring2, 0, text_buffer_size);
9025 update_text_area(); /* to get initial size of the window */
9028 init_window(own_window, text_width + border_margin * 2 + 1,
9029 text_height + border_margin * 2 + 1, set_transparent, background_colour,
9031 #else /* OWN_WINDOW */
9032 init_window(0, text_width + border_margin * 2 + 1,
9033 text_height + border_margin * 2 + 1, set_transparent, 0,
9035 #endif /* OWN_WINDOW */
9038 update_text_area(); /* to position text/window on screen */
9041 if (own_window && !fixed_pos) {
9042 XMoveWindow(display, window.window, window.x, window.y);
9045 set_transparent_background(window.window);
9055 /* Set signal handlers */
9056 act.sa_handler = signal_handler;
9057 sigemptyset(&act.sa_mask);
9060 act.sa_flags |= SA_RESTART;
9063 if (sigaction(SIGINT, &act, &oact) < 0
9064 || sigaction(SIGUSR1, &act, &oact) < 0
9065 || sigaction(SIGHUP,&act,&oact) < 0
9066 || sigaction(SIGTERM, &act, &oact) < 0) {
9067 ERR("error setting signal handler: %s", strerror(errno));
9070 /* *************** *
9072 * *************** */
9075 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
9082 void signal_handler(int sig)
9084 /* signal handler is light as a feather, as it should be.
9085 * we will poll g_signal_pending with each loop of conky
9086 * and do any signal processing there, NOT here. */
9087 g_signal_pending = sig;