9 struct information info;
20 return tv.tv_sec + tv.tv_usec / 1000000.0;
23 FILE *open_file(const char *file, int *reported)
25 FILE *fp = fopen(file, "r");
27 if (!reported || *reported == 0) {
28 ERR("can't open %s: %s", file, strerror(errno));
38 void variable_substitute(const char *s, char *dest, unsigned int n)
48 /* variable is either $foo or ${foo} */
52 while (*s && *s != '}')
62 /* copy variable to buffer and look it up */
63 len = (s - a > 255) ? 255 : (s - a);
77 strncpy(dest, var, len);
92 /* network interface stuff */
94 static struct net_stat netstats[16];
96 struct net_stat *get_net_stat(const char *dev)
103 /* find interface stat */
104 for (i = 0; i < 16; i++) {
105 if (netstats[i].dev && strcmp(netstats[i].dev, dev) == 0)
109 /* wasn't found? add it */
111 for (i = 0; i < 16; i++) {
112 if (netstats[i].dev == 0) {
113 netstats[i].dev = strdup(dev);
119 CRIT_ERR("too many interfaces used (limit is 16)");
123 void format_seconds(char *buf, unsigned int n, long t)
125 if (t >= 24 * 60 * 60) /* hours necessary when there are days? */
126 snprintf(buf, n, "%ldd %ldh %ldm", t / 60 / 60 / 24,
127 (t / 60 / 60) % 24, (t / 60) % 60);
128 else if (t >= 60 * 60)
129 snprintf(buf, n, "%ldh %ldm", (t / 60 / 60) % 24,
132 snprintf(buf, n, "%ldm %lds", t / 60, t % 60);
135 void format_seconds_short(char *buf, unsigned int n, long t)
137 if (t >= 24 * 60 * 60)
138 snprintf(buf, n, "%ldd %ldh", t / 60 / 60 / 24,
140 else if (t >= 60 * 60)
141 snprintf(buf, n, "%ldh %ldm", (t / 60 / 60) % 24,
144 snprintf(buf, n, "%ldm", t / 60);
147 static double last_meminfo_update;
148 static double last_fs_update;
150 unsigned int need_mask;
158 need_mask |= 1 << INFO_BUFFERS;
160 /* clear speeds and up status in case device was removed and doesn't get
163 for (i = 0; i < 16; i++) {
164 if (netstats[i].dev) {
166 netstats[i].recv_speed = 0.0;
167 netstats[i].trans_speed = 0.0;
173 #define NEED(a) ((need_mask & (1 << a)) && ((info.mask & (1 << a)) == 0))
175 if (NEED(INFO_UPTIME))
178 if (NEED(INFO_PROCS))
179 update_total_processes();
181 if (NEED(INFO_RUN_PROCS))
182 update_running_processes();
200 if (NEED(INFO_MLDONKEY)) get_mldonkey_status(&mlconfig, &mlinfo);
213 if (NEED(INFO_LOADAVG))
214 update_load_average();
217 if (NEED(INFO_METAR) && current_update_time - last_metar_update > 1200.9 && info.looped) {
219 last_metar_update = current_update_time;
224 if ((NEED(INFO_MEM) || NEED(INFO_BUFFERS)) &&
225 current_update_time - last_meminfo_update > 6.9) {
228 info.mem -= info.bufmem;
229 last_meminfo_update = current_update_time;
232 /* update_fs_stat() won't do anything if there aren't fs -things */
233 if (NEED(INFO_FS) && current_update_time - last_fs_update > 12.9) {
235 last_fs_update = current_update_time;