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

Re: missing sysinfo () and SI_LOAD_SHIFT



On Mon, Jul 14, 2003 at 03:44:56PM -0400, Roland McGrath wrote:
> getloadavg is what everything should use to get the load average.

I made a patch to use getloadavg, but it's a bit weird as i had to do
double->long conversion and it isn't very clear what the SI_LOAD_SHIFT
undocumented kernel Linux macro is suposed to do.

Anyway, i'd appreciate if someone more clued reviewed it:

--- 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];
+		long load;
+		getloadavg (loadavg, 1);
+		if (loadavg[0] > LONG_MAX)
+			load = LONG_MAX;
+		else
+			load = (long) loadavg[0];
+		waittime = (load >> (SI_LOAD_SHIFT-2))*6 + 20;
 		DPRINTF( "dir was not empty, sleeping\nload*4=%d waittime=%d\n",
 				 (waittime-20)/6, waittime );
 		sleep( waittime );

-- 
Robert Millan



Reply to: