[rrd-developers] rrdtool args too long for shell - solution

rik1083 rkearsley at blueyonder.co.uk
Sun Aug 1 02:38:43 CEST 2010


Hi Guys
Thanks for your wonderful tool, I use it all the time. 
I've been hitting a problem while combining several rrds into a single
graph, for example:
300 rrds, 14 datasources in each.. and combining them all
basically 100's if not 1000's of arguements
The problem is that the shell was hitting a length limit!
My solution - write args to text file (1 per line) and pass the filename as
the arg and read them in from the text file..
I'm not sure I did it in a great way but it works and could be useful if
anyone comes across this problem too. Code:
I renamed the original main() to rrdmain() and  made a new main which calls
rrdmain() after it has read the args from the file:

int main (int argc, char **argv[]) {

	FILE*fp ;
	int i;
	char line[1600];
	char** myargv;
	char* carriage;

	if (argc > 2 && strcmp("file", argv[1]) == 0) {

         fp = fopen ( argv[2],"r" ) ;
         if( fp == NULL )
         {
               puts ( "cannot open file" ) ;
               return 0;
		 }

		i = 0;
		while(!feof(fp))
		{
			i++;
			memset(line,'\0',1600);
			fgets(line,1600,fp);
			//printf("line %s", line);
		}
		fclose(fp);
		
		myargv = calloc(i, sizeof(char*));

		fp = fopen ( argv[2],"r" ) ;
		i=0;
		while(!feof(fp))
		{
			fgets(line,1600,fp);
			carriage = strrchr(line, '\n');
			if (carriage != NULL) { *carriage = 0; }
			myargv[i] = strdup(line);
			printf("line %s", line);
			i++;
		}
		fclose(fp);
		rrdmain(i, myargv);
	}
	else {
		rrdmain(argc, argv);
	}
}
         

int rrdmain(
    int argc,
    char **argv[])
{ //original main follows unmodified


again, it's not great but it got me past the limitation and maybe you can
use the idea in future versions

Cheers,
Richard

-- 
View this message in context: http://rrd-mailinglists.937164.n2.nabble.com/rrdtool-args-too-long-for-shell-solution-tp5359835p5359835.html
Sent from the RRDtool Developers Mailinglist mailing list archive at Nabble.com.



More information about the rrd-developers mailing list