From 10dc9d4d17e6880bfdfd253716ce72ec1243227f Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 26 Jun 2000 10:45:52 +0000 Subject: Updates to handle Linux 2.4.0 kernels (kludged around the "none" entries in /proc/mounts, added a hack to make sysinfo work with both old and new kernels). -Erik --- init/init.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'init') diff --git a/init/init.c b/init/init.c index 98a58f275..9289b86a6 100644 --- a/init/init.c +++ b/init/init.c @@ -42,7 +42,6 @@ #include #include #include -#include /* For check_free_memory() */ #include #include #include @@ -270,13 +269,28 @@ static int check_free_memory() { struct sysinfo info; + /* Pre initialize mem_unit in case this kernel is something prior to + * the linux 2.4 kernel (which will actually fill in mem_unit... */ sysinfo(&info); if (sysinfo(&info) != 0) { - message(LOG, "Error checking free memory: %s\n", strerror(errno)); + printf("Error checking free memory: %s\n", strerror(errno)); return -1; } + if (info.mem_unit==0) { + /* Looks like we have a kernel prior to Linux 2.4.x */ + info.mem_unit=1024; + info.totalram/=info.mem_unit; + info.totalswap/=info.mem_unit; + } else { + /* Bah. Linux 2.4.x completely changed sysinfo. This can in theory + overflow a 32 bit unsigned long, but who puts more then 4GiB ram+swap + on an embedded system? */ + info.mem_unit/=1024; + info.totalram*=info.mem_unit; + info.totalswap*=info.mem_unit; + } - return((info.totalram+info.totalswap)/1024); + return(info.totalram+info.totalswap); } static void console_init() -- cgit v1.2.3