Close but #1071...
This commit is contained in:
parent
bfa54143f6
commit
bc5941a540
29
init.c
29
init.c
@ -288,30 +288,27 @@ void set_term(int fd)
|
|||||||
tcsetattr(fd, TCSANOW, &tty);
|
tcsetattr(fd, TCSANOW, &tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* How much memory does this machine have? */
|
/* How much memory does this machine have?
|
||||||
|
Units are kBytes to avoid overflow on 4GB machines */
|
||||||
static int check_free_memory()
|
static int check_free_memory()
|
||||||
{
|
{
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
|
unsigned int result, u, s=10;
|
||||||
|
|
||||||
/* 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) {
|
if (sysinfo(&info) != 0) {
|
||||||
printf("Error checking free memory: %s\n", strerror(errno));
|
perrorMsg("Error checking free memory: ");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
|
|
||||||
if (info.mem_unit==0) {
|
|
||||||
info.mem_unit=1;
|
|
||||||
}
|
|
||||||
info.mem_unit*=1024;
|
|
||||||
|
|
||||||
/* Note: These values can in theory overflow a 32 bit unsigned long (i.e.
|
/* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes.
|
||||||
* mem >= Gib), but who puts more then 4GiB ram+swap on an embedded
|
* Kernels 2.4.0 return info.mem_unit in bytes. */
|
||||||
* system? */
|
u = info.mem_unit;
|
||||||
info.totalram/=info.mem_unit;
|
if (u==0) u=1;
|
||||||
info.totalswap/=info.mem_unit;
|
while ( (u&1) == 0 && s > 0 ) { u>>=1; s--; }
|
||||||
return(info.totalram+info.totalswap);
|
result = (info.totalram>>s) + (info.totalswap>>s);
|
||||||
|
result = result*u;
|
||||||
|
if (result < 0) result = INT_MAX;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void console_init()
|
static void console_init()
|
||||||
|
29
init/init.c
29
init/init.c
@ -288,30 +288,27 @@ void set_term(int fd)
|
|||||||
tcsetattr(fd, TCSANOW, &tty);
|
tcsetattr(fd, TCSANOW, &tty);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* How much memory does this machine have? */
|
/* How much memory does this machine have?
|
||||||
|
Units are kBytes to avoid overflow on 4GB machines */
|
||||||
static int check_free_memory()
|
static int check_free_memory()
|
||||||
{
|
{
|
||||||
struct sysinfo info;
|
struct sysinfo info;
|
||||||
|
unsigned int result, u, s=10;
|
||||||
|
|
||||||
/* 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) {
|
if (sysinfo(&info) != 0) {
|
||||||
printf("Error checking free memory: %s\n", strerror(errno));
|
perrorMsg("Error checking free memory: ");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
/* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */
|
|
||||||
if (info.mem_unit==0) {
|
|
||||||
info.mem_unit=1;
|
|
||||||
}
|
|
||||||
info.mem_unit*=1024;
|
|
||||||
|
|
||||||
/* Note: These values can in theory overflow a 32 bit unsigned long (i.e.
|
/* Kernels 2.0.x and 2.2.x return info.mem_unit==0 with values in bytes.
|
||||||
* mem >= Gib), but who puts more then 4GiB ram+swap on an embedded
|
* Kernels 2.4.0 return info.mem_unit in bytes. */
|
||||||
* system? */
|
u = info.mem_unit;
|
||||||
info.totalram/=info.mem_unit;
|
if (u==0) u=1;
|
||||||
info.totalswap/=info.mem_unit;
|
while ( (u&1) == 0 && s > 0 ) { u>>=1; s--; }
|
||||||
return(info.totalram+info.totalswap);
|
result = (info.totalram>>s) + (info.totalswap>>s);
|
||||||
|
result = result*u;
|
||||||
|
if (result < 0) result = INT_MAX;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void console_init()
|
static void console_init()
|
||||||
|
Loading…
Reference in New Issue
Block a user