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

patch for wanna-build (sysinfo/getloadavg)



Hi there.

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];
+		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: