From: Sebastian Harl Date: Sun, 14 Oct 2012 15:52:39 +0000 (+0200) Subject: Use plugin_thread_create() rather than pthread_create() in all plugins. X-Git-Tag: collectd-5.2.0~20^2~11 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=76e6392863d130ceca048eb860e4db1c9e40fee7;p=collectd.git Use plugin_thread_create() rather than pthread_create() in all plugins. This function copies the plugin context from the calling thread to the new thread. While this might not strictly be necessary in most/many cases, this will make sure that any code within a plugin uses the same context information, thus avoiding possible problems in the future. --- diff --git a/src/amqp.c b/src/amqp.c index 30a85810..db657916 100644 --- a/src/amqp.c +++ b/src/amqp.c @@ -610,7 +610,7 @@ static int camqp_subscribe_init (camqp_config_t *conf) /* {{{ */ tmp = subscriber_threads + subscriber_threads_num; memset (tmp, 0, sizeof (*tmp)); - status = pthread_create (tmp, /* attr = */ NULL, + status = plugin_thread_create (tmp, /* attr = */ NULL, camqp_subscribe_thread, conf); if (status != 0) { diff --git a/src/dns.c b/src/dns.c index 08a03692..fe3b672a 100644 --- a/src/dns.c +++ b/src/dns.c @@ -286,7 +286,7 @@ static int dns_init (void) if (listen_thread_init != 0) return (-1); - status = pthread_create (&listen_thread, NULL, dns_child_loop, + status = plugin_thread_create (&listen_thread, NULL, dns_child_loop, (void *) 0); if (status != 0) { diff --git a/src/email.c b/src/email.c index 8fc5509f..787f3917 100644 --- a/src/email.c +++ b/src/email.c @@ -481,8 +481,8 @@ static void *open_connection (void __attribute__((unused)) *arg) collectors[i] = (collector_t *)smalloc (sizeof (collector_t)); collectors[i]->socket = NULL; - if (0 != (err = pthread_create (&collectors[i]->thread, &ptattr, - collect, collectors[i]))) { + if (0 != (err = plugin_thread_create (&collectors[i]->thread, + &ptattr, collect, collectors[i]))) { char errbuf[1024]; log_err ("pthread_create() failed: %s", sstrerror (errno, errbuf, sizeof (errbuf))); @@ -555,7 +555,7 @@ static int email_init (void) { int err = 0; - if (0 != (err = pthread_create (&connector, NULL, + if (0 != (err = plugin_thread_create (&connector, NULL, open_connection, NULL))) { char errbuf[1024]; disabled = 1; diff --git a/src/exec.c b/src/exec.c index 6dfdfe6a..da6e367d 100644 --- a/src/exec.c +++ b/src/exec.c @@ -814,7 +814,7 @@ static int exec_read (void) /* {{{ */ pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&t, &attr, exec_read_one, (void *) pl); + plugin_thread_create (&t, &attr, exec_read_one, (void *) pl); } /* for (pl) */ return (0); @@ -857,7 +857,7 @@ static int exec_notification (const notification_t *n, /* {{{ */ pthread_attr_init (&attr); pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); - pthread_create (&t, &attr, exec_notification_one, (void *) pln); + plugin_thread_create (&t, &attr, exec_notification_one, (void *) pln); } /* for (pl) */ return (0); diff --git a/src/gmond.c b/src/gmond.c index 3c746c48..28be0920 100644 --- a/src/gmond.c +++ b/src/gmond.c @@ -879,7 +879,7 @@ static int mc_receive_thread_start (void) /* {{{ */ mc_receive_thread_loop = 1; - status = pthread_create (&mc_receive_thread_id, /* attr = */ NULL, + status = plugin_thread_create (&mc_receive_thread_id, /* attr = */ NULL, mc_receive_thread, /* args = */ NULL); if (status != 0) { diff --git a/src/ipmi.c b/src/ipmi.c index 7eafea86..fada5bdc 100644 --- a/src/ipmi.c +++ b/src/ipmi.c @@ -669,7 +669,7 @@ static int c_ipmi_init (void) c_ipmi_active = 1; - status = pthread_create (&thread_id, /* attr = */ NULL, thread_main, + status = plugin_thread_create (&thread_id, /* attr = */ NULL, thread_main, /* user data = */ NULL); if (status != 0) { diff --git a/src/network.c b/src/network.c index 59c2be7c..369da94d 100644 --- a/src/network.c +++ b/src/network.c @@ -3320,7 +3320,7 @@ static int network_init (void) if (dispatch_thread_running == 0) { int status; - status = pthread_create (&dispatch_thread_id, + status = plugin_thread_create (&dispatch_thread_id, NULL /* no attributes */, dispatch_thread, NULL /* no argument */); @@ -3340,7 +3340,7 @@ static int network_init (void) if (receive_thread_running == 0) { int status; - status = pthread_create (&receive_thread_id, + status = plugin_thread_create (&receive_thread_id, NULL /* no attributes */, receive_thread, NULL /* no argument */); diff --git a/src/pinba.c b/src/pinba.c index a6fd06fe..48a2431d 100644 --- a/src/pinba.c +++ b/src/pinba.c @@ -645,7 +645,7 @@ static int plugin_init (void) /* {{{ */ if (collector_thread_running) return (0); - status = pthread_create (&collector_thread_id, + status = plugin_thread_create (&collector_thread_id, /* attrs = */ NULL, collector_thread, /* args = */ NULL); diff --git a/src/ping.c b/src/ping.c index b536f429..417a7ac7 100644 --- a/src/ping.c +++ b/src/ping.c @@ -361,7 +361,7 @@ static int start_thread (void) /* {{{ */ ping_thread_loop = 1; ping_thread_error = 0; - status = pthread_create (&ping_thread_id, /* attr = */ NULL, + status = plugin_thread_create (&ping_thread_id, /* attr = */ NULL, ping_thread, /* arg = */ (void *) 0); if (status != 0) { diff --git a/src/python.c b/src/python.c index 4a828b44..350bd14a 100644 --- a/src/python.c +++ b/src/python.c @@ -922,7 +922,7 @@ static int cpy_init(void) { pthread_sigmask(SIG_BLOCK, &sigset, NULL); state = PyEval_SaveThread(); if (do_interactive) { - if (pthread_create(&thread, NULL, cpy_interactive, NULL)) { + if (plugin_thread_create(&thread, NULL, cpy_interactive, NULL)) { ERROR("python: Error creating thread for interactive interpreter."); } } diff --git a/src/rrdtool.c b/src/rrdtool.c index 56a82d03..cac5c21b 100644 --- a/src/rrdtool.c +++ b/src/rrdtool.c @@ -1195,7 +1195,7 @@ static int rrd_init (void) pthread_mutex_unlock (&cache_lock); - status = pthread_create (&queue_thread, /* attr = */ NULL, + status = plugin_thread_create (&queue_thread, /* attr = */ NULL, rrd_queue_thread, /* args = */ NULL); if (status != 0) { diff --git a/src/unixsock.c b/src/unixsock.c index d729477b..337978df 100644 --- a/src/unixsock.c +++ b/src/unixsock.c @@ -355,7 +355,8 @@ static void *us_server_thread (void __attribute__((unused)) *arg) pthread_attr_init (&th_attr); pthread_attr_setdetachstate (&th_attr, PTHREAD_CREATE_DETACHED); - status = pthread_create (&th, &th_attr, us_handle_client, (void *) remote_fd); + status = plugin_thread_create (&th, &th_attr, + us_handle_client, (void *) remote_fd); if (status != 0) { char errbuf[1024]; @@ -434,7 +435,8 @@ static int us_init (void) loop = 1; - status = pthread_create (&listen_thread, NULL, us_server_thread, NULL); + status = plugin_thread_create (&listen_thread, NULL, + us_server_thread, NULL); if (status != 0) { char errbuf[1024];