From b0ab056e99d83246475ef097dd27c04fafd49d70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Sat, 21 Jan 2017 09:49:22 +0100 Subject: [PATCH] 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 --- sysdeps/linux/sysinfo.c | 8 ++++++-- 1 file 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++) {