summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xCMakeLists.txt2
-rw-r--r--src/Makefile.am59
-rw-r--r--src/backends.c7
-rw-r--r--src/common.c16
-rw-r--r--src/common.h3
-rw-r--r--src/health.c7
-rw-r--r--src/locks.c24
-rw-r--r--src/locks.h4
-rw-r--r--src/main.c88
-rw-r--r--src/main.h2
-rw-r--r--src/plugin_checks.c6
-rw-r--r--src/plugin_freebsd.c6
-rw-r--r--src/plugin_idlejitter.c6
-rw-r--r--src/plugin_macos.c6
-rw-r--r--src/plugin_nfacct.c33
-rw-r--r--src/plugin_proc.c6
-rw-r--r--src/plugin_proc_diskspace.c6
-rw-r--r--src/plugin_tc.c6
-rw-r--r--src/plugins_d.c40
-rw-r--r--src/plugins_d.h2
-rw-r--r--src/rrd.h2
-rw-r--r--src/rrdpush.c40
-rw-r--r--src/socket.c4
-rw-r--r--src/statsd.c31
-rw-r--r--src/sys_fs_cgroup.c6
-rw-r--r--src/threads.c178
-rw-r--r--src/threads.h32
-rw-r--r--src/web_client.c6
-rw-r--r--src/web_client.h2
-rw-r--r--src/web_server.c58
30 files changed, 374 insertions, 314 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 71d6d94fd8..b4c50e55b1 100755
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -64,7 +64,7 @@ set(NETDATA_LINUX_FILES
src/sys_kernel_mm_ksm.c
src/sys_fs_cgroup.c
src/sys_fs_btrfs.c
- )
+ src/threads.c src/threads.h)
set(NETDATA_COMMON_FILES
src/adaptive_resortable_list.c
diff --git a/src/Makefile.am b/src/Makefile.am
index f6589da7ba..cbb8b0ccbc 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -128,6 +128,8 @@ netdata_SOURCES = \
statsd.h \
storage_number.c \
storage_number.h \
+ threads.c \
+ threads.h \
unit_test.c \
unit_test.h \
url.c \
@@ -224,14 +226,22 @@ netdata_LDADD = \
apps_plugin_SOURCES = \
apps_plugin.c \
- avl.c avl.h \
- clocks.c clocks.h \
- common.c common.h \
+ avl.c \
+ avl.h \
+ clocks.c \
+ clocks.h \
+ common.c \
+ common.h \
inlined.h \
- locks.c locks.h \
+ locks.c \
+ locks.h \
log.c log.h \
- procfile.c procfile.h \
- web_buffer.c web_buffer.h \
+ procfile.c \
+ procfile.h \
+ threads.c \
+ threads.h \
+ web_buffer.c \
+ web_buffer.h \
$(NULL)
if FREEBSD
@@ -247,12 +257,18 @@ apps_plugin_LDADD = \
freeipmi_plugin_SOURCES = \
freeipmi_plugin.c \
- clocks.c clocks.h \
- common.c common.h \
+ clocks.c \
+ clocks.h \
+ common.c \
+ common.h \
inlined.h \
- locks.c locks.h \
+ locks.c \
+ locks.h \
log.c log.h \
- procfile.c procfile.h \
+ procfile.c \
+ procfile.h \
+ threads.c \
+ threads.h \
$(NULL)
freeipmi_plugin_LDADD = \
@@ -261,14 +277,23 @@ freeipmi_plugin_LDADD = \
cgroup_network_SOURCES = \
cgroup-network.c \
- clocks.c clocks.h \
- common.c common.h \
+ clocks.c \
+ clocks.h \
+ common.c \
+ common.h \
inlined.h \
- locks.c locks.h \
- log.c log.h \
- procfile.c procfile.h \
- popen.c popen.h \
- signals.c signals.h \
+ locks.c \
+ locks.h \
+ log.c \
+ log.h \
+ procfile.c \
+ procfile.h \
+ popen.c \
+ popen.h \
+ signals.c \
+ signals.h \
+ threads.c \
+ threads.h \
$(NULL)
cgroup_network_LDADD = \
diff --git a/src/backends.c b/src/backends.c
index ff709be479..c7af9bc550 100644
--- a/src/backends.c
+++ b/src/backends.c
@@ -508,15 +508,13 @@ static void backends_main_cleanup(void *ptr) {
}
void *backends_main(void *ptr) {
- netdata_thread_welcome("BACKEND");
-
int default_port = 0;
int sock = -1;
BUFFER *b = buffer_create(1), *response = buffer_create(1);
int (*backend_request_formatter)(BUFFER *, const char *, RRDHOST *, const char *, RRDSET *, RRDDIM *, time_t, time_t, uint32_t) = NULL;
int (*backend_response_checker)(BUFFER *) = NULL;
- pthread_cleanup_push(backends_main_cleanup, ptr);
+ netdata_thread_cleanup_push(backends_main_cleanup, ptr);
// ------------------------------------------------------------------------
// collect configuration options
@@ -913,7 +911,6 @@ cleanup:
buffer_free(b);
buffer_free(response);
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/common.c b/src/common.c
index a976e96eb3..1c53e7ae00 100644
--- a/src/common.c
+++ b/src/common.c
@@ -1116,22 +1116,6 @@ int fd_is_valid(int fd) {
return fcntl(fd, F_GETFD) != -1 || errno != EBADF;
}
-pid_t gettid(void) {
-#ifdef __FreeBSD__
- return (pid_t)pthread_getthreadid_np();
-#elif defined(__APPLE__)
-#if (defined __MAC_OS_X_VERSION_MIN_REQUIRED && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060)
- uint64_t curthreadid;
- pthread_threadid_np(NULL, &curthreadid);
- return (pid_t)curthreadid;
-#else /* __MAC_OS_X_VERSION_MIN_REQUIRED */
- return (pid_t)pthread_self;
-#endif /* __MAC_OS_X_VERSION_MIN_REQUIRED */
-#else /* __APPLE__*/
- return (pid_t)syscall(SYS_gettid);
-#endif /* __FreeBSD__, __APPLE__*/
-}
-
char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len) {
char *s = fgets(buf, (int)buf_size, fp);
if (!s) return NULL;
diff --git a/src/common.h b/src/common.h
index 688d5fed9a..951a1badf1 100644
--- a/src/common.h
+++ b/src/common.h
@@ -172,6 +172,7 @@
#include "clocks.h"
#include "log.h"
+#include "threads.h"
#include "locks.h"
#include "simple_pattern.h"
#include "avl.h"
@@ -294,8 +295,6 @@ extern int fd_is_valid(int fd);
extern int enable_ksm;
-extern pid_t gettid(void);
-
extern int sleep_usec(usec_t usec);
extern char *fgets_trim_len(char *buf, size_t buf_size, FILE *fp, size_t *len);
diff --git a/src/health.c b/src/health.c
index a5f7eda054..cd0ad43fae 100644
--- a/src/health.c
+++ b/src/health.c
@@ -348,10 +348,8 @@ static void health_main_cleanup(void *ptr) {
}
void *health_main(void *ptr) {
- netdata_thread_welcome("HEALTH");
-
BUFFER *wb = buffer_create(100);
- pthread_cleanup_push(health_main_cleanup, ptr);
+ netdata_thread_cleanup_push(health_main_cleanup, ptr);
int min_run_every = (int)config_get_number(CONFIG_SECTION_HEALTH, "run at least every seconds", 10);
if(min_run_every < 1) min_run_every = 1;
@@ -736,7 +734,6 @@ void *health_main(void *ptr) {
buffer_free(wb);
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/locks.c b/src/locks.c
index dbe67817da..ad19366726 100644
--- a/src/locks.c
+++ b/src/locks.c
@@ -1,30 +1,6 @@
#include "common.h"
// ----------------------------------------------------------------------------
-// threads initialization
-
-static __thread char *netdata_thread_tag_name = NULL;
-
-const char *netdata_thread_tag(void) {
- return ((netdata_thread_tag_name && *netdata_thread_tag_name)?netdata_thread_tag_name:"unknown");
-}
-
-void netdata_thread_welcome_nolog(char *tag) {
- netdata_thread_tag_name = tag;
-
- if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
- error("%s: cannot set pthread cancel type to DEFERRED.", netdata_thread_tag());
-
- if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
- error("%s: cannot set pthread cancel state to ENABLE.", netdata_thread_tag());
-}
-
-void netdata_thread_welcome(char *tag) {
- netdata_thread_welcome_nolog(tag);
- info("%s: thread created with task id %d", netdata_thread_tag(), gettid());
-}
-
-// ----------------------------------------------------------------------------
// automatic thread cancelability management, based on locks
static __thread int netdata_thread_first_cancelability = 0;
diff --git a/src/locks.h b/src/locks.h
index 1ed76db776..39cfe849fa 100644
--- a/src/locks.h
+++ b/src/locks.h
@@ -7,10 +7,6 @@ typedef pthread_mutex_t netdata_mutex_t;
typedef pthread_rwlock_t netdata_rwlock_t;
#define NETDATA_RWLOCK_INITIALIZER PTHREAD_RWLOCK_INITIALIZER
-extern void netdata_thread_welcome(char *tag);
-extern void netdata_thread_welcome_nolog(char *tag);
-extern const char *netdata_thread_tag(void);
-
extern int __netdata_mutex_init(netdata_mutex_t *mutex);
extern int __netdata_mutex_lock(netdata_mutex_t *mutex);
extern int __netdata_mutex_trylock(netdata_mutex_t *mutex);
diff --git a/src/main.c b/src/main.c
index 2a681a5e65..8d7c72fe3b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -36,37 +36,37 @@ struct netdata_static_thread static_threads[] = {
#ifdef INTERNAL_PLUGIN_NFACCT
// nfacct requires root access
// so, we build it as an external plugin with setuid to root
- {"nfacct", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
+ {"PLUGIN_NFACCT", CONFIG_SECTION_PLUGINS, "nfacct", 1, NULL, NULL, nfacct_main},
#endif
#ifdef NETDATA_INTERNAL_CHECKS
// debugging plugin
- {"check", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
+ {"PLUGIN_CHECK", CONFIG_SECTION_PLUGINS, "checks", 0, NULL, NULL, checks_main},
#endif
#if defined(__FreeBSD__)
// FreeBSD internal plugins
- {"freebsd", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
+ {"PLUGIN_FREEBSD", CONFIG_SECTION_PLUGINS, "freebsd", 1, NULL, NULL, freebsd_main},
#elif defined(__APPLE__)
// macOS internal plugins
- {"macos", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
+ {"PLUGIN_MACOS", CONFIG_SECTION_PLUGINS, "macos", 1, NULL, NULL, macos_main},
#else
// linux internal plugins
- {"proc", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
- {"diskspace", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
- {"cgroups", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
- {"tc", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
+ {"PLUGIN_PROC", CONFIG_SECTION_PLUGINS, "proc", 1, NULL, NULL, proc_main},
+ {"PLUGIN_DISKSPACE", CONFIG_SECTION_PLUGINS, "diskspace", 1, NULL, NULL, proc_diskspace_main},
+ {"PLUGIN_CGROUP", CONFIG_SECTION_PLUGINS, "cgroups", 1, NULL, NULL, cgroups_main},
+ {"PLUGIN_TC", CONFIG_SECTION_PLUGINS, "tc", 1, NULL, NULL, tc_main},
#endif /* __FreeBSD__, __APPLE__*/
// common plugins for all systems
- {"idlejitter", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
- {"backends", NULL, NULL, 1, NULL, NULL, backends_main},
- {"health", NULL, NULL, 1, NULL, NULL, health_main},
- {"plugins.d", NULL, NULL, 1, NULL, NULL, pluginsd_main},
- {"web", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
- {"web-single-threaded", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
- {"push-metrics", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
- {"statsd", NULL, NULL, 1, NULL, NULL, statsd_main},
+ {"PLUGIN_IDLEJITTER", CONFIG_SECTION_PLUGINS, "idlejitter", 1, NULL, NULL, cpuidlejitter_main},
+ {"BACKENDS", NULL, NULL, 1, NULL, NULL, backends_main},
+ {"HEALTH", NULL, NULL, 1, NULL, NULL, health_main},
+ {"PLUGINSD", NULL, NULL, 1, NULL, NULL, pluginsd_main},
+ {"WEB_SERVER", NULL, NULL, 1, NULL, NULL, socket_listen_main_multi_threaded},
+ {"WEB_SERVER_SINGLE_THREADED", NULL, NULL, 0, NULL, NULL, socket_listen_main_single_threaded},
+ {"STREAMING", NULL, NULL, 0, NULL, NULL, rrdpush_sender_thread},
+ {"STATSD", NULL, NULL, 1, NULL, NULL, statsd_main},
{NULL, NULL, NULL, 0, NULL, NULL, NULL}
};
@@ -184,22 +184,10 @@ void cancel_main_threads() {
for (i = 0; static_threads[i].name != NULL ; i++) {
if(static_threads[i].enabled) {
info("EXIT: Stopping master thread: %s", static_threads[i].name);
- int ret;
- if((ret = pthread_cancel(*static_threads[i].thread)) != 0)
- error("EXIT: pthread_cancel() failed with code %d.", ret);
- //else
- // info("MAIN: thread %s cancelled", static_threads[i].name);
-
+ netdata_thread_cancel(*static_threads[i].thread);
static_threads[i].enabled = 0;
}
}
-
- // if, for any reason there is any child exited
- // catch it here
- info("EXIT: waiting for any unfinished child processes");
- siginfo_t info;
- waitid(P_PID, 0, &info, WEXITED|WNOHANG);
- info("EXIT: all threads/childs stopped.");
}
struct option_def option_definitions[] = {
@@ -606,8 +594,6 @@ int main(int argc, char **argv) {
int i;
int config_loaded = 0;
int dont_fork = 0;
- size_t wanted_stacksize = 0, stacksize = 0;
- pthread_attr_t attr;
// set the name for logging
program_name = "netdata";
@@ -932,21 +918,8 @@ int main(int argc, char **argv) {
// setup the signals we want to use
signals_init();
-
- // --------------------------------------------------------------------
- // get the required stack size of the threads of netdata
-
- i = pthread_attr_init(&attr);
- if(i != 0)
- fatal("pthread_attr_init() failed with code %d.", i);
-
- i = pthread_attr_getstacksize(&attr, &stacksize);
- if(i != 0)
- fatal("pthread_attr_getstacksize() failed with code %d.", i);
- else
- debug(D_OPTIONS, "initial pthread stack size is %zu bytes", stacksize);
-
- wanted_stacksize = (size_t)config_get_number(CONFIG_SECTION_GLOBAL, "pthread stack size", (long)stacksize);
+ // setup threads configs
+ netdata_threads_init();
// --------------------------------------------------------------------
@@ -1011,18 +984,7 @@ int main(int argc, char **argv) {
web_files_uid();
web_files_gid();
-
- // ------------------------------------------------------------------------
- // set default pthread stack size - after we have forked
-
- if(stacksize < wanted_stacksize) {
- i = pthread_attr_setstacksize(&attr, wanted_stacksize);
- if(i != 0)
- fatal("pthread_attr_setstacksize() to %zu bytes, failed with code %d.", wanted_stacksize, i);
- else
- debug(D_SYSTEM, "Successfully set pthread stacksize to %zu bytes", wanted_stacksize);
- }
-
+ netdata_threads_init_after_fork();
// ------------------------------------------------------------------------
// initialize rrd, registry, health, rrdpush, etc.
@@ -1045,15 +1007,9 @@ int main(int argc, char **argv) {
struct netdata_static_thread *st = &static_threads[i];
if(st->enabled) {
- st->thread = mallocz(sizeof(pthread_t));
-
+ st->thread = mallocz(sizeof(netdata_thread_t));
debug(D_SYSTEM, "Starting thread %s.", st->name);
-
- if(pthread_create(st->thread, &attr, st->start_routine, st))
- error("failed to create new thread for %s.", st->name);
-
- else if(pthread_detach(*st->thread))
- error("Cannot request detach of newly created %s thread.", st->name);
+ netdata_thread_create(st->thread, st->name, NETDATA_THREAD_OPTION_DEFAULT, st->start_routine, st);
}
else debug(D_SYSTEM, "Not starting thread %s.", st->name);
}
diff --git a/src/main.h b/src/main.h
index e9d0fcc92e..dd2df2ca9a 100644
--- a/src/main.h
+++ b/src/main.h
@@ -24,7 +24,7 @@ struct netdata_static_thread {
volatile sig_atomic_t enabled;
- pthread_t *thread;
+ netdata_thread_t *thread;
void (*init_routine) (void);
void *(*start_routine) (void *);
diff --git a/src/plugin_checks.c b/src/plugin_checks.c
index 56455cc545..d586d0b493 100644
--- a/src/plugin_checks.c
+++ b/src/plugin_checks.c
@@ -12,8 +12,7 @@ static void checks_main_cleanup(void *ptr) {
}
void *checks_main(void *ptr) {
- netdata_thread_welcome("CHECKS");
- pthread_cleanup_push(checks_main_cleanup, ptr);
+ netdata_thread_cleanup_push(checks_main_cleanup, ptr);
usec_t usec = 0, susec = localhost->rrd_update_every * USEC_PER_SEC, loop_usec = 0, total_susec = 0;
struct timeval now, last, loop;
@@ -121,8 +120,7 @@ void *checks_main(void *ptr) {
rrdset_done(check3);
}
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugin_freebsd.c b/src/plugin_freebsd.c
index bd68f6a8ae..e5c5ce45ee 100644
--- a/src/plugin_freebsd.c
+++ b/src/plugin_freebsd.c
@@ -76,8 +76,7 @@ static void freebsd_main_cleanup(void *ptr) {
}
void *freebsd_main(void *ptr) {
- netdata_thread_welcome("FREEBSD");
- pthread_cleanup_push(freebsd_main_cleanup, ptr);
+ netdata_thread_cleanup_push(freebsd_main_cleanup, ptr);
int vdo_cpu_netdata = config_get_boolean("plugin:freebsd", "netdata server resources", 1);
@@ -169,7 +168,6 @@ void *freebsd_main(void *ptr) {
}
}
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugin_idlejitter.c b/src/plugin_idlejitter.c
index fbf2ce0514..4b38d9adbc 100644
--- a/src/plugin_idlejitter.c
+++ b/src/plugin_idlejitter.c
@@ -12,8 +12,7 @@ static void cpuidlejitter_main_cleanup(void *ptr) {
}
void *cpuidlejitter_main(void *ptr) {
- netdata_thread_welcome("IDLEJITTER");
- pthread_cleanup_push(cpuidlejitter_main_cleanup, ptr);
+ netdata_thread_cleanup_push(cpuidlejitter_main_cleanup, ptr);
usec_t sleep_ut = config_get_number("plugin:idlejitter", "loop time in ms", CPU_IDLEJITTER_SLEEP_TIME_MS) * USEC_PER_MS;
if(sleep_ut <= 0) {
@@ -85,8 +84,7 @@ void *cpuidlejitter_main(void *ptr) {
}
}
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugin_macos.c b/src/plugin_macos.c
index 454546eef8..4c51088d40 100644
--- a/src/plugin_macos.c
+++ b/src/plugin_macos.c
@@ -10,8 +10,7 @@ static void macos_main_cleanup(void *ptr) {
}
void *macos_main(void *ptr) {
- netdata_thread_welcome("MACOS");
- pthread_cleanup_push(macos_main_cleanup, ptr);
+ netdata_thread_cleanup_push(macos_main_cleanup, ptr);
// when ZERO, attempt to do it
int vdo_cpu_netdata = !config_get_boolean("plugin:macos", "netdata server resources", 1);
@@ -63,7 +62,6 @@ void *macos_main(void *ptr) {
}
}
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugin_nfacct.c b/src/plugin_nfacct.c
index 8319c67263..2aa17c909f 100644
--- a/src/plugin_nfacct.c
+++ b/src/plugin_nfacct.c
@@ -751,17 +751,25 @@ static void nfacct_send_metrics() {
// ----------------------------------------------------------------------------
-void *nfacct_main(void *ptr) {
+static void nfacct_main_cleanup(void *ptr) {
struct netdata_static_thread *static_thread = (struct netdata_static_thread *)ptr;
+ if(static_thread->enabled) {
+ static_thread->enabled = 0;
- info("NETFILTER thread created with task id %d", gettid());
+ info("%s: cleaning up...", netdata_thread_tag());
- if(pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL) != 0)
- error("NETFILTER: Cannot set pthread cancel type to DEFERRED.");
+#ifdef DO_NFACCT
+ nfacct_cleanup();
+#endif
- if(pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL) != 0)
- error("NETFILTER: Cannot set pthread cancel state to ENABLE.");
+#ifdef DO_NFSTAT
+ nfstat_cleanup();
+#endif
+ }
+}
+void *nfacct_main(void *ptr) {
+ netdata_thread_cleanup_push(nfacct_main_cleanup, ptr);
int update_every = (int)config_get_number("plugin:netfilter", "update every", localhost->rrd_update_every);
if(update_every < localhost->rrd_update_every)
@@ -805,18 +813,7 @@ void *nfacct_main(void *ptr) {
#endif
}
- info("NETFILTER thread exiting");
-
-#ifdef DO_NFACCT
- nfacct_cleanup();
-#endif
-
-#ifdef DO_NFSTAT
- nfstat_cleanup();
-#endif
-
- static_thread->enabled = 0;
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugin_proc.c b/src/plugin_proc.c
index 317acaced1..154b23b7f8 100644
--- a/src/plugin_proc.c
+++ b/src/plugin_proc.c
@@ -74,8 +74,7 @@ static void proc_main_cleanup(void *ptr) {
}
void *proc_main(void *ptr) {
- netdata_thread_welcome("PROC");
- pthread_cleanup_push(proc_main_cleanup, ptr);
+ netdata_thread_cleanup_push(proc_main_cleanup, ptr);
int vdo_cpu_netdata = config_get_boolean("plugin:proc", "netdata server resources", 1);
@@ -163,8 +162,7 @@ void *proc_main(void *ptr) {
}
}
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugin_proc_diskspace.c b/src/plugin_proc_diskspace.c
index 97a9740deb..e2ee61e640 100644
--- a/src/plugin_proc_diskspace.c
+++ b/src/plugin_proc_diskspace.c
@@ -338,8 +338,7 @@ static void diskspace_main_cleanup(void *ptr) {
}
void *proc_diskspace_main(void *ptr) {
- netdata_thread_welcome("DISKSPACE");
- pthread_cleanup_push(diskspace_main_cleanup, ptr);
+ netdata_thread_cleanup_push(diskspace_main_cleanup, ptr);
int vdo_cpu_netdata = config_get_boolean("plugin:proc", "netdata server resources", 1);
@@ -456,7 +455,6 @@ void *proc_diskspace_main(void *ptr) {
}
}
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugin_tc.c b/src/plugin_tc.c
index 676a4c8e5e..9d694d6bb0 100644
--- a/src/plugin_tc.c
+++ b/src/plugin_tc.c
@@ -853,8 +853,7 @@ static void tc_main_cleanup(void *ptr) {
}
void *tc_main(void *ptr) {
- netdata_thread_welcome("TC");
- pthread_cleanup_push(tc_main_cleanup, ptr);
+ netdata_thread_cleanup_push(tc_main_cleanup, ptr);
struct rusage thread;
@@ -1158,7 +1157,6 @@ void *tc_main(void *ptr) {
}
cleanup:
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
diff --git a/src/plugins_d.c b/src/plugins_d.c
index f127c4cbe8..2937010151 100644
--- a/src/plugins_d.c
+++ b/src/plugins_d.c
@@ -498,8 +498,7 @@ static void pluginsd_worker_thread_cleanup(void *arg) {
}
void *pluginsd_worker_thread(void *arg) {
- netdata_thread_welcome_nolog("PLUGINSD_WORKER");
- pthread_cleanup_push(pluginsd_worker_thread_cleanup, arg);
+ netdata_thread_cleanup_push(pluginsd_worker_thread_cleanup, arg);
struct plugind *cd = (struct plugind *)arg;
@@ -513,15 +512,11 @@ void *pluginsd_worker_thread(void *arg) {
break;
}
- info("PLUGINSD: '%s' running on pid %d", cd->fullfilename, cd->pid);
-
+ info("%s on tid %d: connected to '%s' running on pid %d", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid);
count = pluginsd_process(localhost, cd, fp, 0);
- error("PLUGINSD: plugin '%s' disconnected.", cd->fullfilename);
-
+ error("%s on tid %d: '%s' (pid %d) disconnected after %zu successful data collections (ENDs).", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, count);
killpid(cd->pid, SIGTERM);
- info("PLUGINSD: '%s' on pid %d stopped after %zu successful data collections (ENDs).", cd->fullfilename, cd->pid, count);
-
// get the return code
int code = mypclose(fp, cd->pid);
@@ -530,18 +525,18 @@ void *pluginsd_worker_thread(void *arg) {
if(likely(!cd->successful_collections)) {
// nothing collected - disable it
- error("PLUGINSD: '%s' exited with error code %d. Disabling it.", cd->fullfilename, code);
+ error("%s on tid %d: '%s' (pid %d) exited with error code %d. Disabling it.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, code);
cd->enabled = 0;
}
else {
// we have collected something
if(likely(cd->serial_failures <= 10)) {
- error("PLUGINSD: '%s' exited with error code %d, but has given useful output in the past (%zu times). %s", cd->fullfilename, code, cd->successful_collections, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is disabled.");
+ error("%s on tid %d: '%s' (pid %d) exited with error code %d, but has given useful output in the past (%zu times). %s", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, code, cd->successful_collections, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is disabled.");
sleep((unsigned int) (cd->update_every * 10));
}
else {
- error("PLUGINSD: '%s' exited with error code %d, but has given useful output in the past (%zu times). We tried %zu times to restart it, but it failed to generate data. Disabling it.", cd->fullfilename, code, cd->successful_collections, cd->serial_failures);
+ error("%s on tid %d: '%s' (pid %d) exited with error code %d, but has given useful output in the past (%zu times). We tried %zu times to restart it, but it failed to generate data. Disabling it.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, code, cd->successful_collections, cd->serial_failures);
cd->enabled = 0;
}
}
@@ -553,11 +548,11 @@ void *pluginsd_worker_thread(void *arg) {
// we have collected nothing so far
if(likely(cd->serial_failures <= 10)) {
- error("PLUGINSD: '%s' (pid %d) does not generate useful output but it reports success (exits with 0). %s.", cd->fullfilename, cd->pid, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is disabled.");
+ error("%s on tid %d: '%s' (pid %d) does not generate useful output but it reports success (exits with 0). %s.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, cd->enabled?"Waiting a bit before starting it again.":"Will not start it again - it is now disabled.");
sleep((unsigned int) (cd->update_every * 10));
}
else {
- error("PLUGINSD: '%s' (pid %d) does not generate useful output, although it reports success (exits with 0), but we have tried %zu times to collect something. Disabling it.", cd->fullfilename, cd->pid, cd->serial_failures);
+ error("%s on tid %d: '%s' (pid %d) does not generate useful output, although it reports success (exits with 0), but we have tried %zu times to collect something. Disabling it.", netdata_thread_tag(), gettid(), cd->fullfilename, cd->pid, cd->serial_failures);
cd->enabled = 0;
}
}
@@ -569,8 +564,7 @@ void *pluginsd_worker_thread(void *arg) {
if(unlikely(!cd->enabled)) break;
}
- pthread_cleanup_pop(1);
- pthread_exit(NULL);
+ netdata_thread_cleanup_pop(1);
return NULL;
}
@@ -585,9 +579,7 @@ static void pluginsd_main_cleanup(void *data) {
for (cd = pluginsd_root; cd; cd = cd