summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ce185d1)
raw | patch | inline | side by side (parent: ce185d1)
author | campbellsean@google.com <campbellsean@google.com> | |
Fri, 6 Oct 2017 17:44:38 +0000 (13:44 -0400) | ||
committer | campbellsean@google.com <campbellsean@google.com> | |
Fri, 6 Oct 2017 17:44:38 +0000 (13:44 -0400) |
src/daemon/collectd.c | patch | blob | history | |
src/daemon/globals.c | patch | blob | history | |
src/daemon/globals.h | patch | blob | history |
diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c
index 5dfe7c34bcb64ca4e60ea3639d1c7b8712366183..8f671b35398a9a91221959e317ad5cc849aeffdc 100644 (file)
--- a/src/daemon/collectd.c
+++ b/src/daemon/collectd.c
str = global_option_get("Hostname");
if ((str != NULL) && (str[0] != 0)) {
- sstrncpy(hostname_g, str, hostname_g_size);
+ hostname_set(str);
return 0;
}
- if (gethostname(hostname_g, hostname_g_size) != 0) {
+ if (gethostname(hostname_g, sizeof(hostname_g)) != 0) {
fprintf(stderr, "`gethostname' failed and no "
"hostname was configured.\n");
return -1;
if (ai_ptr->ai_canonname == NULL)
continue;
- sstrncpy(hostname_g, ai_ptr->ai_canonname, hostname_g_size);
+ hostname_set(ai_ptr->ai_canonname);
break;
}
diff --git a/src/daemon/globals.c b/src/daemon/globals.c
index 398e2dd204bb8af5dd5f3f89e712de433b4da84c..bde7eb222cd58654c85b257329029a2b1676d2e7 100644 (file)
--- a/src/daemon/globals.c
+++ b/src/daemon/globals.c
* DEALINGS IN THE SOFTWARE.
**/
+#include "common.h"
#include "globals.h"
#include "plugin.h"
-/*
- * Global variables
- */
-char hostname_g[DATA_MAX_NAME_LEN];
-const int hostname_g_size = sizeof (hostname_g);
+
+void hostname_set(char const *hostname) {
+ sstrncpy(hostname_g, hostname, sizeof(hostname_g));
+}
+
+char *hostname_g;
cdtime_t interval_g;
int pidfile_from_cli = 0;
int timeout_g;
diff --git a/src/daemon/globals.h b/src/daemon/globals.h
index 9ccac582260007361ca38d355a593c55d3064530..58700316343e4142f9d29ddc2755b1239793e503 100644 (file)
--- a/src/daemon/globals.h
+++ b/src/daemon/globals.h
/* Type for time as used by "utils_time.h" */
typedef uint64_t cdtime_t;
-extern char hostname_g[];
-extern const int hostname_g_size;
+/* hostname_set updates hostname_g */
+void hostname_set(char const *hostname);
+
+extern char *hostname_g;
extern cdtime_t interval_g;
extern int pidfile_from_cli;
extern int timeout_g;