From: Michael Tremer Date: Thu, 4 Sep 2014 18:10:55 +0000 (+0200) Subject: installer: use sysinfo() for memory detection X-Git-Tag: v2.17-core87~103^2~51^2~20 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=5be66d81b94352ca230320336002b2c93a46c2d5 installer: use sysinfo() for memory detection --- diff --git a/src/installer/hw.c b/src/installer/hw.c index ba7fda267a..e453e23cbe 100644 --- a/src/installer/hw.c +++ b/src/installer/hw.c @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -502,23 +503,13 @@ struct hw_destination* hw_make_destination(int part_type, struct hw_disk** disks } unsigned long long hw_memory() { - FILE* handle = NULL; - char line[STRING_SIZE]; + struct sysinfo si; - unsigned long long memory = 0; - - /* Calculate amount of memory in machine */ - if ((handle = fopen("/proc/meminfo", "r"))) { - while (fgets(line, sizeof(line), handle)) { - if (!sscanf (line, "MemTotal: %llu kB", &memory)) { - memory = 0; - } - } - - fclose(handle); - } + int r = sysinfo(&si); + if (r < 0) + return 0; - return memory * 1024; + return si.totalram; } static int hw_zero_out_device(const char* path, int bytes) { diff --git a/src/installer/main.c b/src/installer/main.c index d9dd75c2c6..1f7ec2b4ba 100644 --- a/src/installer/main.c +++ b/src/installer/main.c @@ -494,6 +494,7 @@ int main(int argc, char *argv[]) { fprintf(flog, " swap : %s (%lluMB)\n", destination->part_swap, BYTES2MB(destination->size_swap)); fprintf(flog, " root : %s (%lluMB)\n", destination->part_root, BYTES2MB(destination->size_root)); fprintf(flog, " data : %s (%lluMB)\n", destination->part_data, BYTES2MB(destination->size_data)); + fprintf(flog, "Memory : %lluMB\n", BYTES2MB(hw_memory())); // Warn the user if there is not enough space to create a swap partition if (!unattended && !*destination->part_swap) {