From 219a877858e73b52b33c99d0b71a17a6e6305be3 Mon Sep 17 00:00:00 2001 From: Olaf Meeuwissen Date: Thu, 24 Sep 2015 20:56:00 +0900 Subject: [PATCH] net: Add mutex lock logic around device additions The avahi_thread may call add_device() as well. This addresses a concern raised in 313921 and may fix 314696 as well as 315044. --- backend/net.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/net.c b/backend/net.c index a3ebded27..4beb45d10 100644 --- a/backend/net.c +++ b/backend/net.c @@ -1044,9 +1044,14 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) continue; } - +#ifdef WITH_AVAHI + avahi_threaded_poll_lock (avahi_thread); +#endif /* WITH_AVAHI */ DBG (2, "sane_init: trying to add %s\n", device_name); add_device (device_name, 0); +#ifdef WITH_AVAHI + avahi_threaded_poll_unlock (avahi_thread); +#endif /* WITH_AVAHI */ } fclose (fp); @@ -1090,8 +1095,14 @@ sane_init (SANE_Int * version_code, SANE_Auth_Callback authorize) if (host[0] == '\0') continue; #endif /* ENABLE_IPV6 */ +#ifdef WITH_AVAHI + avahi_threaded_poll_lock (avahi_thread); +#endif /* WITH_AVAHI */ DBG (2, "sane_init: trying to add %s\n", host); add_device (host, 0); +#ifdef WITH_AVAHI + avahi_threaded_poll_unlock (avahi_thread); +#endif /* WITH_AVAHI */ } free (copy); } @@ -1507,7 +1518,13 @@ sane_open (SANE_String_Const full_name, SANE_Handle * meta_handle) DBG (1, "sane_open: device %s not found, trying to register it anyway\n", nd_name); +#ifdef WITH_AVAHI + avahi_threaded_poll_lock (avahi_thread); +#endif /* WITH_AVAHI */ status = add_device (nd_name, &dev); +#ifdef WITH_AVAHI + avahi_threaded_poll_unlock (avahi_thread); +#endif /* WITH_AVAHI */ if (status != SANE_STATUS_GOOD) { DBG (1, "sane_open: could not open device\n");