[rrd-users] Multiple calls to rrd_fetch results in "not enough arguments"

Ollie Cook ollie at uk.clara.net
Sun Apr 14 00:46:24 MEST 2002


Hi,

I am writing a program in C which interfaces with librrdtool.  It loops through
an array of .rrd files, and calls rrd_fetch on each of them.

However, on the second and subsequent calls to rrd_fetch, the function returns
-1 and sets the rrd_error to "not enough arguments".

As far as I can tell, this is because optind persists between calls to
getopt_long which rrd_fetch calls.

On the first call, optind is 1, so the condition (optind + 1 >= argc) is not
met, but on subsequent calls, optind is greater than 1, so the condition is
met, causing rrd_fetch to fail:

  | Breakpoint 1, rrd_fetch (argc=5, argv=0xbfbff9d0, start=0xbfbffa00, end=0xbfbff9fc, step=0xbfbff9f8, ds_cnt=0xbfbff9f4, 
  |    ds_namv=0xbfbff9e8, data=0xbfbff9ec) at rrd_fetch.c:27
  |27          long     step_tmp =1;
  |(gdb) p optind
  |$1 = 1
  |(gdb) c
  |Continuing.

(The above, first, call to rrd_fetch returns 0)

  |
  |Breakpoint 1, rrd_fetch (argc=5, argv=0xbfbff9d0, start=0xbfbffa00, end=0xbfbff9fc, step=0xbfbff9f8, ds_cnt=0xbfbff9f4, 
  |    ds_namv=0xbfbff9e8, data=0xbfbff9ec) at rrd_fetch.c:27
  |27          long     step_tmp =1;
  |(gdb) p optind
  |$2 = 3
  |(gdb) c
  |Continuing.
  |
  |Breakpoint 1, rrd_fetch (argc=5, argv=0xbfbff9d0, start=0xbfbffa00, end=0xbfbff9fc, step=0xbfbff9f8, ds_cnt=0xbfbff9f4, 
  |    ds_namv=0xbfbff9e8, data=0xbfbff9ec) at rrd_fetch.c:27
  |27          long     step_tmp =1;
  |(gdb) p optind
  |$3 = 5
  |(gdb) 

(These two, and subsequent calls, return -1).

argv which is passed to rrd_fetch by my program is the same in all calls, with
the exception of the filename, which changes. The number of arguments remains
constant.

So my question is, should optind be incrementing by 2 on each call to
rrd_fetch? I would have though it should have stayed a constant '1' on each
call.

The behaviour is exhibited in all version of rrdtool I have tried up to 1.0.35.

A workaround is to reset optind before each call to rrd_fetch, but maybe this
should be handled in the rrd_* function calls themselves?

If there is any further information I can provide, please let me know.

Ollie

-- 
Oliver Cook    Systems Administrator, ClaraNET
ollie at uk.clara.net               020 7903 3065

--
Unsubscribe mailto:rrd-users-request at list.ee.ethz.ch?subject=unsubscribe
Help        mailto:rrd-users-request at list.ee.ethz.ch?subject=help
Archive     http://www.ee.ethz.ch/~slist/rrd-users
WebAdmin    http://www.ee.ethz.ch/~slist/lsg2.cgi



More information about the rrd-users mailing list