[rrd-users] rrd_xport C usage

Olivier AUDRY olivier.audry at colt.net
Mon Mar 29 17:13:06 CEST 2010


hello

here is my very simple code to try to use rrd_xport. Some one can help me 
to understand why I have a segfault on the rrd_xport call ?

        int             optind,opterr,rows,xxsize;
        char            *s;
        char            **params;
        elem            *tmp;
        time_t          start, end;
        regex_t         reg;
        struct tm       *t;
        rrd_value_t     **data;
        unsigned long   col_cnt;
        unsigned long   step;


        step            = 300;
        col_cnt         = 1;
        xxsize          = 0;
        params          = malloc( 8 * sizeof(char *));
        start           = end = time(NULL) - 604800;
        end             += 1209600 ;

        t               = localtime(&start);
        tmp             = list;

        rows            = (start - end) / step;

        regcomp(&reg, pattern, REG_EXTENDED|REG_NOSUB|REG_ICASE);
        while(tmp != NULL) {
                regexec(&reg,tmp->filename,0,NULL,0);
                if (!regexec(&reg,tmp->filename,0,NULL,0)) {
                        optind = opterr = 0;
                        rrd_clear_error();
                        printf("Processing %s\n", tmp->filename);
                        s = calloc((strlen("DEF:used1=./rrd/lmwbs-ws01/") + strlen(tmp->filename) + \
                                strlen(":pct:AVERAGE")),  sizeof(char));

                        data = malloc (1 * rows * sizeof (rrd_value_t));

                        strcat(s,"DEF:used1=./rrd/lmwbs-ws01/");
                        strcat(s,tmp->filename);
                        strcat(s,":pct:AVERAGE");

                        params[0] = "xport";
                        params[1] = s;
                        params[2] = "VDEF:D2=used1,LSLSLOPE";
                        params[3] = "VDEF:H2=used1,LSLINT";
                        params[4] = "CDEF:avg2=used1,POP,D2,COUNT,*,H2,+";
                        params[5] = "CDEF:abc2=avg2,90,100,LIMIT";
                        params[6] = "XPORT:abc2:'uhuh'";
                        params[7] = NULL;

                        rrd_xport(8, params, &xxsize, &start, &end, &step, &col_cnt, NULL, data);
                        free(s);
                }
                tmp = tmp->nxt;
        }
        regfree(&reg);

thx for your help.

oau



More information about the rrd-users mailing list