summaryrefslogtreecommitdiffstats
path: root/daemon
diff options
context:
space:
mode:
authorIlya Mashchenko <ilya@netdata.cloud>2023-11-16 17:09:06 +0200
committerGitHub <noreply@github.com>2023-11-16 17:09:06 +0200
commit5344c11728dfcd427ca6f5561f701b8680dd9598 (patch)
treeaf4a4843285cdcb5f4b7b6fd6328b5d74f2bed68 /daemon
parentcd82944a89f32e00951fa4a6e4b3a75ec08cfc1d (diff)
docker: use /host/etc/hostname if mounted (#16401)
Diffstat (limited to 'daemon')
-rw-r--r--daemon/main.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/daemon/main.c b/daemon/main.c
index 9e237c8510..cf701b3ce0 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -1054,16 +1054,32 @@ static void backwards_compatible_config() {
}
+static int get_hostname(char *buf, size_t buf_size) {
+ if (netdata_configured_host_prefix && *netdata_configured_host_prefix) {
+ char filename[FILENAME_MAX + 1];
+ snprintfz(filename, FILENAME_MAX, "%s/etc/hostname", netdata_configured_host_prefix);
+
+ if (!read_file(filename, buf, buf_size)) {
+ trim(buf);
+ return 0;
+ }
+ }
+
+ return gethostname(buf, buf_size);
+}
+
static void get_netdata_configured_variables() {
backwards_compatible_config();
// ------------------------------------------------------------------------
// get the hostname
+ netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", "");
+ verify_netdata_host_prefix();
+
char buf[HOSTNAME_MAX + 1];
- if(gethostname(buf, HOSTNAME_MAX) == -1){
+ if (get_hostname(buf, HOSTNAME_MAX))
netdata_log_error("Cannot get machine hostname.");
- }
netdata_configured_hostname = config_get(CONFIG_SECTION_GLOBAL, "hostname", buf);
netdata_log_debug(D_OPTIONS, "hostname set to '%s'", netdata_configured_hostname);
@@ -1163,10 +1179,6 @@ static void get_netdata_configured_variables() {
default_rrd_memory_mode = RRD_MEMORY_MODE_SAVE;
}
#endif
- // ------------------------------------------------------------------------
-
- netdata_configured_host_prefix = config_get(CONFIG_SECTION_GLOBAL, "host access prefix", "");
- verify_netdata_host_prefix();
// --------------------------------------------------------------------
// get KSM settings