summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7381780)
raw | patch | inline | side by side (parent: 7381780)
author | Sean Campbell <campbellsean@campbellsean-cloudtop.c.googlers.com> | |
Fri, 6 Oct 2017 20:55:37 +0000 (16:55 -0400) | ||
committer | Sean Campbell <campbellsean@campbellsean-cloudtop.c.googlers.com> | |
Fri, 6 Oct 2017 20:55:37 +0000 (16:55 -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 8f671b35398a9a91221959e317ad5cc849aeffdc..278453955a338cd4095fe59e7fc64e34942f49dd 100644 (file)
--- a/src/daemon/collectd.c
+++ b/src/daemon/collectd.c
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;
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;
}
diff --git a/src/daemon/globals.c b/src/daemon/globals.c
index 652ff06dad8fdd271881149c75b7b2005d0f60cc..2222a5ce8b9e8f53e69319324219c3a35fa3212d 100644 (file)
--- a/src/daemon/globals.c
+++ b/src/daemon/globals.c
/**
* collectd - src/globals.c
- * Copyright (C) 2017 Florian octo Forster
+ * Copyright (C) 2017 Google LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
#endif
void hostname_set(char const *hostname) {
- sstrncpy(hostname_g, hostname, sizeof(hostname_g));
+ char *h = strdup(hostname);
+ if (h == NULL)
+ return;
+
+ free(hostname_g);
+ hostname_g = h;
}
/*
diff --git a/src/daemon/globals.h b/src/daemon/globals.h
index b91ccc82ddfd5f65d59c388d431c0ab865ff5d4c..587b223b9c08aa3ff4e69d37d3e53fbff9cf128a 100644 (file)
--- a/src/daemon/globals.h
+++ b/src/daemon/globals.h
/**
* collectd - src/globals.h
- * Copyright (C) 2017 Florian octo Forster
+ * Copyright (C) 2017 Google LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),