Make sure to guard against retrying the Avahi connection whilst already doing so (Ubuntu #877967).

This commit is contained in:
Tim Waugh 2011-10-19 11:55:09 +01:00
parent dbd9e735ec
commit a660226894
2 changed files with 61 additions and 42 deletions

View File

@ -1,6 +1,6 @@
diff -up cups-1.5.0/cgi-bin/admin.c.avahi-5-services cups-1.5.0/cgi-bin/admin.c
--- cups-1.5.0/cgi-bin/admin.c.avahi-5-services 2011-05-20 04:49:49.000000000 +0100
+++ cups-1.5.0/cgi-bin/admin.c 2011-10-11 11:36:13.571498447 +0100
+++ cups-1.5.0/cgi-bin/admin.c 2011-10-19 11:53:32.123177998 +0100
@@ -1643,7 +1643,7 @@ do_config_server(http_t *http) /* I - H
else
local_protocols[0] = '\0';
@ -33,7 +33,7 @@ diff -up cups-1.5.0/cgi-bin/admin.c.avahi-5-services cups-1.5.0/cgi-bin/admin.c
cgiSetVariable("HAVE_LDAP", "1");
diff -up cups-1.5.0/scheduler/client.c.avahi-5-services cups-1.5.0/scheduler/client.c
--- cups-1.5.0/scheduler/client.c.avahi-5-services 2011-06-10 22:16:18.000000000 +0100
+++ cups-1.5.0/scheduler/client.c 2011-10-11 11:36:13.575498374 +0100
+++ cups-1.5.0/scheduler/client.c 2011-10-19 11:53:32.127177926 +0100
@@ -4987,7 +4987,7 @@ valid_host(cupsd_client_t *con) /* I -
!strncmp(host, "[::1]:", 6));
}
@ -53,8 +53,8 @@ diff -up cups-1.5.0/scheduler/client.c.avahi-5-services cups-1.5.0/scheduler/cli
/*
* Check if the hostname is an IP address...
diff -up cups-1.5.0/scheduler/conf.c.avahi-5-services cups-1.5.0/scheduler/conf.c
--- cups-1.5.0/scheduler/conf.c.avahi-5-services 2011-10-11 11:36:11.893529370 +0100
+++ cups-1.5.0/scheduler/conf.c 2011-10-11 11:36:13.580498282 +0100
--- cups-1.5.0/scheduler/conf.c.avahi-5-services 2011-10-19 11:53:31.895182225 +0100
+++ cups-1.5.0/scheduler/conf.c 2011-10-19 11:53:32.131177850 +0100
@@ -651,7 +651,7 @@ cupsdReadConfiguration(void)
Browsing = CUPS_DEFAULT_BROWSING;
DefaultShared = CUPS_DEFAULT_DEFAULT_SHARED;
@ -65,8 +65,8 @@ diff -up cups-1.5.0/scheduler/conf.c.avahi-5-services cups-1.5.0/scheduler/conf.
#endif /* HAVE_DNSSD */
diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dirsvc.c
--- cups-1.5.0/scheduler/dirsvc.c.avahi-5-services 2011-10-11 11:36:12.084525850 +0100
+++ cups-1.5.0/scheduler/dirsvc.c 2011-10-11 11:36:13.585498189 +0100
--- cups-1.5.0/scheduler/dirsvc.c.avahi-5-services 2011-10-19 11:53:32.011180075 +0100
+++ cups-1.5.0/scheduler/dirsvc.c 2011-10-19 11:53:58.916681461 +0100
@@ -27,6 +27,7 @@
* ldap_connect() - Start new LDAP connection
* ldap_reconnect() - Reconnect to LDAP Server
@ -190,7 +190,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
}
@@ -1419,6 +1444,27 @@ ldap_disconnect(LDAP *ld) /* I - LDAP h
@@ -1419,6 +1444,36 @@ ldap_disconnect(LDAP *ld) /* I - LDAP h
#endif /* HAVE_LDAP */
@ -202,14 +202,23 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
+void
+cupsdStartAvahiClient(void)
+{
+ int error = 0;
+
+ if (!AvahiCupsClient && !AvahiCupsClientConnecting)
+ {
+ if (!AvahiCupsPollHandle)
+ AvahiCupsPollHandle = avahi_cups_poll_new ();
+
+ if (AvahiCupsPollHandle)
+ avahi_client_new (avahi_cups_poll_get (AvahiCupsPollHandle),
+ AVAHI_CLIENT_NO_FAIL, avahi_client_cb, NULL, NULL);
+ {
+ if (avahi_client_new (avahi_cups_poll_get (AvahiCupsPollHandle),
+ AVAHI_CLIENT_NO_FAIL,
+ avahi_client_cb, NULL,
+ &error) != NULL)
+ AvahiCupsClientConnecting = 1;
+ else
+ cupsdLogMessage (CUPSD_LOG_WARN, "Avahi client failed: %d", error);
+ }
+ }
+}
+#endif /* HAVE_AVAHI */
@ -218,7 +227,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* 'cupsdStartBrowsing()' - Start sending and receiving broadcast information.
*/
@@ -1542,13 +1588,16 @@ cupsdStartBrowsing(void)
@@ -1542,13 +1597,16 @@ cupsdStartBrowsing(void)
else
BrowseSocket = -1;
@ -236,7 +245,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* First create a "master" connection for all registrations...
*/
@@ -1573,6 +1622,7 @@ cupsdStartBrowsing(void)
@@ -1573,6 +1631,7 @@ cupsdStartBrowsing(void)
fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC);
cupsdAddSelect(fd, (cupsd_selfunc_t)dnssdUpdate, NULL, NULL);
@ -244,7 +253,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* Then get the port we use for registrations. If we are not listening
@@ -1598,17 +1648,23 @@ cupsdStartBrowsing(void)
@@ -1598,17 +1657,23 @@ cupsdStartBrowsing(void)
*/
if (BrowseRemoteProtocols & BROWSE_DNSSD)
@ -271,7 +280,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
#ifdef HAVE_LIBSLP
if ((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP)
@@ -1834,10 +1890,10 @@ cupsdStopBrowsing(void)
@@ -1834,10 +1899,10 @@ cupsdStopBrowsing(void)
BrowseSocket = -1;
}
@ -285,7 +294,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
#ifdef HAVE_LIBSLP
if (((BrowseLocalProtocols | BrowseRemoteProtocols) & BROWSE_SLP) &&
@@ -1902,7 +1958,7 @@ cupsdStopPolling(void)
@@ -1902,7 +1967,7 @@ cupsdStopPolling(void)
}
@ -294,7 +303,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* 'cupsdUpdateDNSSDName()' - Update the computer name we use for browsing...
*/
@@ -1910,8 +1966,14 @@ cupsdStopPolling(void)
@@ -1910,8 +1975,14 @@ cupsdStopPolling(void)
void
cupsdUpdateDNSSDName(void)
{
@ -309,7 +318,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
# ifdef HAVE_SYSTEMCONFIGURATION
SCDynamicStoreRef sc; /* Context for dynamic store */
CFDictionaryRef btmm; /* Back-to-My-Mac domains */
@@ -2042,6 +2104,7 @@ cupsdUpdateDNSSDName(void)
@@ -2042,6 +2113,7 @@ cupsdUpdateDNSSDName(void)
else
strlcpy(webif, "CUPS Web Interface", sizeof(webif));
@ -317,7 +326,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
if (WebIFRef)
DNSServiceRefDeallocate(WebIFRef);
@@ -2054,9 +2117,45 @@ cupsdUpdateDNSSDName(void)
@@ -2054,9 +2126,45 @@ cupsdUpdateDNSSDName(void)
NULL)) != kDNSServiceErr_NoError)
cupsdLogMessage(CUPSD_LOG_ERROR,
"DNS-SD web interface registration failed: %d", error);
@ -364,7 +373,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
#ifdef HAVE_LDAP
@@ -2334,13 +2433,15 @@ dnssdAddAlias(const void *key, /* I - K
@@ -2334,13 +2442,15 @@ dnssdAddAlias(const void *key, /* I - K
"Bad Back to My Mac domain in dynamic store!");
}
# endif /* HAVE_COREFOUNDATION */
@ -381,7 +390,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
dnssdBuildTxtRecord(
int *txt_len, /* O - TXT record length */
cupsd_printer_t *p, /* I - Printer information */
@@ -2379,7 +2480,12 @@ dnssdBuildTxtRecord(
@@ -2379,7 +2489,12 @@ dnssdBuildTxtRecord(
keyvalue[i ][0] = "ty";
keyvalue[i++][1] = p->make_model ? p->make_model : "Unknown";
@ -395,7 +404,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
httpAssembleURIf(HTTP_URI_CODING_ALL, adminurl_str, sizeof(adminurl_str),
"http", NULL, admin_hostname, DNSSDPort, "/%s/%s",
(p->type & CUPS_PRINTER_CLASS) ? "classes" : "printers",
@@ -2462,19 +2568,12 @@ dnssdBuildTxtRecord(
@@ -2462,19 +2577,12 @@ dnssdBuildTxtRecord(
* Then pack them into a proper txt record...
*/
@ -420,7 +429,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
}
@@ -2489,6 +2588,10 @@ dnssdDeregisterPrinter(
@@ -2489,6 +2597,10 @@ dnssdDeregisterPrinter(
{
cupsdLogMessage(CUPSD_LOG_DEBUG2, "dnssdDeregisterPrinter(%s)", p->name);
@ -431,7 +440,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* Closing the socket deregisters the service
*/
@@ -2524,6 +2627,24 @@ dnssdDeregisterPrinter(
@@ -2524,6 +2636,24 @@ dnssdDeregisterPrinter(
free(p->printer_txt);
p->printer_txt = NULL;
}
@ -456,7 +465,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* Remove the printer from the array of DNS-SD printers, then clear the
@@ -2533,8 +2654,10 @@ dnssdDeregisterPrinter(
@@ -2533,8 +2663,10 @@ dnssdDeregisterPrinter(
cupsArrayRemove(DNSSDPrinters, p);
cupsdClearString(&p->reg_name);
}
@ -467,7 +476,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* 'dnssdPackTxtRecord()' - Pack an array of key/value pairs into the
* TXT record format.
@@ -2644,8 +2767,10 @@ dnssdRegisterCallback(
@@ -2644,8 +2776,10 @@ dnssdRegisterCallback(
LastEvent |= CUPSD_EVENT_PRINTER_MODIFIED;
}
}
@ -478,7 +487,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* 'dnssdRegisterPrinter()' - Start sending broadcast information for a printer
* or update the broadcast contents.
@@ -2654,20 +2779,40 @@ dnssdRegisterCallback(
@@ -2654,20 +2788,40 @@ dnssdRegisterCallback(
static void
dnssdRegisterPrinter(cupsd_printer_t *p)/* I - Printer */
{
@ -522,7 +531,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* If per-printer sharing was just disabled make sure we're not
* registered before returning.
@@ -2686,12 +2831,36 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
@@ -2686,12 +2840,36 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
if (p->info && strlen(p->info) > 0)
{
if (DNSSDComputerName)
@ -561,7 +570,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
else
strlcpy(name, p->name, sizeof(name));
@@ -2712,6 +2881,7 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
@@ -2712,6 +2890,7 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
* Register IPP and (optionally) LPD...
*/
@ -569,7 +578,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
ipp_len = 0; /* anti-compiler-warning-code */
ipp_txt = dnssdBuildTxtRecord(&ipp_len, p, 0);
@@ -2884,6 +3054,209 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
@@ -2884,6 +3063,209 @@ dnssdRegisterPrinter(cupsd_printer_t *p)
if (printer_txt)
free(printer_txt);
@ -779,7 +788,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
}
@@ -2896,6 +3269,10 @@ dnssdStop(void)
@@ -2896,6 +3278,10 @@ dnssdStop(void)
{
cupsd_printer_t *p; /* Current printer */
@ -790,7 +799,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* De-register the individual printers
@@ -2906,6 +3283,7 @@ dnssdStop(void)
@@ -2906,6 +3292,7 @@ dnssdStop(void)
p = (cupsd_printer_t *)cupsArrayNext(Printers))
dnssdDeregisterPrinter(p);
@ -798,7 +807,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* Shutdown the rest of the service refs...
*/
@@ -2926,14 +3304,17 @@ dnssdStop(void)
@@ -2926,14 +3313,17 @@ dnssdStop(void)
DNSServiceRefDeallocate(DNSSDRef);
DNSSDRef = NULL;
@ -816,7 +825,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
/*
* 'dnssdUpdate()' - Handle DNS-SD queries.
*/
@@ -2955,6 +3336,147 @@ dnssdUpdate(void)
@@ -2955,6 +3345,153 @@ dnssdUpdate(void)
#endif /* HAVE_DNSSD */
@ -931,10 +940,16 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
+ /*
+ * No Avahi daemon, client is waiting.
+ */
+ AvahiCupsClientConnecting = 1;
+ cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client connecting");
+ break;
+
+ case AVAHI_CLIENT_S_REGISTERING:
+ /*
+ * Not yet registered.
+ */
+ cupsdLogMessage (CUPSD_LOG_DEBUG, "Avahi client registering");
+ break;
+
+ case AVAHI_CLIENT_FAILURE:
+ /*
+ * Avahi client failed, close it to allow a clean restart.
@ -966,7 +981,7 @@ diff -up cups-1.5.0/scheduler/dirsvc.c.avahi-5-services cups-1.5.0/scheduler/dir
*/
diff -up cups-1.5.0/scheduler/dirsvc.h.avahi-5-services cups-1.5.0/scheduler/dirsvc.h
--- cups-1.5.0/scheduler/dirsvc.h.avahi-5-services 2011-03-21 02:12:14.000000000 +0000
+++ cups-1.5.0/scheduler/dirsvc.h 2011-10-11 11:36:13.587498153 +0100
+++ cups-1.5.0/scheduler/dirsvc.h 2011-10-19 11:53:32.138177721 +0100
@@ -31,6 +31,10 @@
# endif /* HAVE_LDAP_SSL_H */
#endif /* HAVE_LDAP */
@ -1040,8 +1055,8 @@ diff -up cups-1.5.0/scheduler/dirsvc.h.avahi-5-services cups-1.5.0/scheduler/dir
extern void cupsdUpdateLDAPBrowse(void);
#endif /* HAVE_LDAP */
diff -up cups-1.5.0/scheduler/ipp.c.avahi-5-services cups-1.5.0/scheduler/ipp.c
--- cups-1.5.0/scheduler/ipp.c.avahi-5-services 2011-10-11 11:36:12.042526624 +0100
+++ cups-1.5.0/scheduler/ipp.c 2011-10-11 11:36:13.596497987 +0100
--- cups-1.5.0/scheduler/ipp.c.avahi-5-services 2011-10-19 11:53:31.978180686 +0100
+++ cups-1.5.0/scheduler/ipp.c 2011-10-19 11:53:32.147177555 +0100
@@ -6096,7 +6096,7 @@ copy_printer_attrs(
ippAddDate(con->response, IPP_TAG_PRINTER, "printer-current-time",
ippTimeToDate(curtime));
@ -1061,8 +1076,8 @@ diff -up cups-1.5.0/scheduler/ipp.c.avahi-5-services cups-1.5.0/scheduler/ipp.c
if (!ra || cupsArrayFind(ra, "printer-error-policy"))
ippAddString(con->response, IPP_TAG_PRINTER, IPP_TAG_NAME,
diff -up cups-1.5.0/scheduler/main.c.avahi-5-services cups-1.5.0/scheduler/main.c
--- cups-1.5.0/scheduler/main.c.avahi-5-services 2011-10-11 11:36:12.186523971 +0100
+++ cups-1.5.0/scheduler/main.c 2011-10-11 11:36:13.600497913 +0100
--- cups-1.5.0/scheduler/main.c.avahi-5-services 2011-10-19 11:53:32.101178406 +0100
+++ cups-1.5.0/scheduler/main.c 2011-10-19 11:53:32.151177479 +0100
@@ -120,6 +120,10 @@ main(int argc, /* I - Number of comm
cupsd_listener_t *lis; /* Current listener */
time_t current_time, /* Current time */
@ -1102,8 +1117,8 @@ diff -up cups-1.5.0/scheduler/main.c.avahi-5-services cups-1.5.0/scheduler/main.
#ifndef __APPLE__
diff -up cups-1.5.0/scheduler/printers.c.avahi-5-services cups-1.5.0/scheduler/printers.c
--- cups-1.5.0/scheduler/printers.c.avahi-5-services 2011-10-11 11:36:11.958528172 +0100
+++ cups-1.5.0/scheduler/printers.c 2011-10-11 11:36:13.606497802 +0100
--- cups-1.5.0/scheduler/printers.c.avahi-5-services 2011-10-19 11:53:31.916181835 +0100
+++ cups-1.5.0/scheduler/printers.c 2011-10-19 11:53:32.156177388 +0100
@@ -883,9 +883,9 @@ cupsdDeletePrinter(
cupsdClearString(&p->alert);
cupsdClearString(&p->alert_description);
@ -1136,7 +1151,7 @@ diff -up cups-1.5.0/scheduler/printers.c.avahi-5-services cups-1.5.0/scheduler/p
diff -up cups-1.5.0/scheduler/printers.h.avahi-5-services cups-1.5.0/scheduler/printers.h
--- cups-1.5.0/scheduler/printers.h.avahi-5-services 2011-03-18 18:42:46.000000000 +0000
+++ cups-1.5.0/scheduler/printers.h 2011-10-11 11:36:13.609497747 +0100
+++ cups-1.5.0/scheduler/printers.h 2011-10-19 11:53:32.157177369 +0100
@@ -16,6 +16,9 @@
#ifdef HAVE_DNSSD
# include <dns_sd.h>

View File

@ -13,7 +13,7 @@
Summary: Common Unix Printing System
Name: cups
Version: 1.5.0
Release: 17%{?dist}
Release: 18%{?dist}
License: GPLv2
Group: System Environment/Daemons
Source: http://ftp.easysw.com/pub/cups/%{version}/cups-%{version}-source.tar.bz2
@ -646,6 +646,10 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/ipptool.1.gz
%changelog
* Wed Oct 19 2011 Tim Waugh <twaugh@redhat.com> 1:1.5.0-18
- Make sure to guard against retrying the Avahi connection whilst
already doing so (Ubuntu #877967).
* Tue Oct 18 2011 Tim Waugh <twaugh@redhat.com> 1:1.5.0-17
- Use libsystemd-daemon instead of bundling sd-daemon.c.