Grzegorz Dzięgielewski wrote:
> Hello!
>
> While wget is used on dualcpu machine the assert(msecs>=0) from
> calc_rate() broke program execution with this:
> wget: retr.c:262: calc_rate: Warunek `msecs >= 0' nie został
> spełniony. (Polish locale - sorry)
>
> We think that bug is in wtimer_elapsed() function. Probably it's a
> problem with forking and timer. We have cutted of the measure of KB/s
> and everything is ok.
>
> My system: Debian woody 2.4.20+grsec1.9.8a, 2xCeleron433Mhz, 192RAM.
When I experienced this, it was because gettimeofday()'s subsecond value
sometimes went *backwards*.
To test for this, I made this code:
--------------- gtodtest.c ------------------
#include <stdio.h>
#include <sys/time.h>
int main(int argc, char* argv[]) {
struct timeval t,t1 = {0,0};
setvbuf(stdout, NULL, _IONBF, 0);
while (1) {
gettimeofday(&t,NULL);
// printf("%12li : %7li\n", t.tv_sec, t.tv_usec);
if (t.tv_sec == t1.tv_sec)
{ if (t.tv_usec < t1.tv_usec) putc('!',stdout); }
else putc('.',stdout);
t1.tv_sec = t.tv_sec;
t1.tv_usec = t.tv_usec;
}
return 0;
}
-------------------------------------------------
Compile and run. It prints a '.' every second, and a '!' every time
gettimeofday misbehaves. If you get lots of '!'s then you know this is the
problem. A crude solution is to change the assert to "if (msecs >= 0) msecs
= 0;".
Max.