[rrd-developers] problems with rrd_update() when updating rrd file

Tobias Oetiker tobi at oetiker.ch
Wed Jun 2 07:18:32 CEST 2010


Hi Kevin,

Yesterday kevin brintnall wrote:

> A couple questions for Tobi...
>
> (1) should rrd_update_r() call rrd_clear_error() at the top?  Its return
> call depends on rrd_test_error().  Would it make sense to save/clear/reset
> the error?  Not sure on this.

well, the way the error flag is handled until now (theoretically)
is, that whoever calls rrd_* functions has to rrd_clear_error prior to
calling the function, and after calling the function the should
check for errors ...

this is modeled after errno(3)

  For some system calls and library functions (e.g.,
  getpriority(2)), -1 is a valid return on success.  In such cases,
  a successful return can be distinguished from an error return by
  setting errno to zero before the call, and then, if the call
  returns a status that indicates that an error may have occurred,
  checking to see if errno has a non-zero value.

I did a quick grep for this in program/src and find that it is
mostly true except for a few cases. So the behaviour is quite
consistant but only just ...

as for rrd_update (and some others) doing stuff with rrd_test_error
internally, I guess this is the real culprit as this is not in line
with the behaviour you get from errno ...

so I guess the parts of code that do use rrd_test_error internally
should 'push' the prior state of rrd_error when they start working
and at the very end 'pop' it if no error has been set.


does this make sense ?

> (2) Should we expose rrd_info_r ?

aehm ... this is already exposed I think.

cheers
tobi
>
> -kb
>
> On Tue, Jun 1, 2010 at 7:42 AM, Tomáš Macek <maca02 at atlas.cz> wrote:
>
> > Hm, so rrd_clear_error() did the job. I inserted call of rrd_clear_error()
> > before each rrd_*() calling and program works (see the line with
> > "attention" comment). I've tried to simplify things as possible and here
> > it is, maybe this will help to anyone else to solve his problems... Am I
> > doing everything right now?
> >
> > Tomas
> >
> > -------------------------
> >
> > #include <stdio.h>
> > #include <sys/types.h>
> > #include <unistd.h>
> > #include <stdlib.h>
> > #include <stdarg.h>
> > #include <rrd.h>
> >
> > void rrd_cmd(char *cmdstr) {
> >     char *strptr = NULL, *str = NULL;
> >     char *argv[64];
> >     int error = 0, i = 0;
> >     rrd_info_t *it = NULL;
> >     char rrdcmd[2048] = "";
> >
> >     snprintf(rrdcmd, 2048, "%s", cmdstr);
> >
> >     i = 0;
> >
> >     /* memset update, create *argv[] */
> >     memset(argv, 0, 64 * sizeof(char *));
> >
> >     for (strptr = rrdcmd; strptr != NULL;) {
> >         while ((str = strsep(&strptr, " ")) != NULL && str != '\0') {
> >            argv[i] = str;
> >            i++;
> >         }
> >     }
> >
> >     rrd_clear_error(); /* attention!!! */
> >     it = rrd_info(i, argv);
> >     rrd_info_free(it);
> >     rrd_clear_error();  /* attention!!! */
> >      error = rrd_update(i, argv);
> >      if (error == -1) {
> >         printf("Error: RRD_UPDATE command: %s\n", rrd_get_error());
> >         rrd_clear_error();
> >     }
> > }
> >
> > int update_rrd_cmd(char *rrd_name, char *ds_string, char *n_value_string,
> > char *buff, int n) {
> >     memset(buff, 0, n);
> >     snprintf(buff, n, "update %s --template %s %s", rrd_name, ds_string,
> > n_value_string);
> >     printf("%s: buff = %s\n", __FUNCTION__, buff);
> >     return 0;
> > }
> >
> > int main(void) {
> >     char buff[2048] = "";
> >     update_rrd_cmd("./testfile.rrd", "ds0:ds1", "N:123:456", buff, 2048);
> >     rrd_cmd(buff);
> >     return 0;
> > }
> >
> >
> > On Tue, 01 Jun 2010 08:20:18 +0200, Tomáš Macek <maca02 at atlas.cz> wrote:
> >
> > > Hello again,
> > > this problem is present since 1.4.0. I know it, because I've tried every
> > > version since 1.3.8 (works), through 1.3.9 (works), 1.4.0 - 1.4.3 does
> > > not
> > > work at all with syntax error as described below. Everytime I compiled
> > > and
> > > tried the same source code and linked with the proper library version.
> > > What has changed in the API of rrd_update() in 1.4.0? I really don't
> > > understand what I'm doing wrong. Any hints/help appreciated, looking at
> > > the CHANGES file did not helped me.
> > >
> > > Tomas
> > >
> > >
> > > On Thu, 20 May 2010 12:28:25 +0200, Tomáš Macek <maca02 at atlas.cz> wrote:
> > >
> > >> Hi, I have RHEL 5.5 with rrdtool 1.4.3 and I'm using it's API for
> > >> updating
> > >> rrd files. The problem is that when I pass arguments to the rrd_update()
> > >> function, it always returns error saying "Usage: rrdtool update
> > >> [--daemon
> > >> <addr>] <file>". The same code worked really fine on 1.3.8. I looked at
> > >> the CHANGELOG file and there was some line saying, that something has
> > >> changed on checking optarg parameters.
> > >>
> > >> This is from gdb just before I pass the array into rrd_update()
> > >> function:
> > >> -----------
> > >> Breakpoint 2, rrd_cmd (rrdcmd=0x634dc0 "update", cmd=1, di_cnt=2) at
> > >> rrd_op.c:215
> > >> 215                 error = rrd_update(i, argv);
> > >> (gdb) p argv
> > >> $26 = {0x634dc0 "update", 0x634dc7 "cac_ap2aeth.rrd",
> > >>    0x634e06 "--template", 0x634e11 "ds0:ds1", 0x634e19
> > >> "N:2325779922:3582706806", 0x0 <repeats 59 times>}
> > >> -----------
> > >>
> > >> and after program goes thourgh rrd_update(), the argv array looks like
> > >> this:
> > >> -----------
> > >> 216                 if (error == -1) {
> > >> (gdb) p argv
> > >> $28 = {0x634dc0 "update", 0x634e06 "--template", 0x634e11 "ds0:ds1",
> > >>    0x634dc7 "cac_ap2aeth.rrd", 0x634e19 "N:2325779922:3582706806",
> > >>    0x0 <repeats 59 times>}
> > >> -----------
> > >>
> > >> Please, notice the replaced arguments after rrd_update()... I don't
> > >> know,
> > >> what I'm doing wrong, the code under 1.3.8 library worked just fine and
> > >> according to the man rrdupdate the arguments are fine. Hope I'm not
> > >> missing something stupid, but I was not able to find anything strange in
> > >> rrd_update() function in the rrd_update.c.
> > >> Let me know, if you need something more from me, thank you
> > >>
> > >> Regards, Tomas
> > >>
> > >> _______________________________________________
> > >> rrd-developers mailing list
> > >> rrd-developers at lists.oetiker.ch
> > >> https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
> > >
> > > _______________________________________________
> > > rrd-developers mailing list
> > > rrd-developers at lists.oetiker.ch
> > > https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
> >
> > _______________________________________________
> > rrd-developers mailing list
> > rrd-developers at lists.oetiker.ch
> > https://lists.oetiker.ch/cgi-bin/listinfo/rrd-developers
> >
>
>
>
>

-- 
Tobi Oetiker, OETIKER+PARTNER AG, Aarweg 15 CH-4600 Olten, Switzerland
http://it.oetiker.ch tobi at oetiker.ch ++41 62 775 9902 / sb: -9900


More information about the rrd-developers mailing list