summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomas Bzatek <tbzatek@redhat.com>2013-10-30 12:16:14 +0100
committerTomas Bzatek <tbzatek@redhat.com>2013-10-30 13:30:55 +0100
commit793843369a4445f8602ef176b41c828730cb4404 (patch)
tree3cf841b48f3cc7394a17414a710cffe07036ae68 /src
parentfd999feb7387941a1af16c777a5d83b50d79bad1 (diff)
downloadopenlmi-providers-793843369a4445f8602ef176b41c828730cb4404.tar.gz
openlmi-providers-793843369a4445f8602ef176b41c828730cb4404.tar.xz
openlmi-providers-793843369a4445f8602ef176b41c828730cb4404.zip
indmanager: Use proper mutex error checking
Things are bit harsh in the indication manager when it comes to cancellation. At certain situation we force-cancel the polling thread, having no chance for cleanup. The mutex we use to protect memory shared between threads may be left in undefined state. The pthread_mutex_unlock() call in im_stop_ind() may be called on already unlocked mutex which, in default setup, causes a segfault. Setting a mutex attribute PTHREAD_MUTEX_ERRORCHECK will prevent this, returning proper error.
Diffstat (limited to 'src')
-rw-r--r--src/indmanager/ind_manager.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/indmanager/ind_manager.c b/src/indmanager/ind_manager.c
index 805806f..525d2f8 100644
--- a/src/indmanager/ind_manager.c
+++ b/src/indmanager/ind_manager.c
@@ -74,6 +74,7 @@ bool maybe_remove_polled(IMManager *, CMPIObjectPath *, IMError *);
/* For threading purposes */
pthread_t _t_manage;
pthread_mutex_t _t_mutex;
+pthread_mutexattr_t _t_mutex_attr;
pthread_cond_t _t_cond;
/* CMPI rc handler */
@@ -831,7 +832,9 @@ IMManager* im_create_manager(IMInstGather gather, IMFilterChecker f_checker,
manager->data = NULL;
DEBUG("Manager created");
- if (pthread_mutex_init(&_t_mutex, NULL) ||
+ if (pthread_mutexattr_init(&_t_mutex_attr) ||
+ pthread_mutexattr_settype(&_t_mutex_attr, PTHREAD_MUTEX_ERRORCHECK) ||
+ pthread_mutex_init(&_t_mutex, &_t_mutex_attr) ||
pthread_cond_init(&_t_cond, NULL)) {
*err = IM_ERR_THREAD;
free(manager);
@@ -860,7 +863,8 @@ bool im_destroy_manager(IMManager *manager, const CMPIContext *ctx,
}
pthread_mutex_unlock(&_t_mutex);
DEBUG("Destroying manager");
- if (pthread_mutex_destroy(&_t_mutex)) {
+ if (pthread_mutex_destroy(&_t_mutex) ||
+ pthread_mutexattr_destroy(&_t_mutex_attr)) {
*err = IM_ERR_THREAD;
return false;
}