X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdaemon%2Fcollectd.c;h=140e7ccece37db4e5a04b9b2e4decabb1ee2aa30;hp=791199ffb6302a8968749a23bedb677cd1d93f12;hb=da11ce02eb202b3e01d3e2d1b40f248a84430973;hpb=31ccd1103fadf7d1a6109252ca24f1ecb4d704ed diff --git a/src/daemon/collectd.c b/src/daemon/collectd.c index 791199ff..140e7cce 100644 --- a/src/daemon/collectd.c +++ b/src/daemon/collectd.c @@ -43,6 +43,10 @@ #include #endif +#if HAVE_KSTAT_H +#include +#endif + #ifndef COLLECTD_LOCALE #define COLLECTD_LOCALE "C" #endif @@ -76,23 +80,17 @@ static void sig_usr1_handler(int __attribute__((unused)) signal) { } static int init_hostname(void) { - const char *str; - - struct addrinfo *ai_list; - int status; + const char *str = global_option_get("Hostname"); + if ((str != NULL) && (str[0] != 0)) { + hostname_set(str); + return 0; + } 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, hostname_len) != 0) { fprintf(stderr, "`gethostname' failed and no " @@ -100,13 +98,16 @@ static int init_hostname(void) { return -1; } + hostname_set(hostname); + str = global_option_get("FQDNLookup"); if (IS_FALSE(str)) return 0; + struct addrinfo *ai_list; struct addrinfo ai_hints = {.ai_flags = AI_CANONNAME}; - status = getaddrinfo(hostname, NULL, &ai_hints, &ai_list); + int 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 " @@ -211,6 +212,7 @@ static int change_basedir(const char *orig_dir, _Bool create) { } /* static int change_basedir (char *dir) */ #if HAVE_LIBKSTAT +extern kstat_ctl_t *kc; static void update_kstat(void) { if (kc == NULL) { if ((kc = kstat_open()) == NULL) @@ -464,12 +466,11 @@ void read_cmdline(int argc, char **argv, struct cmdline_config *config) { /* read options */ while (1) { int c; - c = getopt(argc, argv, - "htTC:" + c = getopt(argc, argv, "BhtTC:" #if COLLECT_DAEMON - "fP:" + "fP:" #endif - ); + ); if (c == -1) break; @@ -554,9 +555,7 @@ int main(int argc, char **argv) { int exit_status = 0; struct cmdline_config config = { - .daemonize = 1, - .create_basedir = 1, - .configfile = CONFIGFILE, + .daemonize = 1, .create_basedir = 1, .configfile = CONFIGFILE, }; read_cmdline(argc, argv, &config); @@ -589,7 +588,7 @@ int main(int argc, char **argv) { #ifdef KERNEL_LINUX && notify_upstart() == 0 && notify_systemd() == 0 #endif - ) { + ) { int status; if ((pid = fork()) == -1) {