X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Frrd_tool.c;h=4da8019e36daddccd16714b64e32460530bd3d1c;hb=672a5d8877e055d90272210497302afb26e28c8f;hp=088c1955e21c2771d937558585cff6331626386a;hpb=3c268443bb768669f3bd095b9e95a9a5ab4c5ef2;p=rrdtool.git diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 088c195..4da8019 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3rc6 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.3.2 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_tool.c Startup wrapper *****************************************************************************/ @@ -55,7 +55,7 @@ void PrintUsage( N_ ("Valid commands: create, update, updatev, graph, graphv, dump, restore,\n" "\t\tlast, lastupdate, first, info, fetch, tune,\n" - "\t\tresize, xport\n\n"); + "\t\tresize, xport, flush\n\n"); const char *help_listremote = N_("Valid remote commands: quit, ls, cd, mkdir, pwd\n\n"); @@ -95,7 +95,8 @@ void PrintUsage( const char *help_update = N_("* update - update an RRD\n\n" "\trrdtool update filename\n" - "\t\t--template|-t ds-name:ds-name:...\n" + "\t\t[--template|-t ds-name:ds-name:...]\n" + "\t\t[--daemon
]\n" "\t\ttime|N:value[:value...]\n\n" "\t\tat-time@value[:value...]\n\n" "\t\t[ time:value[:value...] ..]\n\n"); @@ -104,7 +105,7 @@ void PrintUsage( N_("* updatev - a verbose version of update\n" "\treturns information about values, RRAs, and datasources updated\n\n" "\trrdtool updatev filename\n" - "\t\t--template|-t ds-name:ds-name:...\n" + "\t\t[--template|-t ds-name:ds-name:...]\n" "\t\ttime|N:value[:value...]\n\n" "\t\tat-time@value[:value...]\n\n" "\t\t[ time:value[:value...] ..]\n\n"); @@ -113,7 +114,13 @@ void PrintUsage( N_("* fetch - fetch data out of an RRD\n\n" "\trrdtool fetch filename.rrd CF\n" "\t\t[-r|--resolution resolution]\n" - "\t\t[-s|--start start] [-e|--end end]\n\n"); + "\t\t[-s|--start start] [-e|--end end]\n" + "\t\t[--daemon ]\n\n"); + + const char *help_flush = + N_("* flush - flush cached data out to an RRD file\n\n" + "\trrdtool flush filename.rrd\n" + "\t\t[--daemon ]\n\n"); /* break up very large strings (help_graph, help_tune) for ISO C89 compliance*/ @@ -126,13 +133,13 @@ void PrintUsage( "\trrdtool graphv filename [-s|--start seconds] [-e|--end seconds]\n"); const char *help_graph1 = N_("\t\t[-x|--x-grid x-axis grid and label]\n" - "\t\t[-Y|--alt-y-grid]\n" + "\t\t[-Y|--alt-y-grid] [--full-size-mode]\n" "\t\t[-y|--y-grid y-axis grid and label]\n" "\t\t[-v|--vertical-label string] [-w|--width pixels]\n" "\t\t[-h|--height pixels] [-o|--logarithmic]\n" "\t\t[-u|--upper-limit value] [-z|--lazy]\n" "\t\t[-l|--lower-limit value] [-r|--rigid]\n" - "\t\t[-g|--no-legend]\n" + "\t\t[-g|--no-legend] [--daemon ]\n" "\t\t[-F|--force-rules-legend]\n" "\t\t[-j|--only-graph]\n"); const char *help_graph2 = N_("\t\t[-n|--font FONTTAG:size:font]\n" @@ -217,7 +224,7 @@ void PrintUsage( C_LASTUPDATE, C_FIRST, C_UPDATE, C_FETCH, C_GRAPH, C_GRAPHV, C_TUNE, C_RESIZE, C_XPORT, C_QUIT, C_LS, C_CD, C_MKDIR, C_PWD, - C_UPDATEV + C_UPDATEV, C_FLUSH }; int help_cmd = C_NONE; @@ -242,6 +249,8 @@ void PrintUsage( help_cmd = C_UPDATEV; else if (!strcmp(cmd, "fetch")) help_cmd = C_FETCH; + else if (!strcmp(cmd, "flush")) + help_cmd = C_FLUSH; else if (!strcmp(cmd, "graph")) help_cmd = C_GRAPH; else if (!strcmp(cmd, "graphv")) @@ -302,6 +311,9 @@ void PrintUsage( case C_FETCH: fputs(_(help_fetch), stdout); break; + case C_FLUSH: + fputs(_(help_flush), stdout); + break; case C_GRAPH: fputs(_(help_graph0), stdout); fputs(_(help_graph1), stdout); @@ -364,11 +376,16 @@ static char *fgetslong( return *aLinePtr = linebuf; bufsize += MAX_LENGTH; if (!(linebuf = realloc(linebuf, bufsize))) { + free(linebuf); perror("fgetslong: realloc"); exit(1); } } - return *aLinePtr = linebuf[0] ? linebuf : 0; + if (linebuf[0]){ + return *aLinePtr = linebuf; + } + free(linebuf); + return *aLinePtr = 0; } int main( @@ -419,11 +436,8 @@ int main( == 0) { #ifdef HAVE_CHROOT - chroot(argv[2]); - if (errno != 0) { - fprintf(stderr, - "ERROR: can't change root to '%s' errno=%d\n", - argv[2], errno); + if (chroot(argv[2]) != 0){ + fprintf(stderr, "ERROR: chroot %s: %s\n", argv[2],rrd_strerror(errno)); exit(errno); } ChangeRoot = 1; @@ -439,15 +453,15 @@ int main( } } if (strcmp(firstdir, "")) { - chdir(firstdir); - if (errno != 0) { - fprintf(stderr, "ERROR: %s\n", rrd_strerror(errno)); + if (chdir(firstdir) != 0){ + fprintf(stderr, "ERROR: chdir %s %s\n", firstdir,rrd_strerror(errno)); exit(errno); } } while (fgetslong(&aLine, stdin)) { if ((argc = CountArgs(aLine)) == 0) { + free(aLine); printf("ERROR: not enough arguments\n"); } if ((myargv = (char **) malloc((argc + 1) * @@ -456,6 +470,8 @@ int main( exit(1); } if ((argc = CreateArgs(argv[0], aLine, argc, myargv)) < 0) { + free(aLine); + free(myargv); printf("ERROR: creating arguments\n"); } else { int ret = HandleInputLine(argc, myargv, stdout); @@ -512,7 +528,6 @@ int HandleInputLine( /* Reset errno to 0 before we start. */ - errno = 0; if (RemoteMode) { if (argc > 1 && strcmp("quit", argv[1]) == 0) { if (argc > 2) { @@ -535,9 +550,8 @@ int HandleInputLine( return (1); } #endif - chdir(argv[2]); - if (errno != 0) { - printf("ERROR: %s\n", rrd_strerror(errno)); + if (chdir(argv[2]) != 0){ + printf("ERROR: chdir %s %s\n", argv[2], rrd_strerror(errno)); return (1); } return (0); @@ -549,7 +563,7 @@ int HandleInputLine( } cwd = getcwd(NULL, MAXPATH); if (cwd == NULL) { - printf("ERROR: %s\n", rrd_strerror(errno)); + printf("ERROR: getcwd %s\n", rrd_strerror(errno)); return (1); } printf("%s\n", cwd); @@ -569,9 +583,8 @@ int HandleInputLine( return (1); } #endif - mkdir(argv[2], 0777); - if (errno != 0) { - printf("ERROR: %s\n", rrd_strerror(errno)); + if(mkdir(argv[2], 0777)!=0){ + printf("ERROR: mkdir %s: %s\n", argv[2],rrd_strerror(errno)); return (1); } return (0); @@ -599,7 +612,7 @@ int HandleInputLine( } closedir(curdir); } else { - printf("ERROR: %s\n", rrd_strerror(errno)); + printf("ERROR: opendir .: %s\n", rrd_strerror(errno)); return (errno); } return (0); @@ -621,15 +634,15 @@ int HandleInputLine( else if (strcmp("dump", argv[1]) == 0) rrd_dump(argc - 1, &argv[1]); else if (strcmp("info", argv[1]) == 0 || strcmp("updatev", argv[1]) == 0) { - info_t *data; + rrd_info_t *data; if (strcmp("info", argv[1]) == 0) data = rrd_info(argc - 1, &argv[1]); else data = rrd_update_v(argc - 1, &argv[1]); - info_print(data); - info_free(data); + rrd_info_print(data); + rrd_info_free(data); } else if (strcmp("--version", argv[1]) == 0 || @@ -646,26 +659,7 @@ int HandleInputLine( else if (strcmp("last", argv[1]) == 0) printf("%ld\n", rrd_last(argc - 1, &argv[1])); else if (strcmp("lastupdate", argv[1]) == 0) { - time_t last_update; - char **ds_namv; - char **last_ds; - unsigned long ds_cnt, i; - - if (rrd_lastupdate(argc - 1, &argv[1], &last_update, - &ds_cnt, &ds_namv, &last_ds) == 0) { - for (i = 0; i < ds_cnt; i++) - printf(" %s", ds_namv[i]); - printf("\n\n"); - printf("%10lu:", last_update); - for (i = 0; i < ds_cnt; i++) { - printf(" %s", last_ds[i]); - free(last_ds[i]); - free(ds_namv[i]); - } - printf("\n"); - free(last_ds); - free(ds_namv); - } + rrd_lastupdate(argc - 1, &argv[1]); } else if (strcmp("first", argv[1]) == 0) printf("%ld\n", rrd_first(argc - 1, &argv[1])); else if (strcmp("update", argv[1]) == 0) @@ -804,16 +798,18 @@ int HandleInputLine( } } else if (strcmp("graphv", argv[1]) == 0) { - info_t *grinfo = NULL; /* 1 to distinguish it from the NULL that rrd_graph sends in */ + rrd_info_t *grinfo = NULL; /* 1 to distinguish it from the NULL that rrd_graph sends in */ grinfo = rrd_graph_v(argc - 1, &argv[1]); if (grinfo) { - info_print(grinfo); - info_free(grinfo); + rrd_info_print(grinfo); + rrd_info_free(grinfo); } } else if (strcmp("tune", argv[1]) == 0) rrd_tune(argc - 1, &argv[1]); + else if (strcmp("flush", argv[1]) == 0) + rrd_cmd_flush(argc - 1, &argv[1]); else { rrd_set_error("unknown function '%s'", argv[1]); }