In the following scenario on an SMP system the ust-consumerd can end
up not properly closing out file handles which leads to log
corruption:
* usttrace -m -l small_quick_app_lots_of_malloc_and_free
* The app completes and usttrace sees and sends the SIGTERM to ust-consumerd
* The ust-consumerd main thread will exit and the _exit() handlers
kills off the remaining pthreads without everything getting closed out
The solution to the problem is to introduce an active_thread count for
the private ustconsumer_instance. This counter will be zeroed out
when it is safe to completely shutdown the main thread, which will
subsequently run the _exit() handlers.
Signed-off-by: Jason Wessel <jason.wessel@windriver.com>
Signed-off-by: Nils Carlson <nils.carlson@ericsson.com>
char *sock_path;
pthread_mutex_t mutex;
int active_buffers;
char *sock_path;
pthread_mutex_t mutex;
int active_buffers;
int result;
sigset_t sigset;
int result;
sigset_t sigset;
+ pthread_mutex_lock(&args->instance->mutex);
+ args->instance->active_threads++;
+ pthread_mutex_unlock(&args->instance->mutex);
+
if(args->instance->callbacks->on_new_thread)
args->instance->callbacks->on_new_thread(args->instance->callbacks);
if(args->instance->callbacks->on_new_thread)
args->instance->callbacks->on_new_thread(args->instance->callbacks);
if(args->instance->callbacks->on_close_thread)
args->instance->callbacks->on_close_thread(args->instance->callbacks);
if(args->instance->callbacks->on_close_thread)
args->instance->callbacks->on_close_thread(args->instance->callbacks);
+ pthread_mutex_lock(&args->instance->mutex);
+ args->instance->active_threads--;
+ pthread_mutex_unlock(&args->instance->mutex);
+
free((void *)args->channel);
free(args);
return NULL;
free((void *)args->channel);
free(args);
return NULL;
if (instance->quit_program) {
pthread_mutex_lock(&instance->mutex);
if (instance->quit_program) {
pthread_mutex_lock(&instance->mutex);
- if(instance->active_buffers == 0) {
+ if (instance->active_buffers == 0 && instance->active_threads == 0) {
pthread_mutex_unlock(&instance->mutex);
break;
}
pthread_mutex_unlock(&instance->mutex);
break;
}