f20720
---
f20720
 libmultipath/uevent.c |   17 ++++++++++++-----
f20720
 libmultipath/uevent.h |    4 +++-
f20720
 multipathd/main.c     |    8 +++++---
f20720
 3 files changed, 20 insertions(+), 9 deletions(-)
f20720
f20720
Index: multipath-tools-130222/libmultipath/uevent.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/uevent.c
f20720
+++ multipath-tools-130222/libmultipath/uevent.c
f20720
@@ -47,7 +47,6 @@
f20720
 #include "list.h"
f20720
 #include "uevent.h"
f20720
 #include "vector.h"
f20720
-#include "config.h"
f20720
 
f20720
 typedef int (uev_trigger)(struct uevent *, void * trigger_data);
f20720
 
f20720
@@ -127,11 +126,14 @@ service_uevq(struct list_head *tmpq)
f20720
 
f20720
 static void uevq_stop(void *arg)
f20720
 {
f20720
+	struct udev *udev = arg;
f20720
+
f20720
 	condlog(3, "Stopping uev queue");
f20720
 	pthread_mutex_lock(uevq_lockp);
f20720
 	my_uev_trigger = NULL;
f20720
 	pthread_cond_signal(uev_condp);
f20720
 	pthread_mutex_unlock(uevq_lockp);
f20720
+	udev_unref(udev);
f20720
 }
f20720
 
f20720
 void
f20720
@@ -399,9 +401,9 @@ exit:
f20720
 	return 1;
f20720
 }
f20720
 
f20720
-int uevent_listen(void)
f20720
+int uevent_listen(struct udev *udev)
f20720
 {
f20720
-	int err;
f20720
+	int err = 2;
f20720
 	struct udev_monitor *monitor = NULL;
f20720
 	int fd, socket_flags;
f20720
 	int need_failback = 1;
f20720
@@ -411,9 +413,14 @@ int uevent_listen(void)
f20720
 	 * thereby not getting to empty the socket's receive buffer queue
f20720
 	 * often enough.
f20720
 	 */
f20720
-	pthread_cleanup_push(uevq_stop, NULL);
f20720
+	if (!udev) {
f20720
+		condlog(1, "no udev context");
f20720
+		return 1;
f20720
+	}
f20720
+	udev_ref(udev);
f20720
+	pthread_cleanup_push(uevq_stop, udev);
f20720
 
f20720
-	monitor = udev_monitor_new_from_netlink(conf->udev, "udev");
f20720
+	monitor = udev_monitor_new_from_netlink(udev, "udev");
f20720
 	if (!monitor) {
f20720
 		condlog(2, "failed to create udev monitor");
f20720
 		goto out;
f20720
Index: multipath-tools-130222/libmultipath/uevent.h
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/libmultipath/uevent.h
f20720
+++ multipath-tools-130222/libmultipath/uevent.h
f20720
@@ -13,6 +13,8 @@
f20720
 #define NETLINK_KOBJECT_UEVENT		15
f20720
 #endif
f20720
 
f20720
+struct udev;
f20720
+
f20720
 struct uevent {
f20720
 	struct list_head node;
f20720
 	struct udev_device *udev;
f20720
@@ -27,7 +29,7 @@ struct uevent {
f20720
 int is_uevent_busy(void);
f20720
 void setup_thread_attr(pthread_attr_t *attr, size_t stacksize, int detached);
f20720
 
f20720
-int uevent_listen(void);
f20720
+int uevent_listen(struct udev *udev);
f20720
 int uevent_dispatch(int (*store_uev)(struct uevent *, void * trigger_data),
f20720
 		    void * trigger_data);
f20720
 int uevent_get_major(struct uevent *uev);
f20720
Index: multipath-tools-130222/multipathd/main.c
f20720
===================================================================
f20720
--- multipath-tools-130222.orig/multipathd/main.c
f20720
+++ multipath-tools-130222/multipathd/main.c
f20720
@@ -840,7 +840,7 @@ out:
f20720
 static void *
f20720
 ueventloop (void * ap)
f20720
 {
f20720
-	if (uevent_listen())
f20720
+	if (uevent_listen(udev))
f20720
 		condlog(0, "error starting uevent listener");
f20720
 
f20720
 	return NULL;
f20720
@@ -1593,7 +1593,7 @@ static int
f20720
 child (void * param)
f20720
 {
f20720
 	pthread_t check_thr, uevent_thr, uxlsnr_thr, uevq_thr;
f20720
-	pthread_attr_t log_attr, misc_attr;
f20720
+	pthread_attr_t log_attr, misc_attr, uevent_attr;
f20720
 	struct vectors * vecs;
f20720
 	struct multipath * mpp;
f20720
 	int i;
f20720
@@ -1606,6 +1606,7 @@ child (void * param)
f20720
 	udev = udev_new();
f20720
 
f20720
 	setup_thread_attr(&misc_attr, 64 * 1024, 1);
f20720
+	setup_thread_attr(&uevent_attr, 128 * 1024, 1);
f20720
 	setup_thread_attr(&waiter_attr, 32 * 1024, 1);
f20720
 
f20720
 	if (logsink) {
f20720
@@ -1671,10 +1672,11 @@ child (void * param)
f20720
 	/*
f20720
 	 * Start uevent listener early to catch events
f20720
 	 */
f20720
-	if ((rc = pthread_create(&uevent_thr, &misc_attr, ueventloop, vecs))) {
f20720
+	if ((rc = pthread_create(&uevent_thr, &uevent_attr, ueventloop, udev))) {
f20720
 		condlog(0, "failed to create uevent thread: %d", rc);
f20720
 		exit(1);
f20720
 	}
f20720
+	pthread_attr_destroy(&uevent_attr);
f20720
 	if ((rc = pthread_create(&uxlsnr_thr, &misc_attr, uxlsnrloop, vecs))) {
f20720
 		condlog(0, "failed to create cli listener: %d", rc);
f20720
 		exit(1);