From d497c250814a2069aba60caee36e2ced31d68344 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Dejean?= Date: Thu, 27 Jul 2006 09:23:32 +0000 Subject: [PATCH] New has_sysfs function to avoid stating over and over '/sys' on each MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 2006-07-27 Benoît Dejean * 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. --- sysdeps/linux/ChangeLog | 10 ++++++++++ sysdeps/linux/glibtop_private.c | 15 +++++++++++++++ sysdeps/linux/glibtop_private.h | 4 ++++ sysdeps/linux/netload.c | 2 +- sysdeps/linux/open.c | 2 +- 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/sysdeps/linux/ChangeLog b/sysdeps/linux/ChangeLog index 2d54f098..ee6fc7b7 100644 --- a/sysdeps/linux/ChangeLog +++ b/sysdeps/linux/ChangeLog @@ -1,3 +1,13 @@ +2006-07-27 Benoît Dejean + + * 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 * msg_limits.c: (glibtop_get_msg_limits_s): diff --git a/sysdeps/linux/glibtop_private.c b/sysdeps/linux/glibtop_private.c index 1ae9e8a0..490e1728 100644 --- a/sysdeps/linux/glibtop_private.c +++ b/sysdeps/linux/glibtop_private.c @@ -163,3 +163,18 @@ check_cpu_line(glibtop *server, const char *line, unsigned i) 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; +} diff --git a/sysdeps/linux/glibtop_private.h b/sysdeps/linux/glibtop_private.h index 2f01d793..30f53960 100644 --- a/sysdeps/linux/glibtop_private.h +++ b/sysdeps/linux/glibtop_private.h @@ -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 #endif /* __LINUX__GLIBTOP_PRIVATE_H__ */ diff --git a/sysdeps/linux/netload.c b/sysdeps/linux/netload.c index 44bd8e6f..0e329f12 100644 --- a/sysdeps/linux/netload.c +++ b/sysdeps/linux/netload.c @@ -541,7 +541,7 @@ glibtop_get_netload_s (glibtop *server, glibtop_netload *buf, linux_2_0_stats(server, buf, interface); } 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); } else { diff --git a/sysdeps/linux/open.c b/sysdeps/linux/open.c index 37fcb793..5930dc53 100644 --- a/sysdeps/linux/open.c +++ b/sysdeps/linux/open.c @@ -50,7 +50,7 @@ static void set_linux_version(glibtop *server) uts.release, x, y, z, 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)) + && !has_sysfs()) glibtop_warn_r(server, "You're running a 2.6 kernel without /sys." "You should mount it.");