13 #include "built_in_parsers.h"
15 #include "plugin_manager.h"
22 int read_args(int argc, char *argv[], struct user_options *opts)
24 int option_index = 0, c;
25 static struct option long_options[] = {
26 { .val = 'j', .has_arg = 1, .name = "jobs", },
27 { .val = 'c', .has_arg = 1, .name = "config", },
28 { .val = 'l', .has_arg = 1, .name = "log-file", },
31 char short_options[] = "j:c:l:";
34 c = getopt_long(argc, argv, short_options, long_options,
42 opts->max_jobs = atoi(optarg);
46 opts->config_file = optarg;
50 open_log_file(optarg);
58 while (optind < argc) {
59 opts->config_file = argv[optind];
66 int main(int argc, char *argv[])
68 struct user_options opts;
69 struct rrd_database *db, **db_list = NULL;
73 pr_info("%s Version %s starting\n", argv[0], RRDD_VERSION);
75 bzero(&opts, sizeof(opts));
77 if (read_args(argc, argv, &opts) < 0)
80 init_plugin_manager(argv[0]);
81 register_built_in_parsers();
83 if (!opts.config_file) {
84 pr_err("No database config file given. Nothing to do\n");
88 db_list = populate_database(opts.config_file);
93 if (rrdtool_create_missing_databases(db_list))
96 if (init_jobcontrol(opts.max_jobs))
104 pr_info("loop start\n");
106 * Update all databases parallel in one shot
108 while ((db = get_outdated_db(db_list)))
109 rrdtool_update_data(db);
111 sleeptime = get_next_update(db_list, &db_name);
113 t = time(0) + sleeptime;
114 strftime(timestr, sizeof(timestr), "%T", localtime(&t));
115 pr_info("Next scheduled event \"%s\" at %s, in %d seconds\n",
116 db_name, timestr, sleeptime);
118 poll_job_requests(sleeptime);