]> git.itanic.dy.fi Git - rrdd/commitdiff
Enable database reading and writing, if requested from command line
authorTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 20 Jun 2012 19:59:27 +0000 (22:59 +0300)
committerTimo Kokkonen <timo.t.kokkonen@iki.fi>
Wed, 20 Jun 2012 19:59:27 +0000 (22:59 +0300)
If no command line arguments are given, continue using the old built
in database config. But if appropriate config is given as a command
line argument, read the entries from the file. If the user does not
have a database config file to get started with, make it possible for
the default database to be created as a starting point.

Signed-off-by: Timo Kokkonen <timo.t.kokkonen@iki.fi>
Makefile
main.c

index 6339d687bb4d7bae0dbd6ed56c22881a0b552ba2..6da318051baf212cf7fa11581fd29614518db22f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -3,7 +3,7 @@ LD=ld
 CFLAGS=-Wall -O2 -g
 
 RRDD_OBJS= main.o process.o rrdtool.o parser.o scheduler.o string.o \
-               debug.o
+               debug.o config.o
 
 ALL_OBJS = $(RRDD_OBJS)
 ALL_DEBS = $(patsubst %.o,.%.o.d,$(ALL_OBJS))
@@ -21,7 +21,7 @@ endif
 all: rrdd
 
 rrdd: $(RRDD_OBJS)
-       $(QUIET_LINK)$(CC) -o rrdd $(RRDD_OBJS)
+       $(QUIET_LINK)$(CC) -o rrdd $(RRDD_OBJS) -lconfig
 
 clean:
        rm -vf rrdd *~ *.o .*.d
diff --git a/main.c b/main.c
index c7f6f044b423b3ec5642cf58af70062c2bc3e51a..f371ff2ab61f66be2a227b8426335772a9308dae 100644 (file)
--- a/main.c
+++ b/main.c
@@ -9,19 +9,24 @@
 #include "debug.h"
 
 #include "database.h"
+#include "config.h"
 
 struct user_options {
        int max_jobs;
+       char *config_file;
+       int dump_defaults;
 };
 
 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, },
+               { .val = 'j', .has_arg = 1, .name = "jobs", },
+               { .val = 'c', .has_arg = 1, .name = "config", },
+               { .val = 'd', .has_arg = 1, .name = "dump-default", },
                { },
        };
-       char short_options[] = "j:";
+       char short_options[] = "j:c:d:";
 
        while (1) {
                c = getopt_long(argc, argv, short_options, long_options,
@@ -35,6 +40,15 @@ int read_args(int argc, char *argv[], struct user_options *opts)
                        opts->max_jobs = atoi(optarg);
                        break;
 
+               case 'c':
+                       opts->config_file = optarg;
+                       break;
+
+               case 'd':
+                       opts->dump_defaults = 1;
+                       opts->config_file = optarg;
+                       break;
+
                case '?':
                        return -1;
                }
@@ -47,12 +61,26 @@ int main(int argc, char *argv[])
        struct user_options opts;
        struct rrd_database *db, **db_list = NULL;
        int sleeptime;
+       int ret = 0;
 
        bzero(&opts, sizeof(opts));
 
        if (read_args(argc, argv, &opts) < 0)
                return -1;
 
+       if (opts.dump_defaults) {
+               ret = write_database(opts.config_file, default_rrds);
+               return 0;
+       }
+
+       if (opts.config_file)
+               db_list = populate_database(opts.config_file);
+       else
+               db_list = default_rrds;
+
+       if (ret || !db_list)
+               return 1;
+
        if (rrdtool_create_missing_databases(db_list))
                return 1;