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;
}
* 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;
/* 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;