X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fdaemon%2Fcollectd.c;h=278453955a338cd4095fe59e7fc64e34942f49dd;hb=69a2285dea4568c0010f116d22415f301b74579a;hp=8f671b35398a9a91221959e317ad5cc849aeffdc;hpb=fa56155c34eed72740d375208a63571d5f9d59e0;p=collectd.git diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index 8f671b35..27845395 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -81,13 +81,20 @@ static int init_hostname(void) { struct addrinfo *ai_list; int status; + long hostname_len = sysconf(_SC_HOST_NAME_MAX); + if (hostname_len == -1) { + hostname_len = NI_MAXHOST; + } + char hostname[hostname_len]; + hostname_set(hostname); + str = global_option_get("Hostname"); if ((str != NULL) && (str[0] != 0)) { hostname_set(str); return 0; } - if (gethostname(hostname_g, sizeof(hostname_g)) != 0) { + if (gethostname(hostname, hostname_len) != 0) { fprintf(stderr, "`gethostname' failed and no " "hostname was configured.\n"); return -1; @@ -99,14 +106,14 @@ static int init_hostname(void) { struct addrinfo ai_hints = {.ai_flags = AI_CANONNAME}; - status = getaddrinfo(hostname_g, NULL, &ai_hints, &ai_list); + 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.", - hostname_g); + hostname); return -1; }