Reworked a bit. Warn on 2.6 without /sys.

* open.c: (set_linux_version), (glibtop_open_s):

	Reworked a bit.
	Warn on 2.6 without /sys.
This commit is contained in:
Benoît Dejean
2005-08-03 22:39:17 +00:00
parent a0493a0ff1
commit 708285f0d2
2 changed files with 22 additions and 14 deletions

View File

@@ -24,6 +24,7 @@
#include <glibtop.h>
#include <glibtop/cpu.h>
#include <glibtop/open.h>
#include <glibtop/error.h>
#include "glibtop_private.h"
@@ -33,27 +34,27 @@
*/
#include <sys/utsname.h>
static unsigned get_linux_version(void) {
static unsigned linux_version_code = 0;
if(!linux_version_code) {
static void set_linux_version(glibtop *server)
{
struct utsname uts;
unsigned x = 0, y = 0, z = 0; /* cleared in case sscanf() < 3 */
if (uname(&uts) == -1) /* failure most likely implies impending death */
exit(1);
glibtop_error_r(server, "uname() failed");
if (sscanf(uts.release, "%u.%u.%u", &x, &y, &z) < 3)
fprintf(stderr, /* *very* unlikely to happen by accident */
"Non-standard uts for running kernel:\n"
"release %s=%u.%u.%u gives version code %d\n",
uts.release, x, y, z, LINUX_VERSION_CODE(x,y,z));
glibtop_warn_r(server,
"Non-standard uts for running kernel:\n"
"release %s=%u.%u.%u gives version code %d\n",
uts.release, x, y, z, LINUX_VERSION_CODE(x,y,z));
linux_version_code = LINUX_VERSION_CODE(x, y, z);
}
if (LINUX_VERSION_CODE(x, y, z) >= LINUX_VERSION_CODE(2, 6, 0)
&& !g_file_test("/sys", G_FILE_TEST_IS_DIR))
glibtop_warn_r(server,
"You're running a 2.6 kernel without /sys."
"You should mount it.");
return linux_version_code;
server->os_version_code = LINUX_VERSION_CODE(x, y, z);
}
/* ======================================================= */
@@ -71,7 +72,7 @@ glibtop_open_s (glibtop *server, const char *program_name,
server->name = program_name;
server->os_version_code = get_linux_version();
set_linux_version(server);
file_to_buffer(server, buffer, FILENAME);