]> git.itanic.dy.fi Git - rrdd/blob - main.c
main: Add NULL terminator to option array
[rrdd] / main.c
1 #include <sys/types.h>
2 #include <unistd.h>
3 #include <getopt.h>
4
5 #include "process.h"
6 #include "rrdtool.h"
7 #include "parser.h"
8 #include "scheduler.h"
9 #include "debug.h"
10
11 #include "database.h"
12
13 struct user_options {
14         int max_jobs;
15 };
16
17 int read_args(int argc, char *argv[], struct user_options *opts)
18 {
19         int option_index = 0, c;
20         static struct option long_options[] = {
21                 { .val = 'j', .name = "jobs", .has_arg = 1, },
22                 { },
23         };
24         char short_options[] = "j:";
25
26         while (1) {
27                 c = getopt_long(argc, argv, short_options, long_options,
28                                 &option_index);
29
30                 if (c == -1)
31                         break;
32
33                 switch (c) {
34                 case 'j':
35                         opts->max_jobs = atoi(optarg);
36                         break;
37
38                 case '?':
39                         return -1;
40                 }
41         }
42         return 0;
43 }
44
45 int main(int argc, char *argv[])
46 {
47         struct user_options opts;
48         struct rrd_database *db;
49         int sleeptime;
50
51         bzero(&opts, sizeof(opts));
52
53         if (read_args(argc, argv, &opts) < 0)
54                 return -1;
55
56         rrdtool_create_missing_databases(all_rrds);
57
58         if (init_jobcontrol(opts.max_jobs))
59                 return -1;
60
61         while (1) {
62                 pr_info("loop start\n");
63                 /*
64                  * Update all databases parallel in one shot
65                  */
66                 while ((db = get_outdated_db((struct rrd_database **)
67                                                &all_rrds)))
68                         rrdtool_update_data(db);
69
70                 sleeptime = get_next_update((struct rrd_database **)&all_rrds);
71
72                 pr_info("Time to sleep %d seconds\n", sleeptime);
73                 poll_job_requests(sleeptime);
74         }
75         return 0;
76 }