@@ -16,7 +16,7 @@
#else
#define lock(a) pthread_mutex_lock(a)
#define unlock(a) pthread_mutex_unlock(a)
-#define lock_cleanup_pop(a) pthread_cleanup_pop(1);
+#define lock_cleanup_pop(a) pthread_cleanup_pop(1)
#endif
void cleanup_lock (void * data);
@@ -100,6 +100,11 @@
}
}
+void cancel_thread(void * data)
+{
+ pthread_cancel((pthread_t)data);
+}
+
int uevent_listen(int (*uev_trigger)(struct uevent *, void * trigger_data),
void * trigger_data)
{
@@ -130,6 +135,7 @@
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 64 * 1024);
pthread_create(&uevq_thr, &attr, uevq_thread, NULL);
+ pthread_cleanup_push(cancel_thread, (void *)uevq_thr);
memset(&snl, 0x00, sizeof(struct sockaddr_nl));
snl.nl_family = AF_NETLINK;
@@ -255,7 +261,7 @@
close(sock);
pthread_mutex_lock(uevq_lockp);
- pthread_cancel(uevq_thr);
+ pthread_cleanup_pop(1);
pthread_mutex_unlock(uevq_lockp);
pthread_mutex_destroy(uevq_lockp);
@@ -82,6 +82,7 @@
pthread_cond_t exit_cond = PTHREAD_COND_INITIALIZER;
pthread_mutex_t exit_mutex = PTHREAD_MUTEX_INITIALIZER;
+int exitting = 0;
/*
* global copy of vecs for use in sig handlers
*/
@@ -648,6 +649,7 @@
pthread_cleanup_push(cleanup_lock, vecs->lock);
lock(vecs->lock);
+ pthread_testcancel();
r = parse_cmd(str, reply, len, vecs);
@@ -696,7 +698,9 @@
return 0;
basenamecpy(uev->devpath, devname);
+ pthread_cleanup_push(cleanup_lock, vecs->lock);
lock(vecs->lock);
+ pthread_testcancel();
/*
* device map event
@@ -736,6 +740,8 @@
out:
unlock(vecs->lock);
+ lock_cleanup_pop(vecs->lock);
+/* ; */
return r;
}
@@ -941,14 +947,15 @@
{
int oldpriority;
struct pathgroup * pgp;
+ struct path *pp1;
int i, j, changed = 0;
if (refresh_all) {
vector_foreach_slot (pp->mpp->pg, pgp, i) {
- vector_foreach_slot (pgp->paths, pp, j) {
- oldpriority = pp->priority;
- pathinfo(pp, conf->hwtable, DI_PRIO);
- if (pp->priority != oldpriority)
+ vector_foreach_slot (pgp->paths, pp1, j) {
+ oldpriority = pp1->priority;
+ pathinfo(pp1, conf->hwtable, DI_PRIO);
+ if (pp1->priority != oldpriority)
changed = 1;
}
}
@@ -1012,6 +1019,7 @@
block_signal(SIGHUP, &old);
pthread_cleanup_push(cleanup_lock, vecs->lock);
lock(vecs->lock);
+ pthread_testcancel();
condlog(4, "tick");
vector_foreach_slot (vecs->pathvec, pp, i) {
@@ -1497,7 +1505,8 @@
condlog(2, "reconfigure (SIGHUP)");
lock(gvecs->lock);
- reconfigure(gvecs);
+ if (!exitting);
+ reconfigure(gvecs);
unlock(gvecs->lock);
#ifdef _DEBUG_
@@ -1698,6 +1707,7 @@
*/
block_signal(SIGHUP, NULL);
lock(vecs->lock);
+ exitting = 1;
if (conf->queue_without_daemon == QUE_NO_DAEMON_OFF)
vector_foreach_slot(vecs->mpvec, mpp, i)
dm_queue_if_no_path(mpp->alias, 0);