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

Re: patch for wanna-build (sysinfo/getloadavg)



Robert Millan <zeratul2@wanadoo.es> writes:

> Some days ago I posted this small patch for building wanna-build on
> GNU, and asked for revision, but didn't get any response.
>
> It attempts to replace the linux-specific sysinfo() with getloadavg(),
> but there's a type conversion issue and i'd like to make sure i did it
> correctly, please could anyone verify this:
>
> --- wanna-build.old/buildd-mail-wrapper.c	1999-07-21 14:53:22.000000000 +0200
> +++ wanna-build/buildd-mail-wrapper.c	2003-07-15 21:06:59.000000000 +0200
> @@ -37,6 +37,13 @@
>  #include <time.h>
>  #include <dirent.h>
>  #include <sys/sysinfo.h>
> +#ifndef SI_LOAD_SHIFT
> +#define SI_LOAD_SHIFT 16
> +#endif
> +#include <limits.h> /* LONG_MAX */
> +#ifndef LONG_MAX
> +#define LONG_MAX sysconf (_SC_LONG_MAX);
> +#endif
>  #include <sys/types.h>
>  #include <signal.h>
>  
> @@ -164,10 +171,15 @@
>  	 * mailer-running yet. So, in this case, wait some time and then check for
>  	 * mailer-running again. */
>  	if (!dir_was_empty) {
> -		struct sysinfo info;
>  		int waittime;
> -		sysinfo( &info );
> -		waittime = (info.loads[0] >> (SI_LOAD_SHIFT-2))*6 + 20;
> +		double loadavg[0];
                              ^^^ You can't use a zero-sized array; should be 1
> +		long load;
> +		getloadavg (loadavg, 1);
> +		if (loadavg[0] > LONG_MAX)
                                 ^^ (double) LONG_MAX

> +			load = LONG_MAX;
> +		else
> +			load = (long) loadavg[0];
> +		waittime = (load >> (SI_LOAD_SHIFT-2))*6 + 20;

This seems rather complex!  Why not just do something like:
                waittime = (long) (loadavg[0] / 16384) * 6 + 20;

If you don't need SI_LOAD_SHIFT (Linux-specific??), it can probably be
even simpler.

>  		DPRINTF( "dir was not empty, sleeping\nload*4=%d waittime=%d\n",
>  				 (waittime-20)/6, waittime );
>  		sleep( waittime );

I'll add the fix to my local buildd CVS and buildd packages.


Thanks,
Roger

-- 
Roger Leigh

                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                GPG Public Key: 0x25BFB848 available on public keyservers



Reply to: