@cryptotaxi247 / netdata-1 / commits / 43d4a8544

added configuration file option and command line option to set pthread stacksize #66

Costa Tsaousis (ktsaou) committed Apr 2, 2016 at 21:27 UTC 43d4a8544f07210868ef1b88174d269bad8a788b
1 file changed +33 -1
src/main.c
+33 -1
@@ -190,6 +190,8 @@ int main(int argc, char **argv)
190 int i;
191 int config_loaded = 0;
192 int dont_fork = 0;
193 + size_t wanted_stacksize = 0, stacksize = 0;
194 + pthread_attr_t attr;
195
196 // global initialization
197 get_HZ();
@@ -216,6 +218,7 @@ int main(int argc, char **argv)
218 else if(strcmp(argv[i], "-l") == 0 && (i+1) < argc) { config_set("global", "history", argv[i+1]); i++; }
219 else if(strcmp(argv[i], "-t") == 0 && (i+1) < argc) { config_set("global", "update every", argv[i+1]); i++; }
220 else if(strcmp(argv[i], "-ch") == 0 && (i+1) < argc) { config_set("global", "host access prefix", argv[i+1]); i++; }
221 + else if(strcmp(argv[i], "-stacksize") == 0 && (i+1) < argc) { config_set("global", "pthread stack size", argv[i+1]); i++; }
222 else if(strcmp(argv[i], "-nodaemon") == 0 || strcmp(argv[i], "-nd") == 0) dont_fork = 1;
223 else if(strcmp(argv[i], "--unittest") == 0) {
224 rrd_update_every = 1;
@@ -235,6 +238,7 @@ int main(int argc, char **argv)
238 fprintf(stderr, " -ch path to access host /proc and /sys when running in a container. Default: empty.\n");
239 fprintf(stderr, " -nd or -nodeamon to disable forking in the background. Default: unset.\n");
240 fprintf(stderr, " -df FLAGS debug options. Default: 0x%08llx.\n", debug_flags);
241 + fprintf(stderr, " -stacksize BYTES to overwrite the pthread stack size.\n");
242 exit(1);
243 }
244 }
@@ -374,6 +378,20 @@ int main(int argc, char **argv)
378
379 // --------------------------------------------------------------------
380
381 + i = pthread_attr_init(&attr);
382 + if(i != 0)
383 + fatal("pthread_attr_init() failed with code %d.", i);
384 +
385 + i = pthread_attr_getstacksize(&attr, &stacksize);
386 + if(i != 0)
387 + fatal("pthread_attr_getstacksize() failed with code %d.", i);
388 + else
389 + debug(D_OPTIONS, "initial pthread stack size is %zu bytes", stacksize);
390 +
391 + wanted_stacksize = config_get_number("global", "pthread stack size", stacksize);
392 +
393 + // --------------------------------------------------------------------
394 +
395 for (i = 0; static_threads[i].name != NULL ; i++) {
396 struct netdata_static_thread *st = &static_threads[i];
397
@@ -455,6 +473,20 @@ int main(int argc, char **argv)
473 }
474 }
475
476 + // ------------------------------------------------------------------------
477 + // get default pthread stack size
478 +
479 + if(stacksize < wanted_stacksize) {
480 + i = pthread_attr_setstacksize(&attr, wanted_stacksize);
481 + if(i != 0)
482 + fatal("pthread_attr_setstacksize() to %zu bytes, failed with code %d.", wanted_stacksize, i);
483 + else
484 + info("Successfully set pthread stacksize to %zu bytes", wanted_stacksize);
485 + }
486 +
487 + // ------------------------------------------------------------------------
488 + // spawn the threads
489 +
490 for (i = 0; static_threads[i].name != NULL ; i++) {
491 struct netdata_static_thread *st = &static_threads[i];
492
@@ -465,7 +497,7 @@ int main(int argc, char **argv)
497
498 info("Starting thread %s.", st->name);
499
468 - if(pthread_create(st->thread, NULL, st->start_routine, NULL))
500 + if(pthread_create(st->thread, &attr, st->start_routine, NULL))
501 error("failed to create new thread for %s.", st->name);
502
503 else if(pthread_detach(*st->thread))