Browse Source

autodetect hostname

master
Olaf Rempel 14 years ago
parent
commit
c081bf6112
  1. 10
      probe.c
  2. 3
      sammler.c
  3. 2
      sammler.conf

10
probe.c

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <unistd.h>
#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) {

3
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);

2
sammler.conf

@ -1,5 +1,5 @@
[global]
hostname localhost
#hostname localhost
#listen 127.0.0.1:5000
#forward 127.0.0.1:5000

Loading…
Cancel
Save