]> arthur.barton.de Git - netdata.git/blobdiff - src/main.c
Initial "Debianization"
[netdata.git] / src / main.c
index 26bc49f5e6027eb1c69234396b63b33760bdba25..18ad78a8dd0bbdf37cc2488f39d1c3591519f6bc 100644 (file)
@@ -46,8 +46,8 @@ struct netdata_static_thread static_threads[] = {
 #else
     {"proc",               "plugins",   "proc",       1, NULL, NULL, proc_main},
     {"diskspace",          "plugins",   "diskspace",  1, NULL, NULL, proc_diskspace_main},
-#endif /* __FreeBSD__, __APPLE__*/
     {"cgroups",            "plugins",   "cgroups",    1, NULL, NULL, cgroups_main},
+#endif /* __FreeBSD__, __APPLE__*/
     {"check",              "plugins",   "checks",     0, NULL, NULL, checks_main},
     {"backends",            NULL,       NULL,         1, NULL, NULL, backends_main},
     {"health",              NULL,       NULL,         1, NULL, NULL, health_main},
@@ -161,17 +161,19 @@ void kill_childs()
         pthread_cancel(w->thread);
         // it is detached
         // pthread_join(w->thread, NULL);
+
+        w->obsolete = 1;
     }
 
     int i;
     for (i = 0; static_threads[i].name != NULL ; i++) {
-        if(static_threads[i].enabled && static_threads[i].thread) {
+        if(static_threads[i].enabled) {
             info("Stopping %s thread", static_threads[i].name);
             pthread_cancel(*static_threads[i].thread);
             // it is detached
             // pthread_join(*static_threads[i].thread, NULL);
 
-            static_threads[i].thread = NULL;
+            static_threads[i].enabled = 0;
         }
     }
 
@@ -179,19 +181,15 @@ void kill_childs()
         info("Killing tc-qos-helper process %d", tc_child_pid);
         if(killpid(tc_child_pid, SIGTERM) != -1)
             waitid(P_PID, (id_t) tc_child_pid, &info, WEXITED);
+
+        tc_child_pid = 0;
     }
-    tc_child_pid = 0;
 
     struct plugind *cd;
     for(cd = pluginsd_root ; cd ; cd = cd->next) {
         if(cd->enabled && !cd->obsolete) {
-            if(cd->thread != (pthread_t)NULL) {
-                info("Stopping %s plugin thread", cd->id);
-                pthread_cancel(cd->thread);
-                // they are detached
-                // pthread_join(cd->thread, NULL);
-                cd->thread = (pthread_t)NULL;
-            }
+            info("Stopping %s plugin thread", cd->id);
+            pthread_cancel(cd->thread);
 
             if(cd->pid) {
                 info("killing %s plugin child process pid %d", cd->id, cd->pid);
@@ -251,13 +249,13 @@ void help(int exitcode) {
     if(max_len_arg > 30) max_len_arg = 30;
     if(max_len_arg < 20) max_len_arg = 20;
 
-    fprintf(stream, "\n"
+    fprintf(stream, "%s", "\n"
             " ^\n"
             " |.-.   .-.   .-.   .-.   .  netdata                                         \n"
             " |   '-'   '-'   '-'   '-'   real-time performance monitoring, done right!   \n"
             " +----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+-----+--->\n"
             "\n"
-            " Copyright (C) 2017, Costa Tsaousis <costa@tsaousis.gr>\n"
+            " Copyright (C) 2016-2017, Costa Tsaousis <costa@tsaousis.gr>\n"
             " Released under GNU Public License v3 or later.\n"
             " All rights reserved.\n"
             "\n"
@@ -340,6 +338,7 @@ int main(int argc, char **argv)
     int i, check_config = 0;
     int config_loaded = 0;
     int dont_fork = 0;
+    int oom_score = 1000;
     size_t wanted_stacksize = 0, stacksize = 0;
     pthread_attr_t attr;
 
@@ -554,6 +553,10 @@ int main(int argc, char **argv)
         if(!p) p = "/bin:/usr/bin";
         snprintfz(path, 1024, "%s:%s", p, "/sbin:/usr/sbin:/usr/local/bin:/usr/local/sbin");
         setenv("PATH", config_get("plugins", "PATH environment variable", path), 1);
+
+        p = getenv("PYTHONPATH");
+        if(!p) p = "";
+        setenv("PYTHONPATH", config_get("plugins", "PYTHONPATH environment variable", p), 1);
     }
 
     char *user = NULL;
@@ -614,6 +617,7 @@ int main(int argc, char **argv)
         // --------------------------------------------------------------------
 
         rrd_memory_mode = rrd_memory_mode_id(config_get("global", "memory mode", rrd_memory_mode_name(rrd_memory_mode)));
+        oom_score = (int)config_get_number("global", "OOM score", oom_score);
 
         // --------------------------------------------------------------------
 
@@ -753,7 +757,7 @@ int main(int argc, char **argv)
 #endif /* NETDATA_INTERNAL_CHECKS */
 
     // fork, switch user, create pid file, set process priority
-    if(become_daemon(dont_fork, user) == -1)
+    if(become_daemon(dont_fork, user, oom_score) == -1)
         fatal("Cannot daemonize myself.");
 
     info("netdata started on pid %d.", getpid());