From c081bf6112d4583281902015eef14f3f4d78a9e0 Mon Sep 17 00:00:00 2001 From: Olaf Rempel Date: Sun, 11 Jan 2009 23:08:31 +0100 Subject: [PATCH] autodetect hostname --- probe.c | 10 ++++++++-- sammler.c | 3 +-- sammler.conf | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/probe.c b/probe.c index f83231b..29dade7 100644 --- a/probe.c +++ b/probe.c @@ -2,6 +2,7 @@ #include #include #include +#include #include "configfile.h" #include "logging.h" @@ -26,8 +27,13 @@ int probe_init(void) int probe_submit(struct sammler_plugin *plugin, const char *filename, int ds_id, const char *fmt, ... ) { static const char *hostname = NULL; - if (hostname == NULL) - hostname = config_get_string("global", "hostname", "localhost"); + if (hostname == NULL) { + static char hostname_buf[32]; + if (gethostname(hostname_buf, sizeof(hostname_buf)) != 0) + strcpy(hostname_buf, "localhost"); + + hostname = config_get_string("global", "hostname", hostname_buf); + } char *buffer = malloc(BUFSIZE); if (buffer == NULL) { diff --git a/sammler.c b/sammler.c index 455c305..851b00b 100644 --- a/sammler.c +++ b/sammler.c @@ -95,8 +95,7 @@ int main(int argc, char *argv[]) daemon(-1, 0); } - const char *hostname = config_get_string("global", "hostname", "localhost"); - log_print(LOG_EVERYTIME, "sammler (pid:%d) started on host '%s'", getpid(), hostname); + log_print(LOG_EVERYTIME, "sammler (pid:%d)", getpid()); if (probe_init()) exit(1); diff --git a/sammler.conf b/sammler.conf index f14f633..f5a3f76 100644 --- a/sammler.conf +++ b/sammler.conf @@ -1,5 +1,5 @@ [global] -hostname localhost +#hostname localhost #listen 127.0.0.1:5000 #forward 127.0.0.1:5000