X-Git-Url: https://git.octo.it/?p=rrdtool.git;a=blobdiff_plain;f=src%2Frrd_tool.c;h=5e44b301afebbe8ce7278b0d14e1ce020130255b;hp=2d0e17888950813115d1ea7341e916c9e0185aff;hb=210e991460e82d01d086f853e65485040eb2fffb;hpb=d6626f85e661f1aedea636b2f7bcde9cfa1f5e5e diff --git a/src/rrd_tool.c b/src/rrd_tool.c index 2d0e178..5e44b30 100644 --- a/src/rrd_tool.c +++ b/src/rrd_tool.c @@ -1,5 +1,5 @@ /***************************************************************************** - * RRDtool 1.3.0 Copyright by Tobi Oetiker, 1997-2008 + * RRDtool 1.3.1 Copyright by Tobi Oetiker, 1997-2008 ***************************************************************************** * rrd_tool.c Startup wrapper *****************************************************************************/ @@ -376,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( @@ -431,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; @@ -451,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) * @@ -468,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); @@ -524,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) { @@ -547,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); @@ -561,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); @@ -581,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); @@ -611,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);