Re: rrdtool libraries segfault with getopt
Peter Stamfest <peter <at> stamfest.at>
2003-04-04 18:17:42 GMT
On Fri, 4 Apr 2003, Markus Baertschi wrote:
> Date: Fri, 04 Apr 2003 19:54:40 +0200
> From: Markus Baertschi <markus <at> markus.org>
> To: Tobias Oetiker <oetiker <at> ee.ethz.ch>
> Cc: "rrd-developers <at> list.ee.ethz.ch" <rrd-developers <at> list.ee.ethz.ch>
> Subject: [rrd-developers] Re: rrdtool libraries segfault with getopt
> I've done some experimenting and can found, that the rrd_* routines
> require that the optind variable is set to zero before calling them.
> If you use getopt the optind variable points to the last argument
> in your respective argv after the array is processed. Getopt picks
> up where it left using this method. As this is standard unix proctice
> , I feel that the rrd_* routines should reset optind to zero before
> getopt processing.
> One could argue the user of getopt should reset optind to zero after
> each usage of getopt, but I've never seen this done. At the moment
> the rrd_* routines assume that getopt is zero, which breaks them for
> any program using getopt itself.
On a more general level I consider any repeated use of getopt "broken" in
any case, as one can never be sure what a particular getopt implementation
is _really_ doing behind the scenes. As long as one deals with just one
particular implementation a work-around is fine, but when the porting