#include #include #include #include "process.h" #include "rrdtool.h" #include "parser.h" #include "scheduler.h" #include "debug.h" #include "database.h" struct user_options { int max_jobs; }; int read_args(int argc, char *argv[], struct user_options *opts) { int option_index = 0, c; static struct option long_options[] = { { .val = 'j', .name = "jobs", .has_arg = 1, }, }; char short_options[] = "j:"; while (1) { c = getopt_long(argc, argv, short_options, long_options, &option_index); if (c == -1) break; switch (c) { case 'j': opts->max_jobs = atoi(optarg); break; case '?': return -1; } } return 0; } int main(int argc, char *argv[]) { struct user_options opts; struct rrd_database *db; int sleeptime; bzero(&opts, sizeof(opts)); if (read_args(argc, argv, &opts) < 0) return -1; rrdtool_create_missing_databases(all_rrds); if (init_jobcontrol(opts.max_jobs)) return -1; while (1) { pr_info("loop start\n"); /* * Update all databases parallel in one shot */ while ((db = get_outdated_db((struct rrd_database **) &all_rrds))) rrdtool_update_data(db); sleeptime = get_next_update((struct rrd_database **)&all_rrds); pr_info("Time to sleep %d seconds\n", sleeptime); poll_job_requests(sleeptime); } return 0; }