[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#428035: libc6: timmes() returns large negative integer in case of failure instead of -1.

On Fri, Jun 08, 2007 at 12:47:51PM +0200, Joern Wuestenfeld wrote:
> Dear Pierre,
> unfortunately not, because it gives a reasonable result with libc 2.3.6:
> The following small test program:
> #include <sys/times.h>
> #include <stdio.h>
> #include <stdlib.h>
> int main(int argc, char **argv)
> {
>         struct tms *buf;
>         int res;
>         res = times(buf);
>         printf("%s%d%s%d\n","Return from times = ",res, " with  a time =
> ",buf-
> >tms_utime);
>   exit(0);
> }
> gives under libc.so.2.3.6:
> Using gcc (GCC) 4.1.3 20070601 (prerelease) (Debian 4.1.2-12)
> Return from times = -1 with  a time = -1086733439
> and under libc.so.2.5:
> Using gcc (GCC) 4.1.3 20070601 (prerelease) (Debian 4.1.2-12)
> Return from times = -891447083 with  a time = 0
> So whats wrong with the type?

  Nothing. Just read the man page.

       times() returns the number of clock ticks that have elapsed since an  arbitrary	point  in  the
       past.   For  Linux 2.4 and earlier this point is the moment the system was booted.  Since Linux
       2.6, this point is (2^32/HZ) - 300 (i.e., about 429 million) seconds before system  boot  time.
       The  return  value  may overflow the possible range of type clock_t.  On error, (clock_t) -1 is
       returned, and errno is set appropriately.

  this is clear, robust simple. with libc 2.3 it failed for some reason.
Now it does *NOT* fails, gives you your _wrapped_ (see manpage) uptime,
and user time of the calling process, that is 0 (and that's not a
surprise as your example didn't run long enough).

  If you want ot test for error, you should test res against
(clock_t)-1. negatives values are not an error and for any value !=
(clock_t)-1, the tms struct values can be trusted. full stop, just
quoting the documentation.

  And if that breaks your oracle database or whatever, then the
application is making false assertions about what times(3) does.

·O·  Pierre Habouzit
··O                                                madcoder@debian.org
OOO                                                http://www.madism.org

Attachment: pgpAOHhnUT4mA.pgp
Description: PGP signature

Reply to: