autodetect hostname
This commit is contained in:
parent
b6363621ab
commit
c081bf6112
10
probe.c
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) {
|
||||
|
@ -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);
|
||||
|
@ -1,5 +1,5 @@
|
||||
[global]
|
||||
hostname localhost
|
||||
#hostname localhost
|
||||
|
||||
#listen 127.0.0.1:5000
|
||||
#forward 127.0.0.1:5000
|
||||
|
Loading…
Reference in New Issue
Block a user