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/>.
33 #if defined(HAS_MCHECK_H)
35 #endif /* HAS_MCHECK_H */
40 #define EQUAL 0 //returnvalue of strcmp-variants when strings are equal
45 #include <sys/utsname.h>
52 #include <sys/param.h>
54 #if !defined(__GNUC__)
55 # define __attribute__(x) /* nothing */
58 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
60 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
62 #if defined(__OpenBSD__)
64 #endif /* __OpenBSD__ */
67 // use our own strndup() if it's not available
68 char *strndup(const char *s, size_t n);
69 #endif /* HAVE_STRNDUP */
72 #include "audacious.h"
76 #include <xmmsclient/xmmsclient.h>
96 #include "timed_thread.h"
99 #define DEFAULT_TEXT_BUFFER_SIZE 256
100 extern unsigned int text_buffer_size;
102 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
103 #define MAX_SPECIALS_DEFAULT 512
105 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
106 #define MAX_USER_TEXT_DEFAULT 16384
108 #include <sys/socket.h>
111 fprintf(stderr, PACKAGE_NAME": "); \
112 fprintf(stderr, __VA_ARGS__); \
113 fprintf(stderr, "\n"); \
117 #define CRIT_ERR(...) \
118 { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
120 /* debugging output */
121 extern int global_debug_level;
122 #define __DBG(level, ...) \
123 if (global_debug_level > level) { \
124 fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__); \
125 fprintf(stderr, __VA_ARGS__); \
126 fprintf(stderr, "\n"); \
128 #define DEBUG(...) __DBG(0, __VA_ARGS__)
129 #define DEBUG2(...) __DBG(1, __VA_ARGS__)
134 long long last_read_recv, last_read_trans;
135 long long recv, trans;
136 double recv_speed, trans_speed;
137 struct sockaddr addr;
139 double net_rec[15], net_trans[15];
140 // wireless extensions
155 char path[DEFAULT_TEXT_BUFFER_SIZE];
156 char type[DEFAULT_TEXT_BUFFER_SIZE];
165 struct mail_s { // for imap and pop3
166 unsigned long unseen;
167 unsigned long messages;
171 unsigned int retries;
179 timed_thread *p_timed_thread;
184 unsigned int user, nice, system, idle, iowait, irq, softirq;
201 #include "audacious.h"
208 void update_entropy(void);
210 unsigned int entropy_avail;
211 unsigned int poolsize;
221 struct gateway_info {
228 struct monitor_info {
234 struct monitor_info monitor;
238 #ifdef TCP_PORT_MONITOR
239 #include "libtcp-portmon.h"
264 #ifdef TCP_PORT_MONITOR
265 INFO_TCP_PORT_MONITOR = 19,
297 /* get_battery_stuff() item selector */
303 /* if_up strictness selector */
310 /* Update interval */
311 double update_interval;
313 volatile int g_signal_pending;
318 struct utsname uname_s;
324 /* memory information in kilobytes */
325 unsigned long long mem, memeasyfree, memfree, memmax, swap, swapmax;
326 unsigned long long bufmem, buffers, cached;
328 unsigned short procs;
329 unsigned short run_procs;
332 /* struct cpu_stat cpu_summed; what the hell is this? */
333 unsigned int cpu_count;
334 unsigned int cpu_avg_samples;
336 unsigned int net_avg_samples;
349 struct xmms2_s xmms2;
350 int xmms2_conn_state;
351 xmms_socket_t xmms2_fd;
353 xmmsc_connection_t *xmms2_conn;
356 AUDACIOUS_S audacious;
361 struct usr_info users;
362 struct gateway_info gw_info;
363 struct dns_data nameserver_info;
364 struct process *cpu[10];
365 struct process *memu[10];
366 struct process *first_process;
367 unsigned long looped;
368 #ifdef TCP_PORT_MONITOR
369 tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
371 struct entropy_s entropy;
372 double music_player_interval;
378 short kflags; /* kernel settings, see enum KFLAG */
380 unsigned int diskio_value;
381 unsigned int diskio_read_value;
382 unsigned int diskio_write_value;
386 /* set to true if kernel uses "long" format for /proc/stats */
387 KFLAG_IS_LONGSTAT = 0x01,
388 /* set to true if kernel shows # of threads for the proc value
389 * in sysinfo() call */
390 KFLAG_PROC_IS_THREADS = 0x02
391 /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
392 /* KFLAG_NEXT_ONE = 0x04 */
395 #define KFLAG_SETON(a) info.kflags |= a
396 #define KFLAG_SETOFF(a) info.kflags &= (~a)
397 #define KFLAG_FLIP(a) info.kflags ^= a
398 #define KFLAG_ISSET(a) info.kflags & a
409 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
421 /* struct that has all info */
422 struct information info;
424 void signal_handler(int);
425 void reload_config(void);
428 void update_uname(void);
429 double get_time(void);
430 FILE *open_file(const char *file, int *reported);
431 void variable_substitute(const char *s, char *dest, unsigned int n);
432 void format_seconds(char *buf, unsigned int n, long t);
433 void format_seconds_short(char *buf, unsigned int n, long t);
434 struct net_stat *get_net_stat(const char *dev);
435 void clear_net_stats(void);
436 void free_dns_data(void);
437 void update_dns_data(void);
438 void update_users(void);
441 void update_x11info(void);
444 void update_stuff(void);
446 int round_to_int(float f);
448 extern unsigned long long need_mask;
450 extern double current_update_time, last_update_time;
452 extern int no_buffers;
454 #if defined(__linux__)
462 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
463 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
464 int apm_getinfo(int fd, apm_info_t aip);
465 char *get_apm_adapter(void);
466 char *get_apm_battery_life(void);
467 char *get_apm_battery_time(void);