]> arthur.barton.de Git - netdata.git/blobdiff - src/main.c
build: migrate to autotools
[netdata.git] / src / main.c
index 2f4e2a91cb50ed4e1c5ffd3b3eaf69a8c7792a18..138277df4645654033ef89fca7a0870f5de728be 100755 (executable)
@@ -1,3 +1,6 @@
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <sys/time.h>
+#include <sys/resource.h>
 
 #include "common.h"
 #include "log.h"
 #include "daemon.h"
 #include "web_server.h"
 #include "popen.h"
-#include "config.h"
+#include "appconfig.h"
 #include "web_client.h"
 #include "rrd.h"
 #include "rrd2json.h"
@@ -168,6 +173,9 @@ int main(int argc, char **argv)
        int config_loaded = 0;
        int dont_fork = 0;
 
+       // global initialization
+       get_HZ();
+
        // set the name for logging
        program_name = "netdata";
 
@@ -220,7 +228,7 @@ int main(int argc, char **argv)
                        fprintf(stderr, "  -u USERNAME can be any system username to run as. Default: none.\n");
                        fprintf(stderr, "  -ch path to access host /proc and /sys when running in a container. Default: empty.\n");
                        fprintf(stderr, "  -nd or -nodeamon to disable forking in the background. Default: unset.\n");
-                       fprintf(stderr, "  -df FLAGS debug options. Default: 0x%8llx.\n", debug_flags);
+                       fprintf(stderr, "  -df FLAGS debug options. Default: 0x%08llx.\n", debug_flags);
                        exit(1);
                }
        }
@@ -241,6 +249,12 @@ int main(int argc, char **argv)
                debug_flags = strtoull(flags, NULL, 0);
                debug(D_OPTIONS, "Debug flags set to '0x%8llx'.", debug_flags);
 
+               if(debug_flags != 0) {
+                       struct rlimit rl = { RLIM_INFINITY, RLIM_INFINITY };
+                       if(setrlimit(RLIMIT_CORE, &rl) != 0)
+                               info("Cannot request unlimited core dumps for debugging... Proceeding anyway...");
+               }
+
                // --------------------------------------------------------------------
 
                global_host_prefix = config_get("global", "host access prefix", "");
@@ -329,7 +343,7 @@ int main(int argc, char **argv)
                // --------------------------------------------------------------------
 
                prepare_rundir();
-               char *user = config_get("global", "run as user", (getuid() == 0)?"nobody":"");
+               char *user = config_get("global", "run as user", (getuid() == 0)?NETDATA_USER:"");
                if(*user) {
                        if(become_user(user) != 0) {
                                fprintf(stderr, "Cannot become user %s.\n", user);
@@ -368,7 +382,7 @@ int main(int argc, char **argv)
        // never become a problem
        if(nice(20) == -1) fprintf(stderr, "Cannot lower my CPU priority. Error: %s.\n", strerror(errno));
 
-#ifndef NETDATA_NO_DAEMON
+#ifdef NETDATA_DAEMON
        if(become_daemon(dont_fork, 0, input_log_file, output_log_file, error_log_file, access_log_file, &access_fd, &stdaccess) == -1) {
                fprintf(stderr, "Cannot demonize myself (%s).", strerror(errno));
                exit(1);