allow apps.plugin to build without requiring appconfig.c
Costa Tsaousis (ktsaou) committed
Dec 28, 2017 at 04:26 UTC
d387b0d3a65b34280e099eef12deb603166c1d74
3 files changed
+20
-16
src/main.c
+3
-2
@@ -594,6 +594,7 @@ int main(int argc, char **argv) {
594
int i;
595
int config_loaded = 0;
596
int dont_fork = 0;
597
+ size_t default_stacksize;
598
599
// set the name for logging
600
program_name = "netdata";
@@ -919,7 +920,7 @@ int main(int argc, char **argv) {
920
signals_init();
921
922
// setup threads configs
922
- netdata_threads_init();
923
+ default_stacksize = netdata_threads_init();
924
925
926
// --------------------------------------------------------------------
@@ -984,7 +985,7 @@ int main(int argc, char **argv) {
985
web_files_uid();
986
web_files_gid();
987
987
- netdata_threads_init_after_fork();
988
+ netdata_threads_init_after_fork((size_t)config_get_number(CONFIG_SECTION_GLOBAL, "pthread stack size", (long)default_stacksize));
989
990
// ------------------------------------------------------------------------
991
// initialize rrd, registry, health, rrdpush, etc.
src/threads.c
+15
-12
@@ -1,7 +1,7 @@
1
#include "common.h"
2
3
-static size_t stacksize = 0, wanted_stacksize = 0;
4
-static pthread_attr_t attr;
3
+static size_t default_stacksize = 0, wanted_stacksize = 0;
4
+static pthread_attr_t *attr = NULL;
5
6
// ----------------------------------------------------------------------------
7
// per thread data
@@ -48,36 +48,38 @@ pid_t gettid(void) {
48
// ----------------------------------------------------------------------------
49
// early initialization
50
51
-void netdata_threads_init(void) {
51
+size_t netdata_threads_init(void) {
52
int i;
53
54
// --------------------------------------------------------------------
55
// get the required stack size of the threads of netdata
56
57
- i = pthread_attr_init(&attr);
57
+ attr = callocz(1, sizeof(pthread_attr_t));
58
+ i = pthread_attr_init(attr);
59
if(i != 0)
60
fatal("pthread_attr_init() failed with code %d.", i);
61
61
- i = pthread_attr_getstacksize(&attr, &stacksize);
62
+ i = pthread_attr_getstacksize(attr, &default_stacksize);
63
if(i != 0)
64
fatal("pthread_attr_getstacksize() failed with code %d.", i);
65
else
65
- debug(D_OPTIONS, "initial pthread stack size is %zu bytes", stacksize);
66
+ debug(D_OPTIONS, "initial pthread stack size is %zu bytes", default_stacksize);
67
67
- wanted_stacksize = (size_t)config_get_number(CONFIG_SECTION_GLOBAL, "pthread stack size", (long)stacksize);
68
+ return default_stacksize;
69
}
70
71
// ----------------------------------------------------------------------------
72
// late initialization
73
73
-void netdata_threads_init_after_fork(void) {
74
+void netdata_threads_init_after_fork(size_t stacksize) {
75
+ wanted_stacksize = stacksize;
76
int i;
77
78
// ------------------------------------------------------------------------
79
// set default pthread stack size
80
79
- if(stacksize < wanted_stacksize && wanted_stacksize > 0) {
80
- i = pthread_attr_setstacksize(&attr, wanted_stacksize);
81
+ if(attr && default_stacksize < wanted_stacksize && wanted_stacksize > 0) {
82
+ i = pthread_attr_setstacksize(attr, wanted_stacksize);
83
if(i != 0)
84
fatal("pthread_attr_setstacksize() to %zu bytes, failed with code %d.", wanted_stacksize, i);
85
else
@@ -99,8 +101,9 @@ static void thread_cleanup(void *ptr) {
101
info("%s: thread with task id %d finished", netdata_thread_tag(), gettid());
102
103
freez((void *)netdata_thread->tag);
102
- freez(netdata_thread);
104
netdata_thread->tag = NULL;
105
+
106
+ freez(netdata_thread);
107
netdata_thread = NULL;
108
}
109
@@ -132,7 +135,7 @@ int netdata_thread_create(netdata_thread_t *thread, const char *tag, NETDATA_THR
135
info->start_routine = start_routine;
136
info->options = options;
137
135
- int ret = pthread_create(thread, &attr, thread_start, info);
138
+ int ret = pthread_create(thread, attr, thread_start, info);
139
if(ret != 0)
140
error("%s: failed to create new thread for %s. pthread_create() failed with code %d", netdata_thread_tag(), tag, ret);
141
src/threads.h
+2
-2
@@ -18,8 +18,8 @@ typedef pthread_t netdata_thread_t;
18
19
extern const char *netdata_thread_tag(void);
20
21
-extern void netdata_threads_init(void);
22
-extern void netdata_threads_init_after_fork(void);
21
+extern size_t netdata_threads_init(void);
22
+extern void netdata_threads_init_after_fork(size_t stacksize);
23
24
extern int netdata_thread_create(netdata_thread_t *thread, const char *tag, NETDATA_THREAD_OPTIONS options, void *(*start_routine) (void *), void *arg);
25
extern int netdata_thread_cancel(netdata_thread_t thread);