X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_create.c;h=f221c99d535491fa511bbfa0eae2b55b13834aff;hp=2a0a143c9281c2e5e7edfa08a8be2a5acb8f0132;hb=bb124879717bdb65640cd50ce99e3569cb0a9a3f;hpb=19f031713115921bebf5949ce63926d66dd8c6a5 diff --git a/src/rrd_create.c b/src/rrd_create.c index 2a0a143..f221c99 100644 --- a/src/rrd_create.c +++ b/src/rrd_create.c @@ -11,9 +11,9 @@ #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; #ifdef WIN32 # include @@ -40,6 +40,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 +52,30 @@ int rrd_create( char *parsetime_error = NULL; long long_tmp; int rc; + char * opt_daemon = NULL; + int opt_no_overwrite = 0; 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,14 +122,24 @@ int rrd_create( rrd_set_error("need name of an rrd file to create"); return -1; } - rc = rrd_create_r(argv[optind], - pdp_step, last_up, + + 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_r2(argv[optind], + pdp_step, last_up, opt_no_overwrite, argc - optind - 1, (const char **) (argv + optind + 1)); + } return rc; } /* #define DEBUG */ +/* For backwards compatibility with previous API. Use rrd_create_r2 if you + need to have the no_overwrite parameter. */ int rrd_create_r( const char *filename, unsigned long pdp_step, @@ -123,6 +147,16 @@ int rrd_create_r( int argc, const char **argv) { + return rrd_create_r2(filename,pdp_step,last_up,0,argc,argv); +} +int rrd_create_r2( + const char *filename, + unsigned long pdp_step, + time_t last_up, + int no_overwrite, + int argc, + const char **argv) +{ rrd_t rrd; long i; int offset; @@ -131,6 +165,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 +226,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 */ @@ -553,7 +590,7 @@ int rrd_create_r( rrd_free2(&rrd); return (-1); } - return rrd_create_fn(filename, &rrd); + return rrd_create_fn(filename, &rrd, no_overwrite); } void parseGENERIC_DS( @@ -571,7 +608,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) { @@ -676,7 +714,8 @@ int create_hw_contingent_rras( int rrd_create_fn( const char *file_name, - rrd_t *rrd) + rrd_t *rrd, + int no_overwrite ) { unsigned long i, ii; rrd_value_t *unknown; @@ -685,7 +724,7 @@ int rrd_create_fn( rrd_t rrd_dn; unsigned rrd_flags = RRD_READWRITE | RRD_CREAT; - if (opt_no_overwrite) { + if (no_overwrite) { rrd_flags |= RRD_EXCL ; }