Code

Imported upstream version 1.3.8.
[pkg-rrdtool.git] / src / rrd_tool.c
index c981e4a7397258de2709b80972a9a925ae00755f..673598790e1d1849fa74eeea806e13607aaabe47 100644 (file)
@@ -1,11 +1,13 @@
 /*****************************************************************************
- * RRDtool 1.3rc4  Copyright by Tobi Oetiker, 1997-2008
+ * RRDtool 1.3.8  Copyright by Tobi Oetiker, 1997-2009
  *****************************************************************************
  * rrd_tool.c  Startup wrapper
  *****************************************************************************/
 
 #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__CYGWIN32__) && !defined(HAVE_CONFIG_H)
 #include "../win32/config.h"
+#include <stdlib.h>
+#include <sys/stat.h>
 #else
 #ifdef HAVE_CONFIG_H
 #include "../rrd_config.h"
@@ -47,7 +49,7 @@ void PrintUsage(
 
     const char *help_main =
         N_("RRDtool %s"
-           "  Copyright 1997-2008 by Tobias Oetiker <tobi@oetiker.ch>\n"
+           "  Copyright 1997-2009 by Tobias Oetiker <tobi@oetiker.ch>\n"
            "               Compiled %s %s\n\n"
            "Usage: rrdtool [options] command command_options\n\n");
 
@@ -129,18 +131,22 @@ void PrintUsage(
            "\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[--right-axis scale:shift] [--right-axis-label label]\n"
+           "\t\t[--right-axis-format format]\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] [--full-size-mode]\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"
            "\t\t[-m|--zoom factor]\n"
            "\t\t[-A|--alt-autoscale]\n"
            "\t\t[-M|--alt-autoscale-max]\n"
+           "\t\t[-G|--graph-render-mode {normal,mono}]\n"
            "\t\t[-R|--font-render-mode {normal,light,mono}]\n"
            "\t\t[-B|--font-smoothing-threshold size]\n"
+           "\t\t[-T|--tabwidth width]\n"
            "\t\t[-E|--slope-mode]\n"
            "\t\t[-N|--no-gridfit]\n"
            "\t\t[-X|--units-exponent value]\n"
@@ -363,11 +369,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(
@@ -418,11 +429,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;
@@ -438,15 +446,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) *
@@ -455,6 +463,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);
@@ -511,7 +521,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) {
@@ -534,9 +543,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);
@@ -548,7 +556,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);
@@ -568,9 +576,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);
@@ -598,7 +605,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);
@@ -620,15 +627,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 ||
@@ -803,11 +810,12 @@ 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)