X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_create.c;h=707e6013756851e65e8f18b7bef9237303cf838c;hp=a1b4e5a4efc4bec8ee77dc1ad3b037c41076056a;hb=96b0f4aace0deef034a792a08dc2d426cd2b61a4;hpb=8f9c2c2b3c3f8a65e24dd9d8d612eafe48ccfb2e diff --git a/src/rrd_create.c b/src/rrd_create.c index a1b4e5a..707e601 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.4.2 Copyright by Tobi Oetiker, 1997-2009 + * RRDtool 1.4.3 Copyright by Tobi Oetiker, 1997-2010 ***************************************************************************** * rrd_create.c creates new rrds *****************************************************************************/ @@ -11,6 +11,7 @@ #include "rrd_tool.h" #include "rrd_rpncalc.h" #include "rrd_hw.h" +#include "rrd_client.h" #include "rrd_is_thread_safe.h" static int opt_no_overwrite = 0; @@ -33,6 +34,12 @@ void parseGENERIC_DS( static void rrd_free2( rrd_t *rrd); /* our onwn copy, immmune to mmap */ +void rrd_create_set_no_overwrite( + int opt ) +{ + opt_no_overwrite = (opt?1:0); +} + int rrd_create( int argc, char **argv) @@ -40,6 +47,7 @@ int rrd_create( struct option long_options[] = { {"start", required_argument, 0, 'b'}, {"step", required_argument, 0, 's'}, + {"daemon", required_argument, 0, 'd'}, {"no-overwrite", no_argument, 0, 'O'}, {0, 0, 0, 0} }; @@ -51,17 +59,29 @@ int rrd_create( char *parsetime_error = NULL; long long_tmp; int rc; + char * opt_daemon = NULL; optind = 0; opterr = 0; /* initialize getopt */ while (1) { - opt = getopt_long(argc, argv, "Ob:s:", long_options, &option_index); + opt = getopt_long(argc, argv, "Ob:s:d:", long_options, &option_index); if (opt == EOF) break; switch (opt) { + case 'd': + if (opt_daemon != NULL) + free (opt_daemon); + opt_daemon = strdup (optarg); + if (opt_daemon == NULL) + { + rrd_set_error ("strdup failed."); + return (-1); + } + break; + case 'b': if ((parsetime_error = rrd_parsetime(optarg, &last_up_tv))) { rrd_set_error("start time: %s", parsetime_error); @@ -108,9 +128,17 @@ int rrd_create( rrd_set_error("need name of an rrd file to create"); return -1; } + + rrdc_connect (opt_daemon); + if (rrdc_is_connected (opt_daemon)) { + rc = rrdc_create (argv[optind], + pdp_step, last_up, opt_no_overwrite, + argc - optind - 1, (const char **) (argv + optind + 1)); + } else { rc = rrd_create_r(argv[optind], pdp_step, last_up, argc - optind - 1, (const char **) (argv + optind + 1)); + } return rc; } @@ -131,6 +159,9 @@ int rrd_create_r( unsigned short token_idx, error_flag, period = 0; unsigned long hashed_name; + /* clear any previous errors */ + rrd_clear_error(); + /* init rrd clean */ rrd_init(&rrd); /* static header */ @@ -189,11 +220,11 @@ int rrd_create_r( dummychar2, &offset)) { case 0: case 1: - rrd_set_error("Invalid DS name"); + rrd_set_error("Invalid DS name in [%s]",&argv[i][3]); break; case 2: case 3: - rrd_set_error("Invalid DS type"); + rrd_set_error("Invalid DS type in [%s]",&argv[i][3]); break; case 4: /* (%n may or may not be counted) */ case 5: /* check for duplicate datasource names */ @@ -571,7 +602,8 @@ void parseGENERIC_DS( &(rrd -> ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt), minstr,maxstr); */ - old_locale = setlocale(LC_NUMERIC, "C"); + old_locale = setlocale(LC_NUMERIC, NULL); + setlocale(LC_NUMERIC, "C"); if (sscanf(def, "%lu:%18[^:]:%18[^:]", &(rrd->ds_def[ds_idx].par[DS_mrhb_cnt].u_cnt), minstr, maxstr) == 3) {