New has_sysfs function to avoid stating over and over '/sys' on each

2006-07-27  Benoît Dejean  <benoit@placenet.org>

        * glibtop_private.c: (has_sysfs):
        * glibtop_private.h:
        * netload.c: (glibtop_get_netload_s):
        * open.c: (set_linux_version):

        New has_sysfs function to avoid stating
        over and over '/sys' on each netload call.
This commit is contained in:
Benoît Dejean
2006-07-27 09:23:32 +00:00
committed by Benoît Dejean
parent 3345ef1704
commit d497c25081
5 changed files with 31 additions and 2 deletions

View File

@@ -1,3 +1,13 @@
2006-07-27 Benoît Dejean <benoit@placenet.org>
* glibtop_private.c: (has_sysfs):
* glibtop_private.h:
* netload.c: (glibtop_get_netload_s):
* open.c: (set_linux_version):
New has_sysfs function to avoid stating
over and over '/sys' on each netload call.
2006-04-02 Benoît Dejean <benoit@placenet.org> 2006-04-02 Benoît Dejean <benoit@placenet.org>
* msg_limits.c: (glibtop_get_msg_limits_s): * msg_limits.c: (glibtop_get_msg_limits_s):

View File

@@ -163,3 +163,18 @@ check_cpu_line(glibtop *server, const char *line, unsigned i)
return g_str_has_prefix(line, start); return g_str_has_prefix(line, start);
} }
gboolean
has_sysfs(void)
{
static gboolean init;
static gboolean sysfs;
if (G_UNLIKELY(!init)) {
sysfs = g_file_test("/sys", G_FILE_TEST_IS_DIR);
init = TRUE;
}
return sysfs;
}

View File

@@ -142,6 +142,10 @@ check_cpu_line_warn(glibtop *server, const char *line, unsigned i)
} }
gboolean
has_sysfs(void) G_GNUC_INTERNAL G_GNUC_CONST;
G_END_DECLS G_END_DECLS
#endif /* __LINUX__GLIBTOP_PRIVATE_H__ */ #endif /* __LINUX__GLIBTOP_PRIVATE_H__ */

View File

@@ -541,7 +541,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf,
linux_2_0_stats(server, buf, interface); linux_2_0_stats(server, buf, interface);
} }
else if (server->os_version_code > LINUX_VERSION_CODE(2, 6, 0) else if (server->os_version_code > LINUX_VERSION_CODE(2, 6, 0)
&& g_file_test("/sys", G_FILE_TEST_IS_DIR)) { && has_sysfs()) {
linux_2_6_stats(server, buf, interface); linux_2_6_stats(server, buf, interface);
} }
else { else {

View File

@@ -50,7 +50,7 @@ static void set_linux_version(glibtop *server)
uts.release, x, y, z, LINUX_VERSION_CODE(x,y,z)); uts.release, x, y, z, LINUX_VERSION_CODE(x,y,z));
if (LINUX_VERSION_CODE(x, y, z) >= LINUX_VERSION_CODE(2, 6, 0) if (LINUX_VERSION_CODE(x, y, z) >= LINUX_VERSION_CODE(2, 6, 0)
&& !g_file_test("/sys", G_FILE_TEST_IS_DIR)) && !has_sysfs())
glibtop_warn_r(server, glibtop_warn_r(server,
"You're running a 2.6 kernel without /sys." "You're running a 2.6 kernel without /sys."
"You should mount it."); "You should mount it.");