[Buildd-tools-devel] Bug#511095: Bug#511095: unportable use of sysinfo()

Roger Leigh rleigh at codelibre.net
Sun Jan 11 23:08:41 UTC 2009


tags 511095 + pending
thanks

On Wed, Jan 07, 2009 at 12:44:05PM +0000, Robert Millan wrote:
> buildd-mail-wrapper.c relies on unportable sysinfo() call that is only
> available on Linux.  I investigated what would be necessary for this
> program to use getloadavg() instead:
> 
>     waittime = (info.loads[0] >> (SI_LOAD_SHIFT-2))*6 + 20;
> 
> what we have here is info.loads[0] which internally represents a fixed
> point real number.  SI_LOAD_SHIFT is the number of bits it needs to be
> shifted to obtain its integer part.  By substracting 2 we get to keep two
> extra bits, which amount to the top-most 1/4th of the non-integer part.
> 
> info.loads[0] is actually the same as the first double returned by
> getloadavg(), only represented differently, so we can obtain the same
> value with:
> 
>     waittime = (((int) loadavg) << 2)		  /* integer part */
>                | (int) (fmod (loadavg, 1) * 4);   /* non-integer part,
> 						     multipled by 4 */
> 
> I made a few tests with the attached program, and both methods obtain
> exactly the same result.

Many thanks for writing and testing the patch.  I've committed this
into git master, and it will be in the next release.

The only change I made was to add a missing <math.h> include which
caused a compiler warning.

http://git.debian.org/?p=buildd-tools/sbuild.git;a=commitdiff;h=1dddc9d19d00d807eaa8543f0f3272da63d8581a
http://git.debian.org/?p=buildd-tools/sbuild.git;a=commitdiff;h=2546b0249e49effeb32839e792cb6bac570bc528


Thanks,
Roger

-- 
  .''`.  Roger Leigh
 : :' :  Debian GNU/Linux             http://people.debian.org/~rleigh/
 `. `'   Printing on GNU/Linux?       http://gutenprint.sourceforge.net/
   `-    GPG Public Key: 0x25BFB848   Please GPG sign your mail.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: Digital signature
Url : http://lists.alioth.debian.org/pipermail/buildd-tools-devel/attachments/20090111/c291aad9/attachment.pgp 


More information about the Buildd-tools-devel mailing list