[BusyBox] init: sysinfo [PATCH]

Shaun Jackman sjackman at gmail.com
Tue Jul 5 01:40:42 UTC 2005


init uses sysinfo to check if the amount of memory is less than one
megabyte, and if so attempts to swapon.

According to the sysinfo(2) man page...
       This function is Linux-specific, and should not be  used  in  pro-
       grams intended to be portable.

So I suggest armouring its use in an ifdef. I used ifdef
_LINUX_TYPES_H, but I'd like to hear any suggestions of a better test.

I find altering the behaviour of init based on the amount of installed
memory a bit of a hack though. I'd rather see check_memory removed
altogether. If the swapon functionality of init is useful to people,
perhaps a swapon switch to init would be called for.

Cheers,
Shaun

--- init/init.c
+++ init/init.c
@@ -312,6 +312,7 @@
    Units are kBytes to avoid overflow on 4GB machines */
 static unsigned int check_free_memory(void)
 {
+#ifdef _LINUX_TYPES_H
 	struct sysinfo info;
 	unsigned int result, u, s = 10;
 
@@ -335,6 +336,11 @@
 	} else {
 		return(result * u);
 	}
+#else
+	// check_memory attempts to swapon if there's less than a megabyte
+	// of free memory, so tell it we have more than that.
+	return 1001;
+#endif /* _LINUX_TYPES_H */
 }
 
 static void console_init(void)



More information about the busybox mailing list