From 9afaf4d09f0a13681cfaeaaf3f41ded3a1d53dee Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 15 Jan 2007 14:00:10 +0100 Subject: [PATCH] src/plugin.[ch]: Store the hostname in a global variable to minimize calls to `gethostname'. --- src/load.c | 8 +------- src/nfs.c | 8 +------- src/plugin.c | 7 +++++++ src/plugin.h | 2 ++ src/traffic.c | 9 +-------- 5 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/load.c b/src/load.c index 2cc761b6..3e60a43c 100644 --- a/src/load.c +++ b/src/load.c @@ -69,13 +69,7 @@ static void load_submit (double snum, double mnum, double lnum) vl.values = values; vl.values_len = 3; vl.time = time (NULL); - /* FIXME: do this globally */ - if (gethostname (vl.host, sizeof (vl.host)) != 0) - { - syslog (LOG_ERR, "load plugin: gethostname failed: %s", - strerror (errno)); - return; - } + strcpy (vl.host, hostname); strcpy (vl.plugin, "load"); strcpy (vl.plugin_instance, ""); strcpy (vl.type_instance, ""); diff --git a/src/nfs.c b/src/nfs.c index d6e85168..f585b974 100644 --- a/src/nfs.c +++ b/src/nfs.c @@ -205,13 +205,7 @@ static void nfs_procedures_submit (const char *plugin_instance, vl.values = values; vl.values_len = 1; vl.time = time (NULL); - /* FIXME: do this globally */ - if (gethostname (vl.host, sizeof (vl.host)) != 0) - { - syslog (LOG_ERR, "load plugin: gethostname failed: %s", - strerror (errno)); - return; - } + strcpy (vl.host, hostname); strcpy (vl.plugin, "nfs"); strncpy (vl.plugin_instance, plugin_instance, sizeof (vl.plugin_instance)); diff --git a/src/plugin.c b/src/plugin.c index 857643d0..b40d62a1 100644 --- a/src/plugin.c +++ b/src/plugin.c @@ -39,6 +39,8 @@ static llist_t *list_data_set; static char *plugindir = NULL; +char hostname[DATA_MAX_NAME_LEN] = "localhost"; + /* * Static functions */ @@ -238,6 +240,8 @@ void plugin_init_all (void) int (*callback) (void); llentry_t *le; + gethostname (hostname, sizeof (hostname)); + if (list_init == NULL) return; @@ -298,7 +302,10 @@ int plugin_dispatch_values (const char *name, const value_list_t *vl) le = llist_search (list_data_set, name); if (le == NULL) + { + DBG ("No such dataset registered: %s", name); return (-1); + } ds = (data_set_t *) le->value; diff --git a/src/plugin.h b/src/plugin.h index 3b94ff71..107078e7 100644 --- a/src/plugin.h +++ b/src/plugin.h @@ -77,6 +77,8 @@ typedef struct complain_s unsigned int delay; /* how many more iterations we still need to wait */ } complain_t; +extern char hostname[DATA_MAX_NAME_LEN]; + /* * NAME * plugin_set_dir diff --git a/src/traffic.c b/src/traffic.c index 59b59e83..5c5e4f74 100644 --- a/src/traffic.c +++ b/src/traffic.c @@ -237,14 +237,7 @@ static void if_submit (const char *dev, const char *type, vl.values = values; vl.values_len = 2; vl.time = time (NULL); - - /* FIXME: do this globally */ - if (gethostname (vl.host, sizeof (vl.host)) != 0) - { - syslog (LOG_ERR, "load plugin: gethostname failed: %s", - strerror (errno)); - return; - } + strcpy (vl.host, hostname); strcpy (vl.plugin, "interface"); strcpy (vl.plugin_instance, ""); strncpy (vl.type_instance, dev, sizeof (vl.type_instance)); -- 2.11.0