/*****************************************************************************
- * RRDtool 1.2.1 Copyright by Tobi Oetiker, 1997-2005
+ * RRDtool 1.2.15 Copyright by Tobi Oetiker, 1997-2006
*****************************************************************************
* rrd_tool.c Startup wrapper
*****************************************************************************/
{
char help_main[] =
- "RRDtool 1.2.1 Copyright 1997-2005 by Tobias Oetiker <tobi@oetiker.ch>\n"
-#if defined(WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__)
+ "RRDtool " PACKAGE_VERSION " Copyright 1997-2006 by Tobias Oetiker <tobi@oetiker.ch>\n"
" Compiled " __DATE__ " " __TIME__ "\n\n"
-#else
- " Compiled " MAKE_TIMESTAMP "\n\n"
-#endif
"Usage: rrdtool [options] command command_options\n\n";
char help_list[] =
"\t\tlast, first, info, fetch, tune, resize, xport\n\n";
char help_listremote[] =
- "Valid remote commands: quit, ls, cd, mkdir\n\n";
+ "Valid remote commands: quit, ls, cd, mkdir, pwd\n\n";
char help_create[] =
"\t\ttime|N:value[:value...]\n\n"
"\t\tat-time@value[:value...]\n\n"
"\t\t[ time:value[:value...] ..]\n\n";
-
+
char help_fetch[] =
"* fetch - fetch data out of an RRD\n\n"
"\trrdtool fetch filename.rrd CF\n"
- "\t\t[--resolution|-r resolution]\n"
- "\t\t[--start|-s start] [--end|-e end]\n\n";
+ "\t\t[-r|--resolution resolution]\n"
+ "\t\t[-s|--start start] [-e|--end end]\n\n";
/* break up very large strings (help_graph, help_tune) for ISO C89 compliance*/
"* graph - generate a graph from one or several RRD\n\n"
"\trrdtool graph filename [-s|--start seconds] [-e|--end seconds]\n"
"\t\t[-x|--x-grid x-axis grid and label]\n"
- "\t\t[--alt-y-grid]\n"
+ "\t\t[-Y|--alt-y-grid]\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[-F|--force-rules-legend]\n";
+ "\t\t[-F|--force-rules-legend]\n"
+ "\t\t[-j|--only-graph]\n";
char help_graph2[] =
- "\t\t[-j|--only-graph]\n"
- "\t\t[--font FONTTAG:size:font]\n"
- "\t\t[--zoom factor]\n"
- "\t\t[--alt-autoscale]\n"
- "\t\t[--alt-autoscale-max]\n"
- "\t\t[--no-gridfit]\n"
- "\t\t[--units-exponent value]\n"
- "\t\t[--units-length value]\n"
- "\t\t[--step seconds]\n"
+ "\t\t[-n|--font FONTTAG:size:font]\n"
+ "\t\t[-m|--zoom factor]\n"
+ "\t\t[-A|--alt-autoscale]\n"
+ "\t\t[-M|--alt-autoscale-max]\n"
+ "\t\t[-R|--font-render-mode {normal,light,mono}]\n"
+ "\t\t[-B|--font-smoothing-threshold size]\n"
+ "\t\t[-E|--slope-mode]\n"
+ "\t\t[-N|--no-gridfit]\n"
+ "\t\t[-X|--units-exponent value]\n"
+ "\t\t[-L|--units-length value]\n"
+ "\t\t[-S|--step seconds]\n"
"\t\t[-f|--imginfo printfstr]\n"
"\t\t[-a|--imgformat PNG]\n"
- "\t\t[-c|--color COLORTAG#rrggbb[aa]] [-t|--title string]\n";
+ "\t\t[-c|--color COLORTAG#rrggbb[aa]] [-t|--title string]\n"
+ "\t\t[-W|--watermark string]\n"
+ "\t\t[DEF:vname=rrd:ds-name:CF]\n";
char help_graph3[] =
- "\t\t[DEF:vname=rrd:ds-name:CF]\n"
"\t\t[CDEF:vname=rpn-expression]\n"
"\t\t[VDEF:vdefname=rpn-expression]\n"
- "\t\t[PRINT:vname:CF:format]\n"
- "\t\t[GPRINT:vname:CF:format]\n"
"\t\t[PRINT:vdefname:format]\n"
"\t\t[GPRINT:vdefname:format]\n"
+ "\t\t[COMMENT:text]\n"
+ "\t\t[SHIFT:vname:offset]\n"
+ "\t\t[TICK:vname#rrggbb[aa][:[fraction][:legend]]]\n"
"\t\t[HRULE:value#rrggbb[aa][:legend]]\n"
"\t\t[VRULE:value#rrggbb[aa][:legend]]\n"
- "\t\t[LINE{1|2|3}:vname[#rrggbb[aa][:legend]][:STACK]]\n"
- "\t\t[AREA:vname[#rrggbb[aa][:legend]][:STACK]]\n"
- "\t\t[STACK:vname[#rrggbb[aa][:legend]]]\n\n";
+ "\t\t[LINE[width]:vname[#rrggbb[aa][:[legend][:STACK]]]]\n"
+ "\t\t[AREA:vname[#rrggbb[aa][:[legend][:STACK]]]]\n"
+ "\t\t[PRINT:vname:CF:format] (deprecated)\n"
+ "\t\t[GPRINT:vname:CF:format] (deprecated)\n"
+ "\t\t[STACK:vname[#rrggbb[aa][:legend]]] (deprecated)\n\n";
char help_tune1[] =
" * tune - Modify some basic properties of an RRD\n\n"
"\trrdtool xport [-s|--start seconds] [-e|--end seconds]\n"
"\t\t[-m|--maxrows rows]\n"
"\t\t[--step seconds]\n"
+ "\t\t[--enumds]\n"
"\t\t[DEF:vname=rrd:ds-name:CF]\n"
"\t\t[CDEF:vname=rpn-expression]\n"
"\t\t[XPORT:vname:legend]\n\n";
" * mkdir - creates a new directory\n\n"
"\trrdtool mkdir newdirectoryname\n\n";
+ char help_pwd[] =
+ " * pwd - returns the current working directory\n\n"
+ "\trrdtool pwd\n\n";
+
char help_lic[] =
"RRDtool is distributed under the Terms of the GNU General\n"
"Public License Version 2. (www.gnu.org/copyleft/gpl.html)\n\n"
enum { C_NONE, C_CREATE, C_DUMP, C_INFO, C_RESTORE, C_LAST, C_FIRST,
C_UPDATE, C_FETCH, C_GRAPH, C_TUNE, C_RESIZE, C_XPORT,
- C_QUIT, C_LS, C_CD, C_MKDIR, C_UPDATEV };
+ C_QUIT, C_LS, C_CD, C_MKDIR, C_PWD, C_UPDATEV };
int help_cmd = C_NONE;
help_cmd = C_CD;
else if (!strcmp(cmd,"mkdir"))
help_cmd = C_MKDIR;
+ else if (!strcmp(cmd,"pwd"))
+ help_cmd = C_PWD;
}
fputs(help_main, stdout);
switch (help_cmd)
case C_MKDIR:
fputs(help_mkdir, stdout);
break;
+ case C_PWD:
+ fputs(help_pwd, stdout);
+ break;
}
fputs(help_lic, stdout);
}
+static char *fgetslong(char **aLinePtr, FILE *stream)
+{
+ char *linebuf;
+ size_t bufsize = MAX_LENGTH;
+ int eolpos = 0;
+
+ if (feof(stream)) return *aLinePtr = 0;
+ if (!(linebuf = malloc(bufsize))) {
+ perror("fgetslong: malloc");
+ exit(1);
+ }
+ linebuf[0] = '\0';
+ while (fgets(linebuf + eolpos, MAX_LENGTH, stream)) {
+ eolpos += strlen(linebuf + eolpos);
+ if (linebuf[eolpos - 1] == '\n') return *aLinePtr = linebuf;
+ bufsize += MAX_LENGTH;
+ if (!(linebuf = realloc(linebuf, bufsize))) {
+ perror("fgetslong: realloc");
+ exit(1);
+ }
+ }
+ return *aLinePtr = linebuf[0] ? linebuf : 0;
+}
int main(int argc, char *argv[])
{
char **myargv;
- char aLine[MAX_LENGTH];
-#ifdef HAVE_CHROOT
+ char *aLine;
char *firstdir="";
-#endif
#ifdef MUST_DISABLE_SIGFPE
signal(SIGFPE,SIG_IGN);
#endif
gettimeofday(&starttime,&tz);
#endif
RemoteMode=1;
-#ifdef HAVE_CHROOT
if ((argc == 3) && strcmp("",argv[2])){
- if (getuid()==0){
+
+ if (
+#ifdef HAVE_GETUID
+ getuid()
+#else
+ 1
+#endif
+ == 0 ){
+
+#ifdef HAVE_CHROOT
chroot(argv[2]);
if (errno!=0){
fprintf(stderr,"ERROR: can't change root to '%s' errno=%d\n",
}
ChangeRoot=1;
firstdir="/";
- }
- else{
+#else
+ fprintf(stderr,"ERROR: change root is not supported by your OS "
+ "or at least by this copy of rrdtool\n");
+ exit(1);
+#endif
+ } else {
firstdir=argv[2];
}
}
exit(errno);
}
}
-#else
- fprintf(stderr,"ERROR: change root is not supported by your OS "
- "or at least by this copy of rrdtool\n");
- exit(1);
-#endif
- while (fgets(aLine, sizeof(aLine)-1, stdin)){
+ while (fgetslong(&aLine, stdin)){
if ((argc = CountArgs(aLine)) == 0) {
- fprintf(stderr,"ERROR: not enough arguments\n");
+ printf("ERROR: not enough arguments\n");
}
if ((myargv = (char **) malloc((argc+1) *
sizeof(char *))) == NULL) {
exit(1);
}
if ((argc=CreateArgs(argv[0], aLine, argc, myargv)) < 0) {
- fprintf(stderr, "ERROR: creating arguments\n");
- exit(1);
- }
-
- if (HandleInputLine(argc, myargv, stdout))
- exit(1);
- free(myargv);
+ printf("ERROR: creating arguments\n");
+ } else {
+ int ret = HandleInputLine(argc, myargv, stdout);
+ free(myargv);
+ if (ret == 0){
+
#if HAVE_GETRUSAGE
- getrusage(RUSAGE_SELF,&myusage);
- gettimeofday(¤ttime,&tz);
- printf("OK u:%1.2f s:%1.2f r:%1.2f\n",
+ getrusage(RUSAGE_SELF,&myusage);
+ gettimeofday(¤ttime,&tz);
+ printf("OK u:%1.2f s:%1.2f r:%1.2f\n",
(double)myusage.ru_utime.tv_sec+
(double)myusage.ru_utime.tv_usec/1000000.0,
(double)myusage.ru_stime.tv_sec+
+(double)(currenttime.tv_usec-starttime.tv_usec)
/1000000.0);
#else
- printf("OK\n");
-#endif
+ printf("OK\n");
+
+#endif
+ }
+ }
fflush(stdout); /* this is important for pipes to work */
+ free(aLine);
}
}
else if (argc == 2)
#if defined(HAVE_SYS_STAT_H)
struct stat st;
#endif
+ char* cwd; /* To hold current working dir on call to pwd */
+
+ /* Reset errno to 0 before we start.
+ */
+ errno = 0;
if (RemoteMode){
if (argc>1 && strcmp("quit", argv[1]) == 0){
if (argc>2){
printf("ERROR: invalid parameter count for quit\n");
- return(0);
+ return(1);
}
exit(0);
}
if (argc>1 && strcmp("cd", argv[1]) == 0){
if (argc>3){
printf("ERROR: invalid parameter count for cd\n");
- return(0);
+ return(1);
}
#if ! defined(HAVE_CHROOT) || ! defined(HAVE_GETUID)
if (getuid()==0 && ! ChangeRoot){
printf("ERROR: chdir security problem - rrdtool is running as "
- "root an no chroot!\n");
- return(0);
+ "root but not chroot!\n");
+ return(1);
}
#endif
chdir(argv[2]);
if (errno!=0){
printf("ERROR: %s\n",rrd_strerror(errno));
+ return(1);
}
return(0);
}
+ if (argc>1 && strcmp("pwd", argv[1]) == 0){
+ if (argc>2){
+ printf("ERROR: invalid parameter count for pwd\n");
+ return(1);
+ }
+ cwd = getcwd(NULL, MAXPATH);
+ if(cwd == NULL) {
+ printf("ERROR: %s\n",rrd_strerror(errno));
+ return(1);
+ }
+ printf("%s\n", cwd);
+ free(cwd);
+ return(0);
+ }
if (argc>1 && strcmp("mkdir", argv[1]) == 0){
if (argc>3){
printf("ERROR: invalid parameter count for mkdir\n");
- return(0);
+ return(1);
}
#if ! defined(HAVE_CHROOT) || ! defined(HAVE_GETUID)
if (getuid()==0 && ! ChangeRoot){
printf("ERROR: mkdir security problem - rrdtool is running as "
- "root an no chroot!\n");
- return(0);
+ "root but not chroot!\n");
+ return(1);
}
#endif
mkdir(argv[2],0777);
if (errno!=0){
printf("ERROR: %s\n",rrd_strerror(errno));
+ return(1);
}
return(0);
}
if (argc>1 && strcmp("ls", argv[1]) == 0){
if (argc>2){
printf("ERROR: invalid parameter count for ls\n");
- return(0);
+ return(1);
}
if ((curdir=opendir("."))!=NULL){
while((dent=readdir(curdir))!=NULL){
}
}
}
+ closedir(curdir);
}
else{
printf("ERROR: %s\n",rrd_strerror(errno));
strcmp("v", argv[1]) == 0 ||
strcmp("-v", argv[1]) == 0 ||
strcmp("-version", argv[1]) == 0 )
- printf("RRDtool 1.2.1 Copyright by Tobi Oetiker, 1997-2005\n");
+ printf("RRDtool " PACKAGE_VERSION " Copyright by Tobi Oetiker, 1997-2005 (%f)\n",
+ rrd_version());
else if (strcmp("restore", argv[1]) == 0)
rrd_restore(argc-1, &argv[1]);
else if (strcmp("resize", argv[1]) == 0)
free (data);
}
} else if (strcmp("xport", argv[1]) == 0) {
- int xxsize;
+ int xxsize;
unsigned long int j = 0;
time_t start,end, ti;
unsigned long step, col_cnt,row_cnt;
rrd_value_t *data,*ptr;
char **legend_v;
- if(rrd_xport(argc-1, &argv[1], &xxsize,&start,&end,&step,&col_cnt,&legend_v,&data) != -1) {
+ int enumds = 0;
+ int i;
+ char *vtag = NULL;
+ vtag = malloc( strlen(COL_DATA_TAG)+10);
+ for ( i = 2; i < argc; i++){
+ if (strcmp("--enumds", argv[i]) == 0)
+ enumds = 1;
+ }
+
+ if(rrd_xport(argc-1, &argv[1], &xxsize,&start,&end,&step,&col_cnt,&legend_v,&data) != -1) {
row_cnt = (end-start)/step;
ptr = data;
printf("<?xml version=\"1.0\" encoding=\"%s\"?>\n\n", XML_ENCODING);
printf (" <%s>", DATA_ROW_TAG);
printf ("<%s>%lu</%s>", COL_TIME_TAG, ti, COL_TIME_TAG);
for (j = 0; j < col_cnt; j++) {
+ if (enumds == 1)
+ snprintf(vtag,15,"%s%lu", COL_DATA_TAG, j);
+ else
+ snprintf(vtag,15,"%s",COL_DATA_TAG);
+
rrd_value_t newval = DNAN;
newval = *ptr;
if(isnan(newval)){
- printf("<%s>NaN</%s>", COL_DATA_TAG, COL_DATA_TAG);
+ printf("<%s>NaN</%s>", vtag,vtag);
} else {
- printf("<%s>%0.10e</%s>", COL_DATA_TAG, newval, COL_DATA_TAG);
+ printf("<%s>%0.10e</%s>", vtag, newval, vtag);
};
ptr++;
}
printf(" </%s>\n", DATA_TAG);
printf("</%s>\n", ROOT_TAG);
}
+ free(vtag);
}
else if (strcmp("graph", argv[1]) == 0) {
char **calcpr;
double ymin,ymax;
int i;
int tostdout = (strcmp(argv[2],"-") == 0);
+ int imginfo = 0;
+ for (i=2;i<argc;i++){
+ if (strcmp(argv[i],"--imginfo") == 0 || strcmp(argv[i],"-f") == 0){
+ imginfo = 1;
+ break;
+ }
+ }
if( rrd_graph(argc-1, &argv[1], &calcpr, &xsize, &ysize, NULL, &ymin, &ymax) != -1 ) {
- if (!tostdout)
+ if (!tostdout && !imginfo)
printf ("%dx%d\n",xsize,ysize);
if (calcpr) {
for(i=0;calcpr[i];i++){