X-Git-Url: http://git.liburcu.org/?a=blobdiff_plain;f=libust%2Ftracectl.c;h=0cff6fda9f035e8a009232268530e8e39e206ab4;hb=83aa16929ed1e60fabe1bda4824e7c4942ff42ec;hp=bef4537dd4ffeb5311c4e83dabbf60adfbb3fbd3;hpb=fd9c2963da6a81c0d04e09e21156ddcf2fa5efff;p=ust.git diff --git a/libust/tracectl.c b/libust/tracectl.c index bef4537..0cff6fd 100644 --- a/libust/tracectl.c +++ b/libust/tracectl.c @@ -543,6 +543,11 @@ unlock_traces: return retval; } +static void release_listener_mutex(void *ptr) +{ + pthread_mutex_unlock(&listener_thread_data_mutex); +} + static void listener_cleanup(void *ptr) { pthread_mutex_lock(&listen_sock_mutex); @@ -952,7 +957,7 @@ static void process_client_cmd(struct ustcomm_header *recv_header, print_markers(fp); fclose(fp); - reply_header->size = size; + reply_header->size = size + 1; /* Include final \0 */ result = ustcomm_send(sock, reply_header, ptr); @@ -978,7 +983,7 @@ static void process_client_cmd(struct ustcomm_header *recv_header, print_trace_events(fp); fclose(fp); - reply_header->size = size; + reply_header->size = size + 1; /* Include final \0 */ result = ustcomm_send(sock, reply_header, ptr); @@ -1096,6 +1101,7 @@ void *listener_main(void *p) for (i = 0; i < nfds; i++) { pthread_mutex_lock(&listener_thread_data_mutex); + pthread_cleanup_push(release_listener_mutex, NULL); epoll_sock = (struct ustcomm_sock *)events[i].data.ptr; if (epoll_sock == listen_sock) { addr_size = sizeof(struct sockaddr); @@ -1124,7 +1130,7 @@ void *listener_main(void *p) epoll_sock->fd); } } - pthread_mutex_unlock(&listener_thread_data_mutex); + pthread_cleanup_pop(1); /* release listener mutex */ } } @@ -1711,7 +1717,7 @@ static void ust_after_fork_common(ust_fork_info_t *fork_info) void ust_after_fork_parent(ust_fork_info_t *fork_info) { - /* Reenable signals */ + /* Release mutexes and reenable signals */ ust_after_fork_common(fork_info); } @@ -1720,7 +1726,15 @@ void ust_after_fork_child(ust_fork_info_t *fork_info) /* First sanitize the child */ ust_fork(); - /* Then reenable interrupts */ + /* Then release mutexes and reenable signals */ ust_after_fork_common(fork_info); + + /* + * Make sure we clean up the urcu-bp thread list in the child by running + * the garbage collection before any pthread_create can be called. + * Failure to do so could lead to a deadlock caused by reuse of a thread + * ID before urcu-bp garbage collection is performed. + */ + synchronize_rcu(); }