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
#include <stdio.h>
#include <math.h>
#include <sys/sysinfo.h>

main ()
{
  struct sysinfo info;
  double loadavg;

  sysinfo( &info );
  getloadavg (&loadavg, 1);

  printf ("waittime1 = %d\n", (int) (info.loads[0] >> (SI_LOAD_SHIFT - 2)));
  printf ("waittime2 = %d\n", ((int) loadavg) << 2 | (int) (fmod (loadavg, 1) * 4));
}

Reply via email to