Fixed daemonization bugs.
[public/mirror.git] / rrdtool / mirror-rrd.c
1 #include "mirror-nl-glue.h"
2 #include <rrd.h>
3
4 int main(void) {
5         char *argv[3];
6         unsigned long packet_count;
7
8         switch(fork()) {
9                 case -1:
10                         return -1;
11                 case 0:
12                         close(0);
13                         close(1);
14                         setsid();
15                         break;
16                 default:
17                         _exit(0);
18         }       
19
20     mirror_stats_initialize();
21     argv[0] = malloc(1024);     
22     for (;;) {
23         packet_count = get_class_byte_count(&cogent_class);
24         snprintf(argv[0], 1024, "N:%lu", packet_count);
25         rrd_update_r("/var/rrdtool/cogent.rrd", NULL, 1, argv);
26         packet_count = get_class_byte_count(&orion_class);
27         snprintf(argv[0], 1024, "N:%lu", packet_count);
28         rrd_update_r("/var/rrdtool/orion.rrd", NULL, 1, argv);
29         packet_count = get_class_byte_count(&campus_class);
30         snprintf(argv[0], 1024, "N:%lu", packet_count);
31         rrd_update_r("/var/rrdtool/campus.rrd", NULL, 1, argv);
32         if (rrd_test_error()) {
33                 fprintf(stderr, "ERROR: %s\n", rrd_get_error());
34                 rrd_clear_error();
35         }
36         sleep(5);
37         mirror_stats_refresh();
38     }
39 }
40