diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-12-06 23:17:37 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2000-12-06 23:17:37 +0000 |
commit | e29a3c5d83d889887542a5d31fcf51d6d0b0ff02 (patch) | |
tree | 6e0ea07a1546037736c35fed783d67279ed5b56f /init | |
parent | a5f74ed56e067ba3bbaacbe828d5f6b4a9bade65 (diff) | |
download | busybox-w32-e29a3c5d83d889887542a5d31fcf51d6d0b0ff02.tar.gz busybox-w32-e29a3c5d83d889887542a5d31fcf51d6d0b0ff02.tar.bz2 busybox-w32-e29a3c5d83d889887542a5d31fcf51d6d0b0ff02.zip |
Close but #1071...
git-svn-id: svn://busybox.net/trunk/busybox@1389 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'init')
-rw-r--r-- | init/init.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/init/init.c b/init/init.c index 17e605ba0..c4440894c 100644 --- a/init/init.c +++ b/init/init.c | |||
@@ -288,30 +288,27 @@ void set_term(int fd) | |||
288 | tcsetattr(fd, TCSANOW, &tty); | 288 | tcsetattr(fd, TCSANOW, &tty); |
289 | } | 289 | } |
290 | 290 | ||
291 | /* How much memory does this machine have? */ | 291 | /* How much memory does this machine have? |
292 | Units are kBytes to avoid overflow on 4GB machines */ | ||
292 | static int check_free_memory() | 293 | static int check_free_memory() |
293 | { | 294 | { |
294 | struct sysinfo info; | 295 | struct sysinfo info; |
296 | unsigned int result, u, s=10; | ||
295 | 297 | ||
296 | /* Pre initialize mem_unit in case this kernel is something prior to | ||
297 | * the linux 2.4 kernel (which will actually fill in mem_unit... */ | ||
298 | sysinfo(&info); | ||
299 | if (sysinfo(&info) != 0) { | 298 | if (sysinfo(&info) != 0) { |
300 | printf("Error checking free memory: %s\n", strerror(errno)); | 299 | perrorMsg("Error checking free memory: "); |
301 | return -1; | 300 | return -1; |
302 | } | 301 | } |
303 | /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ | 302 | |
304 | if (info.mem_unit==0) { | 303 | /* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes. |
305 | info.mem_unit=1; | 304 | * Kernels 2.4.0 return info.mem_unit in bytes. */ |
306 | } | 305 | u = info.mem_unit; |
307 | info.mem_unit*=1024; | 306 | if (u==0) u=1; |
308 | 307 | while ( (u&1) == 0 && s > 0 ) { u>>=1; s--; } | |
309 | /* Note: These values can in theory overflow a 32 bit unsigned long (i.e. | 308 | result = (info.totalram>>s) + (info.totalswap>>s); |
310 | * mem >= Gib), but who puts more then 4GiB ram+swap on an embedded | 309 | result = result*u; |
311 | * system? */ | 310 | if (result < 0) result = INT_MAX; |
312 | info.totalram/=info.mem_unit; | 311 | return result; |
313 | info.totalswap/=info.mem_unit; | ||
314 | return(info.totalram+info.totalswap); | ||
315 | } | 312 | } |
316 | 313 | ||
317 | static void console_init() | 314 | static void console_init() |