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/>.
31 #if defined(HAS_MCHECK_H)
33 #endif /* HAS_MCHECK_H */
38 #define EQUAL 0 //returnvalue of strcmp-variants when strings are equal
43 #include <sys/utsname.h>
50 #include <sys/param.h>
52 #if !defined(__GNUC__)
53 # define __attribute__(x) /* nothing */
56 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
58 #endif /* __FreeBSD__ || __FreeBSD_kernel__ */
60 #if defined(__OpenBSD__)
62 #endif /* __OpenBSD__ */
65 // use our own strndup() if it's not available
66 char *strndup(const char *s, size_t n);
67 #endif /* HAVE_STRNDUP */
70 #include "audacious.h"
74 #include <xmmsclient/xmmsclient.h>
94 #include "timed_thread.h"
97 #define DEFAULT_TEXT_BUFFER_SIZE 256
98 extern unsigned int text_buffer_size;
100 /* maximum number of special things, e.g. fonts, offsets, aligns, etc. */
101 #define MAX_SPECIALS_DEFAULT 512
103 /* maximum size of config TEXT buffer, i.e. below TEXT line. */
104 #define MAX_USER_TEXT_DEFAULT 16384
106 #include <sys/socket.h>
109 fprintf(stderr, PACKAGE_NAME": "); \
110 fprintf(stderr, __VA_ARGS__); \
111 fprintf(stderr, "\n"); \
115 #define CRIT_ERR(...) \
116 { ERR(__VA_ARGS__); exit(EXIT_FAILURE); }
118 /* debugging output */
119 extern int global_debug_level;
120 #define __DBGP(level, ...) \
121 if (global_debug_level > level) { \
122 fprintf(stderr, "DEBUG(%d) [" __FILE__ ":%d]: ", level, __LINE__); \
123 fprintf(stderr, __VA_ARGS__); \
124 fprintf(stderr, "\n"); \
126 #define DBGP(...) __DBGP(0, __VA_ARGS__)
127 #define DBGP2(...) __DBGP(1, __VA_ARGS__)
132 long long last_read_recv, last_read_trans;
133 long long recv, trans;
134 double recv_speed, trans_speed;
135 struct sockaddr addr;
137 double net_rec[15], net_trans[15];
138 // wireless extensions
153 char path[DEFAULT_TEXT_BUFFER_SIZE];
154 char type[DEFAULT_TEXT_BUFFER_SIZE];
163 struct mail_s { // for imap and pop3
164 unsigned long unseen;
165 unsigned long messages;
169 unsigned int retries;
177 timed_thread *p_timed_thread;
182 unsigned int user, nice, system, idle, iowait, irq, softirq;
199 #include "audacious.h"
206 void update_entropy(void);
208 unsigned int entropy_avail;
209 unsigned int poolsize;
219 struct gateway_info {
226 struct monitor_info {
232 struct monitor_info monitor;
236 #ifdef TCP_PORT_MONITOR
237 #include "libtcp-portmon.h"
262 #ifdef TCP_PORT_MONITOR
263 INFO_TCP_PORT_MONITOR = 19,
295 /* get_battery_stuff() item selector */
301 /* if_up strictness selector */
308 /* Update interval */
309 double update_interval;
311 volatile int g_signal_pending;
316 struct utsname uname_s;
322 /* memory information in kilobytes */
323 unsigned long long mem, memeasyfree, memfree, memmax, swap, swapmax;
324 unsigned long long bufmem, buffers, cached;
326 unsigned short procs;
327 unsigned short run_procs;
330 /* struct cpu_stat cpu_summed; what the hell is this? */
331 unsigned int cpu_count;
332 unsigned int cpu_avg_samples;
334 unsigned int net_avg_samples;
347 struct xmms2_s xmms2;
348 int xmms2_conn_state;
349 xmms_socket_t xmms2_fd;
351 xmmsc_connection_t *xmms2_conn;
354 AUDACIOUS_S audacious;
359 struct usr_info users;
360 struct gateway_info gw_info;
361 struct dns_data nameserver_info;
362 struct process *cpu[10];
363 struct process *memu[10];
364 struct process *first_process;
365 unsigned long looped;
366 #ifdef TCP_PORT_MONITOR
367 tcp_port_monitor_collection_t *p_tcp_port_monitor_collection;
369 struct entropy_s entropy;
370 double music_player_interval;
376 short kflags; /* kernel settings, see enum KFLAG */
378 unsigned int diskio_value;
379 unsigned int diskio_read_value;
380 unsigned int diskio_write_value;
384 /* set to true if kernel uses "long" format for /proc/stats */
385 KFLAG_IS_LONGSTAT = 0x01,
386 /* set to true if kernel shows # of threads for the proc value
387 * in sysinfo() call */
388 KFLAG_PROC_IS_THREADS = 0x02
389 /* bits 0x04, 0x08, 0x10, 0x20, 0x40, 0x80 available for future use */
390 /* KFLAG_NEXT_ONE = 0x04 */
393 #define KFLAG_SETON(a) info.kflags |= a
394 #define KFLAG_SETOFF(a) info.kflags &= (~a)
395 #define KFLAG_FLIP(a) info.kflags ^= a
396 #define KFLAG_ISSET(a) info.kflags & a
407 enum spacer_opts { NO_SPACER = 0, LEFT_SPACER, RIGHT_SPACER };
419 /* struct that has all info */
420 struct information info;
422 void signal_handler(int);
423 void reload_config(void);
426 void update_uname(void);
427 double get_time(void);
428 FILE *open_file(const char *file, int *reported);
429 void variable_substitute(const char *s, char *dest, unsigned int n);
430 void format_seconds(char *buf, unsigned int n, long t);
431 void format_seconds_short(char *buf, unsigned int n, long t);
432 struct net_stat *get_net_stat(const char *dev);
433 void clear_net_stats(void);
434 void free_dns_data(void);
435 void update_dns_data(void);
436 void update_users(void);
439 void update_x11info(void);
442 void update_stuff(void);
444 int round_to_int(float f);
446 extern unsigned long long need_mask;
448 extern double current_update_time, last_update_time;
450 extern int no_buffers;
452 #if defined(__linux__)
460 #if (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) \
461 || defined(__OpenBSD__)) && (defined(i386) || defined(__i386__))
462 int apm_getinfo(int fd, apm_info_t aip);
463 char *get_apm_adapter(void);
464 char *get_apm_battery_life(void);
465 char *get_apm_battery_time(void);