Adds setter for hostname_g and eliminates hostname_g_size variable.
authorcampbellsean@google.com <campbellsean@google.com>
Fri, 6 Oct 2017 17:44:38 +0000 (13:44 -0400)
committercampbellsean@google.com <campbellsean@google.com>
Fri, 6 Oct 2017 17:44:38 +0000 (13:44 -0400)
src/daemon/collectd.c
src/daemon/globals.c
src/daemon/globals.h

index 5dfe7c3..8f671b3 100644 (file)
@@ -83,11 +83,11 @@ static int init_hostname(void) {
 
   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;
@@ -115,7 +115,7 @@ static int init_hostname(void) {
     if (ai_ptr->ai_canonname == NULL)
       continue;
 
-    sstrncpy(hostname_g, ai_ptr->ai_canonname, hostname_g_size);
+    hostname_set(ai_ptr->ai_canonname);
     break;
   }
 
index 398e2dd..bde7eb2 100644 (file)
  * 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;
index 9ccac58..5870031 100644 (file)
 /* 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;