Red Hat Bugzilla – Bug 214738
rrdtool library functions cannot be called multiple times
Last modified: 2007-11-30 17:11:48 EST
Description of problem:
I have a C program linked to librrd.so that does something like this:
if ( rrdfile doesn't exist )
If rrd file does not exist, the call to rrd_update() will fail
with really odd results (trying to open a file with a name that
suspiciously matches one of the new values).
Version-Release number of selected component (if applicable):
rrdtool-1.0.49-4.fc3 and rrdtool-devel-1.0.49-4.fc3
Every single time.
Steps to Reproduce:
1. create a C program like mentioned above
2. make sure the rrd file does not exist
3. run the program --> rrd_update() will fail.
Note that the rrdfile was created successfully.
4. now run the program again --> rrd_update() works fine.
The problem is apparently a well known problem with rrdtool.
I found messages as early as 2002 referring to this problem.
The issue is that all the rrdtool functions in librrd.so
use getopt_long() but none of the functions initialize
optind and opterr.
The solution to this problem is trivial: initialize optind
and opterr right before calling any of the rrd_*() functions
in librrd.so. Of course, you first need to waste a day's work
debugging this problem only to find out that it is a well
The _CORRECT_ solution to this problem is to initialize optind
and opterr right before calling getopt_long() the first time
on each function _IN_ librrd.so. The calling programs shouldn't
need to know how librrd is implemented.
See attached patches for rrdtool-1.0.49-4 and rrdtool-1.0.50
Created attachment 140742 [details]
patch to correct the getopt() problem for rrdtool-1.0.49
Created attachment 140743 [details]
patch to correct the getopt() problem for rrdtool-1.0.50
This is the patch for rrdtool-1.0.50, as used in FC5.
Fedora Core 4 and older have all been retired, and new builds are frowned upon
unless they address severe bugs or security issues.
Is there really a compelling reason here to update a package for something as
old as FC3?
As for FC5, rrdtool is already updated to 1.2.15.
I guess there is no big compelling reason once you know how to work around the
bug. In my case, this bug wasted two days of my time only to find out that I had
stumbled upon a very old bug (and apparently, well known).
If anyone finds themselves in the same boat, at least the patches and the
information here will provide the info they need.
Thanks for your attention.
Sounds good to me.