projects
/
collectd.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Auto-Merge pull request #2784 from rpv-tomsk/fix-5.8
[collectd.git]
/
src
/
daemon
/
collectd.c
diff --git
a/src/daemon/collectd.c
b/src/daemon/collectd.c
index
5dfe7c3
..
9ec0934
100644
(file)
--- a/
src/daemon/collectd.c
+++ b/
src/daemon/collectd.c
@@
-76,37
+76,41
@@
static void sig_usr1_handler(int __attribute__((unused)) signal) {
}
static int init_hostname(void) {
}
static int init_hostname(void) {
- const char *str;
-
- struct addrinfo *ai_list;
- int status;
-
- str = global_option_get("Hostname");
+ const char *str = global_option_get("Hostname");
if ((str != NULL) && (str[0] != 0)) {
if ((str != NULL) && (str[0] != 0)) {
-
sstrncpy(hostname_g, str, hostname_g_size
);
+
hostname_set(str
);
return 0;
}
return 0;
}
- if (gethostname(hostname_g, hostname_g_size) != 0) {
+ long hostname_len = sysconf(_SC_HOST_NAME_MAX);
+ if (hostname_len == -1) {
+ hostname_len = NI_MAXHOST;
+ }
+ char hostname[hostname_len];
+
+ if (gethostname(hostname, hostname_len) != 0) {
fprintf(stderr, "`gethostname' failed and no "
"hostname was configured.\n");
return -1;
}
fprintf(stderr, "`gethostname' failed and no "
"hostname was configured.\n");
return -1;
}
+ hostname_set(hostname);
+
str = global_option_get("FQDNLookup");
if (IS_FALSE(str))
return 0;
str = global_option_get("FQDNLookup");
if (IS_FALSE(str))
return 0;
+ struct addrinfo *ai_list;
struct addrinfo ai_hints = {.ai_flags = AI_CANONNAME};
struct addrinfo ai_hints = {.ai_flags = AI_CANONNAME};
-
status = getaddrinfo(hostname_g
, NULL, &ai_hints, &ai_list);
+
int status = getaddrinfo(hostname
, NULL, &ai_hints, &ai_list);
if (status != 0) {
ERROR("Looking up \"%s\" failed. You have set the "
"\"FQDNLookup\" option, but I cannot resolve "
"my hostname to a fully qualified domain "
"name. Please fix the network "
"configuration.",
if (status != 0) {
ERROR("Looking up \"%s\" failed. You have set the "
"\"FQDNLookup\" option, but I cannot resolve "
"my hostname to a fully qualified domain "
"name. Please fix the network "
"configuration.",
- hostname
_g
);
+ hostname);
return -1;
}
return -1;
}
@@
-115,7
+119,7
@@
static int init_hostname(void) {
if (ai_ptr->ai_canonname == NULL)
continue;
if (ai_ptr->ai_canonname == NULL)
continue;
-
sstrncpy(hostname_g, ai_ptr->ai_canonname, hostname_g_siz
e);
+
hostname_set(ai_ptr->ai_canonnam
e);
break;
}
break;
}