[Buildd-tools-devel] Bug#511095: unportable use of sysinfo()
Robert Millan
rmh at aybabtu.com
Wed Jan 7 12:44:05 UTC 2009
Package: sbuild
Severity: normal
Hi,
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.
-- System Information:
Debian Release: 5.0
APT prefers unstable
APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)
Kernel: Linux 2.6.18-6-amd64 (SMP w/2 CPU cores)
Locale: LANG=ca_AD.UTF-8, LC_CTYPE=ca_AD.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
-------------- next part --------------
A non-text attachment was scrubbed...
Name: sysinfo.c
Type: text/x-c
Size: 328 bytes
Desc: not available
Url : http://lists.alioth.debian.org/pipermail/buildd-tools-devel/attachments/20090107/b8e29851/attachment.bin
More information about the Buildd-tools-devel
mailing list