tmp = subscriber_threads + subscriber_threads_num;
memset(tmp, 0, sizeof(*tmp));
- status = plugin_thread_create(tmp, /* attr = */ NULL, camqp_subscribe_thread,
- conf, "amqp subscribe");
+ status =
+ plugin_thread_create(tmp, camqp_subscribe_thread, conf, "amqp subscribe");
if (status != 0) {
ERROR("amqp plugin: pthread_create failed: %s", STRERROR(status));
return status;
if (proactor == NULL) {
pthread_mutex_init(&send_lock, /* attr = */ NULL);
/* start_thread */
- int status =
- plugin_thread_create(&event_thread_id, NULL /* no attributes */,
- event_thread, NULL /* no argument */, "handle");
+ int status = plugin_thread_create(&event_thread_id, event_thread,
+ NULL /* no argument */, "handle");
if (status != 0) {
ERROR("amqp1 plugin: pthread_create failed: %s", STRERRNO);
} else {
}
status = plugin_thread_create(&connectivity_netlink_thread_id,
- /* attr = */ NULL, connectivity_netlink_thread,
+ connectivity_netlink_thread,
/* arg = */ (void *)0, "connectivity");
if (status != 0) {
connectivity_netlink_thread_loop = 0;
connectivity_dequeue_thread_loop = 1;
- int status =
- plugin_thread_create(&connectivity_dequeue_thread_id,
- /* attr = */ NULL, connectivity_dequeue_thread,
- /* arg = */ (void *)0, "connectivity");
+ int status = plugin_thread_create(&connectivity_dequeue_thread_id,
+ connectivity_dequeue_thread,
+ /* arg = */ (void *)0, "connectivity");
if (status != 0) {
connectivity_dequeue_thread_loop = 0;
ERROR("connectivity plugin: Starting dequeue thread failed.");
user_data_t user_data;
if (ud == NULL) {
user_data = (user_data_t){
- .data = NULL, .free_func = NULL,
+ .data = NULL,
+ .free_func = NULL,
};
} else {
user_data = *ud;
return start_routine(plugin_arg);
} /* void *plugin_thread_start */
-int plugin_thread_create(pthread_t *thread, const pthread_attr_t *attr,
- void *(*start_routine)(void *), void *arg,
- char const *name) {
+int plugin_thread_create(pthread_t *thread, void *(*start_routine)(void *),
+ void *arg, char const *name) {
plugin_thread_t *plugin_thread;
plugin_thread = malloc(sizeof(*plugin_thread));
plugin_thread->start_routine = start_routine;
plugin_thread->arg = arg;
- int ret = pthread_create(thread, attr, plugin_thread_start, plugin_thread);
+ int ret = pthread_create(thread, NULL, plugin_thread_start, plugin_thread);
if (ret != 0) {
sfree(plugin_thread);
return ret;
* Context-aware thread management.
*/
-int plugin_thread_create(pthread_t *thread, const pthread_attr_t *attr,
- void *(*start_routine)(void *), void *arg,
- char const *name);
+int plugin_thread_create(pthread_t *thread, void *(*start_routine)(void *),
+ void *arg, char const *name);
/*
* Plugins need to implement this
cdtime_t plugin_get_interval(void) { return mock_context.interval; }
int plugin_thread_create(__attribute__((unused)) pthread_t *thread,
- __attribute__((unused)) const pthread_attr_t *attr,
__attribute__((unused)) void *(*start_routine)(void *),
__attribute__((unused)) void *arg,
__attribute__((unused)) char const *name) {
if (listen_thread_init != 0)
return -1;
- status = plugin_thread_create(&listen_thread, NULL, dns_child_loop, (void *)0,
+ status = plugin_thread_create(&listen_thread, dns_child_loop, (void *)0,
"dns listen");
if (status != 0) {
ERROR("dns plugin: pthread_create failed: %s", STRERRNO);
}
{ /* initialize collector threads */
- pthread_attr_t ptattr;
-
conns.head = NULL;
conns.tail = NULL;
- pthread_attr_init(&ptattr);
- pthread_attr_setdetachstate(&ptattr, PTHREAD_CREATE_DETACHED);
-
available_collectors = max_conns;
collectors = smalloc(max_conns * sizeof(*collectors));
collectors[i] = smalloc(sizeof(*collectors[i]));
collectors[i]->socket = NULL;
- if (plugin_thread_create(&collectors[i]->thread, &ptattr, collect,
- collectors[i], "email collector") != 0) {
+ if (plugin_thread_create(&collectors[i]->thread, collect, collectors[i],
+ "email collector") == 0) {
+ pthread_detach(collectors[i]->thread);
+ } else {
log_err("plugin_thread_create() failed: %s", STRERRNO);
collectors[i]->thread = (pthread_t)0;
}
}
-
- pthread_attr_destroy(&ptattr);
}
while (1) {
} /* static void *open_connection (void *) */
static int email_init(void) {
- if (plugin_thread_create(&connector, NULL, open_connection, NULL,
+ if (plugin_thread_create(&connector, open_connection, NULL,
"email listener") != 0) {
disabled = 1;
log_err("plugin_thread_create() failed: %s", STRERRNO);
{
for (program_list_t *pl = pl_head; pl != NULL; pl = pl->next) {
pthread_t t;
- pthread_attr_t attr;
/* Only execute `normal' style executables here. */
if ((pl->flags & PL_NORMAL) == 0)
pl->flags |= PL_RUNNING;
pthread_mutex_unlock(&pl_lock);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
int status =
- plugin_thread_create(&t, &attr, exec_read_one, (void *)pl, "exec read");
- if (status != 0) {
+ plugin_thread_create(&t, exec_read_one, (void *)pl, "exec read");
+ if (status == 0) {
+ pthread_detach(t);
+ } else {
ERROR("exec plugin: plugin_thread_create failed.");
}
- pthread_attr_destroy(&attr);
} /* for (pl) */
return 0;
for (program_list_t *pl = pl_head; pl != NULL; pl = pl->next) {
pthread_t t;
- pthread_attr_t attr;
/* Only execute `notification' style executables here. */
if ((pl->flags & PL_NOTIF_ACTION) == 0)
pln->n.meta = NULL;
plugin_notification_meta_copy(&pln->n, n);
- pthread_attr_init(&attr);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- int status = plugin_thread_create(&t, &attr, exec_notification_one,
- (void *)pln, "exec notify");
- if (status != 0) {
+ int status = plugin_thread_create(&t, exec_notification_one, (void *)pln,
+ "exec notify");
+ if (status == 0) {
+ pthread_detach(t);
+ } else {
ERROR("exec plugin: plugin_thread_create failed.");
}
- pthread_attr_destroy(&attr);
} /* for (pl) */
return 0;
mc_receive_thread_loop = 1;
- status =
- plugin_thread_create(&mc_receive_thread_id, /* attr = */ NULL,
- mc_receive_thread, /* args = */ NULL, "gmond recv");
+ status = plugin_thread_create(&mc_receive_thread_id, mc_receive_thread,
+ /* args = */ NULL, "gmond recv");
if (status != 0) {
ERROR("gmond plugin: Starting receive thread failed.");
mc_receive_thread_loop = 0;
CDTIME_T_TO_DOUBLE(cgps_config_data.timeout),
CDTIME_T_TO_DOUBLE(cgps_config_data.pause_connect));
- status =
- plugin_thread_create(&cgps_thread_id, NULL, cgps_thread, NULL, "gps");
+ status = plugin_thread_create(&cgps_thread_id, cgps_thread, NULL, "gps");
if (status != 0) {
ERROR("gps plugin: pthread_create() failed.");
return -1;
st->init_in_progress = cycles;
st->active = true;
- status = plugin_thread_create(&st->thread_id, /* attr = */ NULL,
- c_ipmi_thread_main,
+ status = plugin_thread_create(&st->thread_id, c_ipmi_thread_main,
/* user data = */ (void *)st, "ipmi");
if (status != 0) {
}
if (strlen(socket_adapter.unix_sock.sun_path)) {
- if (plugin_thread_create(&g_mcelog_config.tid, NULL, poll_worker, NULL,
- NULL) != 0) {
+ if (plugin_thread_create(&g_mcelog_config.tid, poll_worker, NULL, NULL) !=
+ 0) {
ERROR(MCELOG_PLUGIN ": Error creating poll thread.");
return -1;
}
continue;
status = plugin_thread_create(&subscribers[i]->thread,
- /* attrs = */ NULL,
/* func = */ subscribers_thread,
/* args = */ subscribers[i],
/* name = */ "mqtt");
if (dispatch_thread_running == 0) {
int status;
- status = plugin_thread_create(&dispatch_thread_id, NULL /* no attributes */,
- dispatch_thread, NULL /* no argument */,
- "network disp");
+ status = plugin_thread_create(&dispatch_thread_id, dispatch_thread,
+ NULL /* no argument */, "network disp");
if (status != 0) {
ERROR("network: pthread_create failed: %s", STRERRNO);
} else {
if (receive_thread_running == 0) {
int status;
- status = plugin_thread_create(&receive_thread_id, NULL /* no attributes */,
- receive_thread, NULL /* no argument */,
- "network recv");
+ status = plugin_thread_create(&receive_thread_id, receive_thread,
+ NULL /* no argument */, "network recv");
if (status != 0) {
ERROR("network: pthread_create failed: %s", STRERRNO);
} else {
if (collector_thread_running)
return 0;
- status = plugin_thread_create(&collector_thread_id,
- /* attrs = */ NULL, collector_thread,
+ status = plugin_thread_create(&collector_thread_id, collector_thread,
/* args = */ NULL, "pinba collector");
if (status != 0) {
ERROR("pinba plugin: pthread_create(3) failed: %s", STRERRNO);
ping_thread_loop = 1;
ping_thread_error = 0;
- status = plugin_thread_create(&ping_thread_id, /* attr = */ NULL, ping_thread,
+ status = plugin_thread_create(&ping_thread_id, ping_thread,
/* arg = */ (void *)0, "ping");
if (status != 0) {
ping_thread_loop = 0;
procevent_netlink_thread_loop = 1;
procevent_netlink_thread_error = 0;
- status = plugin_thread_create(&procevent_netlink_thread_id, /* attr = */ NULL,
+ status = plugin_thread_create(&procevent_netlink_thread_id,
procevent_netlink_thread,
/* arg = */ (void *)0, "procevent");
if (status != 0) {
procevent_dequeue_thread_loop = 1;
int status = plugin_thread_create(&procevent_dequeue_thread_id,
- /* attr = */ NULL, procevent_dequeue_thread,
+ procevent_dequeue_thread,
/* arg = */ (void *)0, "procevent");
if (status != 0) {
procevent_dequeue_thread_loop = 0;
ERROR("python: Unable to create pipe.");
return 1;
}
- if (plugin_thread_create(&thread, NULL, cpy_interactive, pipefd + 1,
+ if (plugin_thread_create(&thread, cpy_interactive, pipefd + 1,
"python interpreter")) {
ERROR("python: Error creating thread for interactive interpreter.");
}
pthread_mutex_unlock(&cache_lock);
- int status =
- plugin_thread_create(&queue_thread, /* attr = */ NULL, rrd_queue_thread,
- /* args = */ NULL, "rrdtool queue");
+ int status = plugin_thread_create(&queue_thread, rrd_queue_thread,
+ /* args = */ NULL, "rrdtool queue");
if (status != 0) {
ERROR("rrdtool plugin: Cannot create queue-thread.");
return -1;
return -1;
}
- status = plugin_thread_create(&sr_thread, NULL, sigrok_read_thread, NULL,
- "sigrok read");
+ status =
+ plugin_thread_create(&sr_thread, sigrok_read_thread, NULL, "sigrok read");
if (status != 0) {
ERROR("sigrok plugin: Failed to create thread: %s.", STRERRNO);
return -1;
DEBUG("sysevent plugin: starting socket thread");
- int status = plugin_thread_create(&sysevent_socket_thread_id,
- /* attr = */ NULL, sysevent_socket_thread,
- /* arg = */ (void *)0, "sysevent");
+ int status =
+ plugin_thread_create(&sysevent_socket_thread_id, sysevent_socket_thread,
+ /* arg = */ (void *)0, "sysevent");
if (status != 0) {
sysevent_socket_thread_loop = 0;
ERROR("sysevent plugin: starting socket thread failed.");
sysevent_dequeue_thread_loop = 1;
- int status = plugin_thread_create(&sysevent_dequeue_thread_id,
- /* attr = */ NULL, sysevent_dequeue_thread,
- /* arg = */ (void *)0, "ssyevent");
+ int status =
+ plugin_thread_create(&sysevent_dequeue_thread_id, sysevent_dequeue_thread,
+ /* arg = */ (void *)0, "ssyevent");
if (status != 0) {
sysevent_dequeue_thread_loop = 0;
ERROR("sysevent plugin: Starting dequeue thread failed.");
int status;
int *remote_fd;
pthread_t th;
- pthread_attr_t th_attr;
-
- pthread_attr_init(&th_attr);
- pthread_attr_setdetachstate(&th_attr, PTHREAD_CREATE_DETACHED);
if (us_open_socket() != 0)
pthread_exit((void *)1);
ERROR("unixsock plugin: accept failed: %s", STRERRNO);
close(sock_fd);
sock_fd = -1;
- pthread_attr_destroy(&th_attr);
pthread_exit((void *)1);
}
DEBUG("Spawning child to handle connection on fd #%i", *remote_fd);
- status = plugin_thread_create(&th, &th_attr, us_handle_client,
- (void *)remote_fd, "unixsock conn");
- if (status != 0) {
+ status = plugin_thread_create(&th, us_handle_client, (void *)remote_fd,
+ "unixsock conn");
+ if (status == 0) {
+ pthread_detach(th);
+ } else {
WARNING("unixsock plugin: pthread_create failed: %s", STRERRNO);
close(*remote_fd);
free(remote_fd);
close(sock_fd);
sock_fd = -1;
- pthread_attr_destroy(&th_attr);
status = unlink((sock_file != NULL) ? sock_file : US_DEFAULT_PATH);
if (status != 0) {
loop = 1;
- status = plugin_thread_create(&listen_thread, NULL, us_server_thread, NULL,
+ status = plugin_thread_create(&listen_thread, us_server_thread, NULL,
"unixsock listen");
if (status != 0) {
ERROR("unixsock plugin: pthread_create failed: %s", STRERRNO);
}
/* start event thread */
pthread_t tid;
- if (plugin_thread_create(&tid, NULL, ovs_event_worker, pdb,
- "utils_ovs:event") != 0) {
+ if (plugin_thread_create(&tid, ovs_event_worker, pdb, "utils_ovs:event") !=
+ 0) {
pthread_mutex_unlock(&pdb->event_thread.mutex);
pthread_mutex_destroy(&pdb->event_thread.mutex);
pthread_cond_destroy(&pdb->event_thread.cond);
/* start poll thread */
pthread_t tid;
pdb->poll_thread.state = OVS_DB_POLL_STATE_RUNNING;
- if (plugin_thread_create(&tid, NULL, ovs_poll_worker, pdb,
- "utils_ovs:poll") != 0) {
+ if (plugin_thread_create(&tid, ovs_poll_worker, pdb, "utils_ovs:poll") != 0) {
pthread_mutex_destroy(&pdb->poll_thread.mutex);
return -1;
}