]> git.proxmox.com Git - mirror_iproute2.git/blob - misc/ifstat.c
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/shemminger...
[mirror_iproute2.git] / misc / ifstat.c
1 /*
2 * ifstat.c handy utility to read net interface statistics
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
10 */
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <fcntl.h>
16 #include <string.h>
17 #include <errno.h>
18 #include <time.h>
19 #include <sys/time.h>
20 #include <fnmatch.h>
21 #include <sys/file.h>
22 #include <sys/socket.h>
23 #include <sys/un.h>
24 #include <sys/poll.h>
25 #include <sys/wait.h>
26 #include <sys/stat.h>
27 #include <signal.h>
28 #include <math.h>
29 #include <getopt.h>
30
31 #include <libnetlink.h>
32 #include <linux/if.h>
33 #include <linux/if_link.h>
34
35 #include <SNAPSHOT.h>
36
37 int dump_zeros = 0;
38 int reset_history = 0;
39 int ignore_history = 0;
40 int no_output = 0;
41 int no_update = 0;
42 int scan_interval = 0;
43 int time_constant = 0;
44 int show_errors = 0;
45 double W;
46 char **patterns;
47 int npatterns;
48
49 char info_source[128];
50 int source_mismatch;
51
52 #define MAXS (sizeof(struct rtnl_link_stats)/sizeof(__u32))
53
54 struct ifstat_ent
55 {
56 struct ifstat_ent *next;
57 char *name;
58 int ifindex;
59 unsigned long long val[MAXS];
60 double rate[MAXS];
61 __u32 ival[MAXS];
62 };
63
64 struct ifstat_ent *kern_db;
65 struct ifstat_ent *hist_db;
66
67 static int match(const char *id)
68 {
69 int i;
70
71 if (npatterns == 0)
72 return 1;
73
74 for (i=0; i<npatterns; i++) {
75 if (!fnmatch(patterns[i], id, 0))
76 return 1;
77 }
78 return 0;
79 }
80
81 static int get_nlmsg(const struct sockaddr_nl *who,
82 struct nlmsghdr *m, void *arg)
83 {
84 struct ifinfomsg *ifi = NLMSG_DATA(m);
85 struct rtattr * tb[IFLA_MAX+1];
86 int len = m->nlmsg_len;
87 struct ifstat_ent *n;
88 int i;
89
90 if (m->nlmsg_type != RTM_NEWLINK)
91 return 0;
92
93 len -= NLMSG_LENGTH(sizeof(*ifi));
94 if (len < 0)
95 return -1;
96
97 if (!(ifi->ifi_flags&IFF_UP))
98 return 0;
99
100 parse_rtattr(tb, IFLA_MAX, IFLA_RTA(ifi), len);
101 if (tb[IFLA_IFNAME] == NULL || tb[IFLA_STATS] == NULL)
102 return 0;
103
104 n = malloc(sizeof(*n));
105 if (!n)
106 abort();
107 n->ifindex = ifi->ifi_index;
108 n->name = strdup(RTA_DATA(tb[IFLA_IFNAME]));
109 memcpy(&n->ival, RTA_DATA(tb[IFLA_STATS]), sizeof(n->ival));
110 memset(&n->rate, 0, sizeof(n->rate));
111 for (i=0; i<MAXS; i++)
112 n->val[i] = n->ival[i];
113 n->next = kern_db;
114 kern_db = n;
115 return 0;
116 }
117
118 static void load_info(void)
119 {
120 struct ifstat_ent *db, *n;
121 struct rtnl_handle rth;
122
123 if (rtnl_open(&rth, 0) < 0)
124 exit(1);
125
126 if (rtnl_wilddump_request(&rth, AF_INET, RTM_GETLINK) < 0) {
127 perror("Cannot send dump request");
128 exit(1);
129 }
130
131 if (rtnl_dump_filter(&rth, get_nlmsg, NULL) < 0) {
132 fprintf(stderr, "Dump terminated\n");
133 exit(1);
134 }
135
136 rtnl_close(&rth);
137
138 db = kern_db;
139 kern_db = NULL;
140
141 while (db) {
142 n = db;
143 db = db->next;
144 n->next = kern_db;
145 kern_db = n;
146 }
147 }
148
149 static void load_raw_table(FILE *fp)
150 {
151 char buf[4096];
152 struct ifstat_ent *db = NULL;
153 struct ifstat_ent *n;
154
155 while (fgets(buf, sizeof(buf), fp) != NULL) {
156 char *p;
157 char *next;
158 int i;
159
160 if (buf[0] == '#') {
161 buf[strlen(buf)-1] = 0;
162 if (info_source[0] && strcmp(info_source, buf+1))
163 source_mismatch = 1;
164 strncpy(info_source, buf+1, sizeof(info_source)-1);
165 continue;
166 }
167 if ((n = malloc(sizeof(*n))) == NULL)
168 abort();
169
170 if (!(p = strchr(buf, ' ')))
171 abort();
172 *p++ = 0;
173
174 if (sscanf(buf, "%d", &n->ifindex) != 1)
175 abort();
176 if (!(next = strchr(p, ' ')))
177 abort();
178 *next++ = 0;
179
180 n->name = strdup(p);
181 p = next;
182
183 for (i=0; i<MAXS; i++) {
184 unsigned rate;
185 if (!(next = strchr(p, ' ')))
186 abort();
187 *next++ = 0;
188 if (sscanf(p, "%llu", n->val+i) != 1)
189 abort();
190 n->ival[i] = (__u32)n->val[i];
191 p = next;
192 if (!(next = strchr(p, ' ')))
193 abort();
194 *next++ = 0;
195 if (sscanf(p, "%u", &rate) != 1)
196 abort();
197 n->rate[i] = rate;
198 p = next;
199 }
200 n->next = db;
201 db = n;
202 }
203
204 while (db) {
205 n = db;
206 db = db->next;
207 n->next = kern_db;
208 kern_db = n;
209 }
210 }
211
212 static void dump_raw_db(FILE *fp, int to_hist)
213 {
214 struct ifstat_ent *n, *h;
215 h = hist_db;
216 fprintf(fp, "#%s\n", info_source);
217
218 for (n=kern_db; n; n=n->next) {
219 int i;
220 unsigned long long *vals = n->val;
221 double *rates = n->rate;
222 if (!match(n->name)) {
223 struct ifstat_ent *h1;
224 if (!to_hist)
225 continue;
226 for (h1 = h; h1; h1 = h1->next) {
227 if (h1->ifindex == n->ifindex) {
228 vals = h1->val;
229 rates = h1->rate;
230 h = h1->next;
231 break;
232 }
233 }
234 }
235 fprintf(fp, "%d %s ", n->ifindex, n->name);
236 for (i=0; i<MAXS; i++)
237 fprintf(fp, "%llu %u ", vals[i], (unsigned)rates[i]);
238 fprintf(fp, "\n");
239 }
240 }
241
242 /* use communication definitions of meg/kilo etc */
243 static const unsigned long long giga = 1000000000ull;
244 static const unsigned long long mega = 1000000;
245 static const unsigned long long kilo = 1000;
246
247 static void format_rate(FILE *fp, unsigned long long *vals,
248 double *rates, int i)
249 {
250 char temp[64];
251 if (vals[i] > giga)
252 fprintf(fp, "%7lluM ", vals[i]/mega);
253 else if (vals[i] > mega)
254 fprintf(fp, "%7lluK ", vals[i]/kilo);
255 else
256 fprintf(fp, "%8llu ", vals[i]);
257
258 if (rates[i] > mega) {
259 sprintf(temp, "%uM", (unsigned)(rates[i]/mega));
260 fprintf(fp, "%-6s ", temp);
261 } else if (rates[i] > kilo) {
262 sprintf(temp, "%uK", (unsigned)(rates[i]/kilo));
263 fprintf(fp, "%-6s ", temp);
264 } else
265 fprintf(fp, "%-6u ", (unsigned)rates[i]);
266 }
267
268 static void format_pair(FILE *fp, unsigned long long *vals, int i, int k)
269 {
270 char temp[64];
271 if (vals[i] > giga)
272 fprintf(fp, "%7lluM ", vals[i]/mega);
273 else if (vals[i] > mega)
274 fprintf(fp, "%7lluK ", vals[i]/kilo);
275 else
276 fprintf(fp, "%8llu ", vals[i]);
277
278 if (vals[k] > giga) {
279 sprintf(temp, "%uM", (unsigned)(vals[k]/mega));
280 fprintf(fp, "%-6s ", temp);
281 } else if (vals[k] > mega) {
282 sprintf(temp, "%uK", (unsigned)(vals[k]/kilo));
283 fprintf(fp, "%-6s ", temp);
284 } else
285 fprintf(fp, "%-6u ", (unsigned)vals[k]);
286 }
287
288 static void print_head(FILE *fp)
289 {
290 fprintf(fp, "#%s\n", info_source);
291 fprintf(fp, "%-15s ", "Interface");
292
293 fprintf(fp, "%8s/%-6s ", "RX Pkts", "Rate");
294 fprintf(fp, "%8s/%-6s ", "TX Pkts", "Rate");
295 fprintf(fp, "%8s/%-6s ", "RX Data", "Rate");
296 fprintf(fp, "%8s/%-6s\n","TX Data", "Rate");
297
298 if (!show_errors) {
299 fprintf(fp, "%-15s ", "");
300 fprintf(fp, "%8s/%-6s ", "RX Errs", "Drop");
301 fprintf(fp, "%8s/%-6s ", "TX Errs", "Drop");
302 fprintf(fp, "%8s/%-6s ", "RX Over", "Rate");
303 fprintf(fp, "%8s/%-6s\n","TX Coll", "Rate");
304 } else {
305 fprintf(fp, "%-15s ", "");
306 fprintf(fp, "%8s/%-6s ", "RX Errs", "Rate");
307 fprintf(fp, "%8s/%-6s ", "RX Drop", "Rate");
308 fprintf(fp, "%8s/%-6s ", "RX Over", "Rate");
309 fprintf(fp, "%8s/%-6s\n","RX Leng", "Rate");
310
311 fprintf(fp, "%-15s ", "");
312 fprintf(fp, "%8s/%-6s ", "RX Crc", "Rate");
313 fprintf(fp, "%8s/%-6s ", "RX Frm", "Rate");
314 fprintf(fp, "%8s/%-6s ", "RX Fifo", "Rate");
315 fprintf(fp, "%8s/%-6s\n","RX Miss", "Rate");
316
317 fprintf(fp, "%-15s ", "");
318 fprintf(fp, "%8s/%-6s ", "TX Errs", "Rate");
319 fprintf(fp, "%8s/%-6s ", "TX Drop", "Rate");
320 fprintf(fp, "%8s/%-6s ", "TX Coll", "Rate");
321 fprintf(fp, "%8s/%-6s\n","TX Carr", "Rate");
322
323 fprintf(fp, "%-15s ", "");
324 fprintf(fp, "%8s/%-6s ", "TX Abrt", "Rate");
325 fprintf(fp, "%8s/%-6s ", "TX Fifo", "Rate");
326 fprintf(fp, "%8s/%-6s ", "TX Hear", "Rate");
327 fprintf(fp, "%8s/%-6s\n","TX Wind", "Rate");
328 }
329 }
330
331 static void print_one_if(FILE *fp, struct ifstat_ent *n,
332 unsigned long long *vals)
333 {
334 int i;
335 fprintf(fp, "%-15s ", n->name);
336 for (i=0; i<4; i++)
337 format_rate(fp, vals, n->rate, i);
338 fprintf(fp, "\n");
339
340 if (!show_errors) {
341 fprintf(fp, "%-15s ", "");
342 format_pair(fp, vals, 4, 6);
343 format_pair(fp, vals, 5, 7);
344 format_rate(fp, vals, n->rate, 11);
345 format_rate(fp, vals, n->rate, 9);
346 fprintf(fp, "\n");
347 } else {
348 fprintf(fp, "%-15s ", "");
349 format_rate(fp, vals, n->rate, 4);
350 format_rate(fp, vals, n->rate, 6);
351 format_rate(fp, vals, n->rate, 11);
352 format_rate(fp, vals, n->rate, 10);
353 fprintf(fp, "\n");
354
355 fprintf(fp, "%-15s ", "");
356 format_rate(fp, vals, n->rate, 12);
357 format_rate(fp, vals, n->rate, 13);
358 format_rate(fp, vals, n->rate, 14);
359 format_rate(fp, vals, n->rate, 15);
360 fprintf(fp, "\n");
361
362 fprintf(fp, "%-15s ", "");
363 format_rate(fp, vals, n->rate, 5);
364 format_rate(fp, vals, n->rate, 7);
365 format_rate(fp, vals, n->rate, 9);
366 format_rate(fp, vals, n->rate, 17);
367 fprintf(fp, "\n");
368
369 fprintf(fp, "%-15s ", "");
370 format_rate(fp, vals, n->rate, 16);
371 format_rate(fp, vals, n->rate, 18);
372 format_rate(fp, vals, n->rate, 19);
373 format_rate(fp, vals, n->rate, 20);
374 fprintf(fp, "\n");
375 }
376 }
377
378
379 static void dump_kern_db(FILE *fp)
380 {
381 struct ifstat_ent *n;
382
383 print_head(fp);
384
385 for (n=kern_db; n; n=n->next) {
386 if (!match(n->name))
387 continue;
388 print_one_if(fp, n, n->val);
389 }
390 }
391
392
393 static void dump_incr_db(FILE *fp)
394 {
395 struct ifstat_ent *n, *h;
396 h = hist_db;
397
398 print_head(fp);
399
400 for (n=kern_db; n; n=n->next) {
401 int i;
402 unsigned long long vals[MAXS];
403 struct ifstat_ent *h1;
404
405 memcpy(vals, n->val, sizeof(vals));
406
407 for (h1 = h; h1; h1 = h1->next) {
408 if (h1->ifindex == n->ifindex) {
409 for (i = 0; i < MAXS; i++)
410 vals[i] -= h1->val[i];
411 h = h1->next;
412 break;
413 }
414 }
415 if (!match(n->name))
416 continue;
417 print_one_if(fp, n, vals);
418 }
419 }
420
421
422 static int children;
423
424 static void sigchild(int signo)
425 {
426 }
427
428 static void update_db(int interval)
429 {
430 struct ifstat_ent *n, *h;
431
432 n = kern_db;
433 kern_db = NULL;
434
435 load_info();
436
437 h = kern_db;
438 kern_db = n;
439
440 for (n = kern_db; n; n = n->next) {
441 struct ifstat_ent *h1;
442 for (h1 = h; h1; h1 = h1->next) {
443 if (h1->ifindex == n->ifindex) {
444 int i;
445 for (i = 0; i < MAXS; i++) {
446 if ((long)(h1->ival[i] - n->ival[i]) < 0) {
447 memset(n->ival, 0, sizeof(n->ival));
448 break;
449 }
450 }
451 for (i = 0; i < MAXS; i++) {
452 double sample;
453 unsigned long incr = h1->ival[i] - n->ival[i];
454 n->val[i] += incr;
455 n->ival[i] = h1->ival[i];
456 sample = (double)(incr*1000)/interval;
457 if (interval >= scan_interval) {
458 n->rate[i] += W*(sample-n->rate[i]);
459 } else if (interval >= 1000) {
460 if (interval >= time_constant) {
461 n->rate[i] = sample;
462 } else {
463 double w = W*(double)interval/scan_interval;
464 n->rate[i] += w*(sample-n->rate[i]);
465 }
466 }
467 }
468
469 while (h != h1) {
470 struct ifstat_ent *tmp = h;
471 h = h->next;
472 free(tmp->name);
473 free(tmp);
474 };
475 h = h1->next;
476 free(h1->name);
477 free(h1);
478 break;
479 }
480 }
481 }
482 }
483
484 #define T_DIFF(a,b) (((a).tv_sec-(b).tv_sec)*1000 + ((a).tv_usec-(b).tv_usec)/1000)
485
486
487 static void server_loop(int fd)
488 {
489 struct timeval snaptime = { 0 };
490 struct pollfd p;
491 p.fd = fd;
492 p.events = p.revents = POLLIN;
493
494 sprintf(info_source, "%d.%lu sampling_interval=%d time_const=%d",
495 getpid(), (unsigned long)random(), scan_interval/1000, time_constant/1000);
496
497 load_info();
498
499 for (;;) {
500 int status;
501 int tdiff;
502 struct timeval now;
503
504 gettimeofday(&now, NULL);
505 tdiff = T_DIFF(now, snaptime);
506 if (tdiff >= scan_interval) {
507 update_db(tdiff);
508 snaptime = now;
509 tdiff = 0;
510 }
511
512 if (poll(&p, 1, tdiff + scan_interval) > 0
513 && (p.revents&POLLIN)) {
514 int clnt = accept(fd, NULL, NULL);
515 if (clnt >= 0) {
516 pid_t pid;
517 if (children >= 5) {
518 close(clnt);
519 } else if ((pid = fork()) != 0) {
520 if (pid>0)
521 children++;
522 close(clnt);
523 } else {
524 FILE *fp = fdopen(clnt, "w");
525 if (fp) {
526 if (tdiff > 0)
527 update_db(tdiff);
528 dump_raw_db(fp, 0);
529 }
530 exit(0);
531 }
532 }
533 }
534 while (children && waitpid(-1, &status, WNOHANG) > 0)
535 children--;
536 }
537 }
538
539 static int verify_forging(int fd)
540 {
541 struct ucred cred;
542 socklen_t olen = sizeof(cred);
543
544 if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, (void*)&cred, &olen) ||
545 olen < sizeof(cred))
546 return -1;
547 if (cred.uid == getuid() || cred.uid == 0)
548 return 0;
549 return -1;
550 }
551
552 static void usage(void) __attribute__((noreturn));
553
554 static void usage(void)
555 {
556 fprintf(stderr,
557 "Usage: ifstat [OPTION] [ PATTERN [ PATTERN ] ]\n"
558 " -h, --help this message\n"
559 " -a, --ignore ignore history\n"
560 " -d, --scan=SECS sample every statistics every SECS\n"
561 " -e, --errors show errors\n"
562 " -n, --nooutput do history only\n"
563 " -r, --reset reset history\n"
564 " -s, --noupdate don;t update history\n"
565 " -t, --interval=SECS report average over the last SECS\n"
566 " -V, --version output version information\n"
567 " -z, --zeros show entries with zero activity\n");
568
569 exit(-1);
570 }
571
572 static const struct option longopts[] = {
573 { "help", 0, 0, 'h' },
574 { "ignore", 0, 0, 'a' },
575 { "scan", 1, 0, 'd'},
576 { "errors", 0, 0, 'e' },
577 { "nooutput", 0, 0, 'n' },
578 { "reset", 0, 0, 'r' },
579 { "noupdate", 0, 0, 's' },
580 { "interval", 1, 0, 't' },
581 { "version", 0, 0, 'V' },
582 { "zeros", 0, 0, 'z' },
583 { 0 }
584 };
585
586 int main(int argc, char *argv[])
587 {
588 char hist_name[128];
589 struct sockaddr_un sun;
590 FILE *hist_fp = NULL;
591 int ch;
592 int fd;
593
594 while ((ch = getopt_long(argc, argv, "hvVzrnasd:t:eK",
595 longopts, NULL)) != EOF) {
596 switch(ch) {
597 case 'z':
598 dump_zeros = 1;
599 break;
600 case 'r':
601 reset_history = 1;
602 break;
603 case 'a':
604 ignore_history = 1;
605 break;
606 case 's':
607 no_update = 1;
608 break;
609 case 'n':
610 no_output = 1;
611 break;
612 case 'e':
613 show_errors = 1;
614 break;
615 case 'd':
616 scan_interval = atoi(optarg) * 1000;
617 if (scan_interval <= 0) {
618 fprintf(stderr, "ifstat: invalid scan interval\n");
619 exit(-1);
620 }
621 break;
622 case 't':
623 time_constant = atoi(optarg);
624 if (time_constant <= 0) {
625 fprintf(stderr, "ifstat: invalid time constant divisor\n");
626 exit(-1);
627 }
628 break;
629 case 'v':
630 case 'V':
631 printf("ifstat utility, iproute2-ss%s\n", SNAPSHOT);
632 exit(0);
633 case 'h':
634 case '?':
635 default:
636 usage();
637 }
638 }
639
640 argc -= optind;
641 argv += optind;
642
643 sun.sun_family = AF_UNIX;
644 sun.sun_path[0] = 0;
645 sprintf(sun.sun_path+1, "ifstat%d", getuid());
646
647 if (scan_interval > 0) {
648 if (time_constant == 0)
649 time_constant = 60;
650 time_constant *= 1000;
651 W = 1 - 1/exp(log(10)*(double)scan_interval/time_constant);
652 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
653 perror("ifstat: socket");
654 exit(-1);
655 }
656 if (bind(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) < 0) {
657 perror("ifstat: bind");
658 exit(-1);
659 }
660 if (listen(fd, 5) < 0) {
661 perror("ifstat: listen");
662 exit(-1);
663 }
664 if (daemon(0, 0)) {
665 perror("ifstat: daemon");
666 exit(-1);
667 }
668 signal(SIGPIPE, SIG_IGN);
669 signal(SIGCHLD, sigchild);
670 server_loop(fd);
671 exit(0);
672 }
673
674 patterns = argv;
675 npatterns = argc;
676
677 if (getenv("IFSTAT_HISTORY"))
678 snprintf(hist_name, sizeof(hist_name),
679 "%s", getenv("IFSTAT_HISTORY"));
680 else
681 snprintf(hist_name, sizeof(hist_name),
682 "%s/.ifstat.u%d", P_tmpdir, getuid());
683
684 if (reset_history)
685 unlink(hist_name);
686
687 if (!ignore_history || !no_update) {
688 struct stat stb;
689
690 fd = open(hist_name, O_RDWR|O_CREAT|O_NOFOLLOW, 0600);
691 if (fd < 0) {
692 perror("ifstat: open history file");
693 exit(-1);
694 }
695 if ((hist_fp = fdopen(fd, "r+")) == NULL) {
696 perror("ifstat: fdopen history file");
697 exit(-1);
698 }
699 if (flock(fileno(hist_fp), LOCK_EX)) {
700 perror("ifstat: flock history file");
701 exit(-1);
702 }
703 if (fstat(fileno(hist_fp), &stb) != 0) {
704 perror("ifstat: fstat history file");
705 exit(-1);
706 }
707 if (stb.st_nlink != 1 || stb.st_uid != getuid()) {
708 fprintf(stderr, "ifstat: something is so wrong with history file, that I prefer not to proceed.\n");
709 exit(-1);
710 }
711 if (!ignore_history) {
712 FILE *tfp;
713 long uptime = -1;
714 if ((tfp = fopen("/proc/uptime", "r")) != NULL) {
715 if (fscanf(tfp, "%ld", &uptime) != 1)
716 uptime = -1;
717 fclose(tfp);
718 }
719 if (uptime >= 0 && time(NULL) >= stb.st_mtime+uptime) {
720 fprintf(stderr, "ifstat: history is aged out, resetting\n");
721 ftruncate(fileno(hist_fp), 0);
722 }
723 }
724
725 load_raw_table(hist_fp);
726
727 hist_db = kern_db;
728 kern_db = NULL;
729 }
730
731 if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) >= 0 &&
732 (connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0
733 || (strcpy(sun.sun_path+1, "ifstat0"),
734 connect(fd, (struct sockaddr*)&sun, 2+1+strlen(sun.sun_path+1)) == 0))
735 && verify_forging(fd) == 0) {
736 FILE *sfp = fdopen(fd, "r");
737 load_raw_table(sfp);
738 if (hist_db && source_mismatch) {
739 fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
740 hist_db = NULL;
741 }
742 fclose(sfp);
743 } else {
744 if (fd >= 0)
745 close(fd);
746 if (hist_db && info_source[0] && strcmp(info_source, "kernel")) {
747 fprintf(stderr, "ifstat: history is stale, ignoring it.\n");
748 hist_db = NULL;
749 info_source[0] = 0;
750 }
751 load_info();
752 if (info_source[0] == 0)
753 strcpy(info_source, "kernel");
754 }
755
756 if (!no_output) {
757 if (ignore_history || hist_db == NULL)
758 dump_kern_db(stdout);
759 else
760 dump_incr_db(stdout);
761 }
762 if (!no_update) {
763 ftruncate(fileno(hist_fp), 0);
764 rewind(hist_fp);
765 dump_raw_db(hist_fp, 1);
766 fflush(hist_fp);
767 }
768 exit(0);
769 }