[Nagios-devel] improper mutex re-initialization
Posted: Fri Apr 24, 2009 10:37 pm
The comments I'm making here are relative to nagios 3.0.6 code.
In base/utils.c, init_command_file_worker_thread() contains a
call to pthread_mutex_init(). But there are paths through the
code wherein init_command_file_worker_thread() might be called
a second time. (If nagios is restarted,
shutdown_command_file_worker_thread() and then open_command_file(),
which calls init_command_file_worker_thread(), would be called,
and this would result in a second call to pthread_mutex_init() on
the same mutex.) However, initializing an initialized mutex
results in undefined behavior. The best fix is probably not to try
to dynamically initialize the external_command_buffer.buffer_lock
mutex. Rather, it should be statically initialized in nagios.c,
where external_command_buffer is defined:
circular_buffer external_command_buffer = {
NULL, /* void **buffer; */
0, /* int tail; */
0, /* int head; */
0, /* int items; */
0, /* int high; */
0L, /* unsigned long overflow; */
PTHREAD_MUTEX_INITIALIZER /* pthread_mutex_t buffer_lock; */
};
This post was automatically imported from historical nagios-devel mailing list archives
Original poster: [email protected]