[cups/f16] Array handling fixes for Avahi poll implementation.

Tim Waugh twaugh at fedoraproject.org
Tue Oct 11 12:10:08 UTC 2011


commit 3f9aa63f175bb78c0ac73cd3cff6097db23167fc
Author: Tim Waugh <twaugh at redhat.com>
Date:   Tue Oct 11 11:31:32 2011 +0100

    Array handling fixes for Avahi poll implementation.

 cups-avahi-4-poll.patch |  162 ++++++++++++++++++++++++++---------------------
 cups.spec               |    3 +-
 2 files changed, 91 insertions(+), 74 deletions(-)
---
diff --git a/cups-avahi-4-poll.patch b/cups-avahi-4-poll.patch
index e7ff82d..189e83d 100644
--- a/cups-avahi-4-poll.patch
+++ b/cups-avahi-4-poll.patch
@@ -1,19 +1,39 @@
 diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
---- cups-1.5.0/scheduler/avahi.c.avahi-4-poll	2011-08-05 15:07:09.570033486 +0100
-+++ cups-1.5.0/scheduler/avahi.c	2011-08-05 15:07:09.570033486 +0100
-@@ -0,0 +1,445 @@
+--- cups-1.5.0/scheduler/avahi.c.avahi-4-poll	2011-10-11 10:56:50.102288037 +0100
++++ cups-1.5.0/scheduler/avahi.c	2011-10-11 10:56:50.102288037 +0100
+@@ -0,0 +1,441 @@
 +/*
 + * "$Id$"
 + *
 + *   Avahi poll implementation for the CUPS scheduler.
 + *
-+ *   Copyright (C) 2010 Red Hat, Inc.
++ *   Copyright (C) 2010, 2011 Red Hat, Inc.
 + *   Authors:
 + *    Tim Waugh <twaugh at redhat.com>
 + *
-+ *   Distribution and use rights are outlined in the file "LICENSE.txt"
-+ *   "LICENSE" which should have been included with this file.  If this
-+ *   file is missing or damaged, see the license at "http://www.cups.org/".
++ *   Redistribution and use in source and binary forms, with or without
++ *   modification, are permitted provided that the following conditions
++ *   are met:
++ *
++ *   Redistributions of source code must retain the above copyright
++ *   notice, this list of conditions and the following disclaimer.
++ *
++ *   Redistributions in binary form must reproduce the above copyright
++ *   notice, this list of conditions and the following disclaimer in the
++ *   documentation and/or other materials provided with the distribution.
++ *
++ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
++ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
++ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
++ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
++ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
++ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
++ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
++ *   OF THE POSSIBILITY OF SUCH DAMAGE.
 + *
 + * Contents:
 + *
@@ -29,7 +49,6 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 + *   timeout_update()      - Update the expiration time for a timeout
 + *   timeout_free()        - Free a timeout
 + *   compare_watched_fds() - Compare watched file descriptors for array sorting
-+ *   compare_timeouts()    - Compare timeouts for array sorting
 + *   avahi_cups_poll_new() - Create a new Avahi main loop object for CUPS
 + *   avahi_cups_poll_free() - Free an Avahi main loop object for CUPS
 + *   avahi_cups_poll_get() - Get the abstract poll API structure
@@ -93,8 +112,6 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +static void		watch_update(AvahiWatch *watch,
 +				     AvahiWatchEvent events);
 +static AvahiWatchEvent	watch_get_events(AvahiWatch *watch);
-+static int		compare_watches(AvahiWatch *p0,
-+					AvahiWatch *p1);
 +
 +
 +/*
@@ -109,8 +126,10 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +  watched_fd->occurred |= AVAHI_WATCH_IN;
 +  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
 +       watch;
-+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches)) {
-+    if (watch->events & watched_fd->occurred) {
++       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
++  {
++    if (watch->events & watched_fd->occurred)
++    {
 +      (watch->callback) (watch, watched_fd->fd,
 +			 AVAHI_WATCH_IN, watch->userdata);
 +      watched_fd->occurred &= ~AVAHI_WATCH_IN;
@@ -132,8 +151,10 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +  watched_fd->occurred |= AVAHI_WATCH_OUT;
 +  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
 +       watch;
-+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches)) {
-+    if (watch->events & watched_fd->occurred) {
++       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
++  {
++    if (watch->events & watched_fd->occurred)
++    {
 +      (watch->callback) (watch, watched_fd->fd,
 +			 AVAHI_WATCH_OUT, watch->userdata);
 +      watched_fd->occurred &= ~AVAHI_WATCH_OUT;
@@ -152,19 +173,24 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +{
 +  AvahiWatch *watch;
 +  cupsd_selfunc_t read_cb = NULL, write_cb = NULL;
++  int any_watches = 0;
 +
 +  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
 +       watch;
-+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches)) {
++       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
++  {
++    any_watches = 1;
 +    if (watch->events & (AVAHI_WATCH_IN |
 +			     AVAHI_WATCH_ERR |
-+			     AVAHI_WATCH_HUP)) {
++			     AVAHI_WATCH_HUP))
++    {
 +      read_cb = (cupsd_selfunc_t)watch_read_cb;
 +      if (write_cb != NULL)
 +	break;
 +    }
 +
-+    if (watch->events & AVAHI_WATCH_OUT) {
++    if (watch->events & AVAHI_WATCH_OUT)
++    {
 +      write_cb = (cupsd_selfunc_t)watch_write_cb;
 +      if (read_cb != NULL)
 +	break;
@@ -176,7 +202,7 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +  else
 +    cupsdRemoveSelect (watched_fd->fd);
 +
-+  return (read_cb || write_cb);
++  return (any_watches);
 +}
 +
 +/*
@@ -202,9 +228,11 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +
 +  key.fd = fd;
 +  watched_fd = cupsArrayFind (cups_poll->watched_fds, &key);
-+  if (watched_fd == NULL) {
++  if (watched_fd == NULL)
++  {
 +    watched_fd = malloc(sizeof(cupsd_watched_fd_t));
-+    if (watched_fd == NULL) {
++    if (watched_fd == NULL)
++    {
 +      free (watch);
 +      return (NULL);
 +    }
@@ -212,8 +240,8 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +    watched_fd->fd = fd;
 +    watched_fd->occurred = 0;
 +    watched_fd->cups_poll = cups_poll;
-+    watched_fd->watches = cupsArrayNew ((cups_array_func_t)compare_watches,
-+					NULL);
++    watched_fd->watches = cupsArrayNew (NULL, NULL);
++    cupsArrayAdd (cups_poll->watched_fds, watched_fd);
 +  }
 +
 +  watch->watched_fd = watched_fd;
@@ -236,7 +264,8 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +  cupsArrayRemove (watched_fd->watches, watch);
 +  free (watch);
 +
-+  if (!watched_fd_add_select (watched_fd)) {
++  if (!watched_fd_add_select (watched_fd))
++  {
 +    /* No more watches */
 +    cupsArrayRemove (cups_poll->watched_fds, watched_fd);
 +    free (watched_fd);
@@ -269,21 +298,6 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +
 +
 +/*
-+ * 'compare_watches' - Compare watches for array sorting
-+ */
-+
-+static int
-+compare_watches (AvahiWatch *p0,
-+		 AvahiWatch *p1)
-+{
-+  if (p0->watched_fd->fd < p1->watched_fd->fd)
-+    return (-1);
-+
-+  return ((p0->watched_fd->fd == p1->watched_fd->fd) ? 0 : 1);
-+}
-+
-+
-+/*
 + * 'timeout_cb()' - Run a timed Avahi callback
 + */
 +
@@ -355,30 +369,14 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +compare_watched_fds(cupsd_watched_fd_t *p0,
 +		    cupsd_watched_fd_t *p1)
 +{
-+  if (p0->fd != p1->fd)
-+    return (p0->fd < p1->fd ? -1 : 1);
++  /*
++   * Compare by fd (no two elements have the same fd)
++   */
 +
-+  if (p0 == p1)
-+    return (0);
++  if (p0->fd == p1->fd)
++    return 0;
 +
-+  return (p0 < p1 ? -1 : 1);
-+}
-+
-+
-+/*
-+ * 'compare_timeouts' - Compare timeouts for array sorting
-+ */
-+static int
-+compare_timeouts(AvahiTimeout *p0,
-+		 AvahiTimeout *p1)
-+{
-+ /*
-+  * Just compare pointers to make it a stable sort.
-+  */
-+
-+  if (p0->cupsd_timeout < p1->cupsd_timeout)
-+    return (-1);
-+  return ((p0->cupsd_timeout == p1->cupsd_timeout) ? 0 : 1);
++  return (p0->fd < p1->fd ? -1 : 1);
 +}
 +
 +
@@ -395,8 +393,7 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +
 +  cups_poll->watched_fds = cupsArrayNew ((cups_array_func_t)compare_watched_fds,
 +					 NULL);
-+  cups_poll->timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts,
-+				      NULL);
++  cups_poll->timeouts = cupsArrayNew (NULL, NULL);
 +
 +  cups_poll->api.userdata = cups_poll;
 +  cups_poll->api.watch_new = watch_new;
@@ -422,9 +419,8 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 +
 +  for (watched_fd = (cupsd_watched_fd_t*)cupsArrayFirst(cups_poll->watched_fds);
 +       watched_fd;
-+       watched_fd = (cupsd_watched_fd_t*)cupsArrayNext(cups_poll->watched_fds)){
++       watched_fd = (cupsd_watched_fd_t*)cupsArrayNext(cups_poll->watched_fds))
 +    cupsArrayClear (watched_fd->watches);
-+  }
 +
 +  cupsArrayClear (cups_poll->watched_fds);
 +  cupsArrayClear (cups_poll->timeouts);
@@ -448,21 +444,41 @@ diff -up cups-1.5.0/scheduler/avahi.c.avahi-4-poll cups-1.5.0/scheduler/avahi.c
 + * End of "$Id$".
 + */
 diff -up cups-1.5.0/scheduler/avahi.h.avahi-4-poll cups-1.5.0/scheduler/avahi.h
---- cups-1.5.0/scheduler/avahi.h.avahi-4-poll	2011-08-05 15:07:09.594032723 +0100
-+++ cups-1.5.0/scheduler/avahi.h	2011-08-05 15:07:09.595032692 +0100
-@@ -0,0 +1,49 @@
+--- cups-1.5.0/scheduler/avahi.h.avahi-4-poll	2011-10-11 10:56:50.102288037 +0100
++++ cups-1.5.0/scheduler/avahi.h	2011-10-11 10:56:50.119287724 +0100
+@@ -0,0 +1,69 @@
 +/*
 + * "$Id$"
 + *
 + *   Avahi poll implementation for the CUPS scheduler.
 + *
-+ *   Copyright (C) 2010 Red Hat, Inc.
++ *   Copyright (C) 2010, 2011 Red Hat, Inc.
 + *   Authors:
 + *    Tim Waugh <twaugh at redhat.com>
 + *
-+ *   Distribution and use rights are outlined in the file "LICENSE.txt"
-+ *   which should have been included with this file.  If this file is
-+ *   file is missing or damaged, see the license at "http://www.cups.org/".
++ *   Redistribution and use in source and binary forms, with or without
++ *   modification, are permitted provided that the following conditions
++ *   are met:
++ *
++ *   Redistributions of source code must retain the above copyright
++ *   notice, this list of conditions and the following disclaimer.
++ *
++ *   Redistributions in binary form must reproduce the above copyright
++ *   notice, this list of conditions and the following disclaimer in the
++ *   documentation and/or other materials provided with the distribution.
++ *
++ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
++ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
++ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
++ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
++ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
++ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
++ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
++ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
++ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
++ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
++ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
++ *   OF THE POSSIBILITY OF SUCH DAMAGE.
 + */
 +
 +#include <config.h>
@@ -501,8 +517,8 @@ diff -up cups-1.5.0/scheduler/avahi.h.avahi-4-poll cups-1.5.0/scheduler/avahi.h
 + * End of "$Id$".
 + */
 diff -up cups-1.5.0/scheduler/Makefile.avahi-4-poll cups-1.5.0/scheduler/Makefile
---- cups-1.5.0/scheduler/Makefile.avahi-4-poll	2011-08-05 15:06:48.548700563 +0100
-+++ cups-1.5.0/scheduler/Makefile	2011-08-05 15:07:09.570033486 +0100
+--- cups-1.5.0/scheduler/Makefile.avahi-4-poll	2011-10-11 10:56:45.868365861 +0100
++++ cups-1.5.0/scheduler/Makefile	2011-10-11 10:56:50.101288055 +0100
 @@ -17,6 +17,7 @@ include ../Makedefs
  
  CUPSDOBJS =	\
diff --git a/cups.spec b/cups.spec
index 36d4337..c57c1b8 100644
--- a/cups.spec
+++ b/cups.spec
@@ -646,7 +646,8 @@ rm -rf $RPM_BUILD_ROOT
 %{_mandir}/man1/ipptool.1.gz
 
 %changelog
-* Mon Oct 10 2011 Tim Waugh <twaugh at redhat.com> 1:1.5.0-16
+* Tue Oct 11 2011 Tim Waugh <twaugh at redhat.com> 1:1.5.0-16
+- Array handling fixes for Avahi poll implementation.
 - Increase client blocking timeout from 30s to 70s (bug #744715).
 - Set BindIPv6Only=ipv6-only in systemd socket unit file as better fix
   for bug #737230.


More information about the scm-commits mailing list