[olsr-dev] strange using of times() ?

Bernd Petrovitsch (spam-protected)
Wed Dec 28 22:57:37 CET 2005


On Wed, 2005-12-28 at 22:32 +0100, Thomas Capricelli wrote:
> On Wednesday 28 December 2005 17:54, Bernd Petrovitsch wrote:
> > On Wed, 2005-12-28 at 00:21 +0100, Thomas Capricelli wrote:
> > [...]
> >
> > > i had the pb of olsrd refusing to start. The error being in
> > > src/scheduler.c,
> >
> > Which version exactly?
> 
> 	oh, 0.4.9, of course. sorry :)

And on Linux I assume.

> > > around line #120
> > > times() returns an error, with errno=2, ("no such file or directory")
> >
> > Depending on the exact version,
> > -) return values of sys-calls are compared "< 0" instead of "==
> >    -1" (yes, I will send patches tro fix them if 0.4.10 is out).
> >    And yes, there were bug reports of this.
> > -) errno might have been overwritten on errors. I already sent patches
> >    but I don't know if I got all cases and if all of them are fixed.
> >    (And I'm also waiting for 0.4.10).
> 
> 	yes, the code says < 0  : 
> 	..   if((end_of_loop = times(&tms_buf)) < 0) ...
> 
> 	So i can consider that there's actually a problem and that the pb is still 
> here in 0.4.10 ?

Yes. This should (at least) read "== -1" instead of "< 0" (to be
POSIX-anal). And the comparison must be formulated different (i.e. make
an unsigned subtraction and compare the unsigned result with 1<<31 for a
mathematically correct result).
The serious problem with the times(2) sys-call is (and this is not an
OLSRD problem) that it returns the number of clock ticks since startup.
And it may overflow which implies that -1 as returned value (if
interpreted as signed) is not necessarily an error but may be just the
1:1<<32 chance to be the correct and valid value (if your machine runs
long enough) and I can't think of a reason for a failing times(2) call
ATM.
Given that (most of) more or less recent Linux systems have 1000 clock
ticks per second, the "long enough" is just around 49 days (which fits
perfectly in your 50 day measurement).
Read "man 2 times" to get to know how to seriously get the clock tick
value (there are others widely used like 100 for former x86 and almost
all of the other systems, 1024 on Alphas since ages and it is alsp
configurable BTW) out of the currently running box.

	Bernd
-- 
Firmix Software GmbH                   http://www.firmix.at/
mobil: +43 664 4416156                 fax: +43 1 7890849-55
          Embedded Linux Development and Services







More information about the Olsr-dev mailing list