diff options
author | Benoît Dejean <bdejean@gmail.com> | 2017-01-21 09:49:22 +0100 |
---|---|---|
committer | Benoît Dejean <bdejean@gmail.com> | 2017-01-22 10:45:26 +0100 |
commit | b0ab056e99d83246475ef097dd27c04fafd49d70 (patch) | |
tree | 95d134afa836f31999e8287e8982f375f6b488b2 | |
parent | d2bc9b4331db925ed31c5a220dd39ebea6254d91 (diff) | |
download | libgtop-b0ab056e99d83246475ef097dd27c04fafd49d70.tar.gz |
Use a dynamically allocated buffer to read /proc/cpuinfo to handle computers
with a lot of CPUs.
https://bugzilla.gnome.org/show_bug.cgi?id=323354
-rw-r--r-- | sysdeps/linux/sysinfo.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/sysdeps/linux/sysinfo.c b/sysdeps/linux/sysinfo.c index bd80b0db..99d8fcc5 100644 --- a/sysdeps/linux/sysinfo.c +++ b/sysdeps/linux/sysinfo.c @@ -36,16 +36,20 @@ static glibtop_sysinfo sysinfo = { .flags = 0 }; static void init_sysinfo (glibtop *server) { - char buffer [65536]; + char* buffer; gchar ** processors; if(G_LIKELY(sysinfo.flags)) return; - file_to_buffer(server, buffer, sizeof buffer, FILENAME); + if (!g_file_get_contents(FILENAME, &buffer, NULL, NULL)) { + glibtop_error_io_r(server, "g_file_get_contents(%s)", FILENAME); + } /* cpuinfo records are seperated by a blank line */ processors = g_strsplit(buffer, "\n\n", 0); + g_free(buffer); + for(sysinfo.ncpu = 0; sysinfo.ncpu < GLIBTOP_NCPU && processors[sysinfo.ncpu] && *processors[sysinfo.ncpu]; sysinfo.ncpu++) { |