Ported avahi support from 1.4.

This commit is contained in:
Tim Waugh 2011-08-05 15:11:04 +01:00
parent 90cf1a0fdd
commit 9829b01410
8 changed files with 3299 additions and 3611 deletions

42
cups-avahi-1-config.patch Normal file
View File

@ -0,0 +1,42 @@
diff -up cups-1.5.0/config.h.in.avahi-1-config cups-1.5.0/config.h.in
--- cups-1.5.0/config.h.in.avahi-1-config 2011-06-16 21:12:16.000000000 +0100
+++ cups-1.5.0/config.h.in 2011-08-05 15:04:09.535759988 +0100
@@ -390,6 +390,13 @@
/*
+ * Do we have Avahi for DNS Service Discovery?
+ */
+
+#undef HAVE_AVAHI
+
+
+/*
* Do we have <sys/ioctl.h>?
*/
diff -up cups-1.5.0/config-scripts/cups-dnssd.m4.avahi-1-config cups-1.5.0/config-scripts/cups-dnssd.m4
--- cups-1.5.0/config-scripts/cups-dnssd.m4.avahi-1-config 2011-05-12 06:21:56.000000000 +0100
+++ cups-1.5.0/config-scripts/cups-dnssd.m4 2011-08-05 15:04:09.525760307 +0100
@@ -23,6 +23,21 @@ AC_ARG_WITH(dnssd-includes, [ --with-dn
DNSSDLIBS=""
DNSSD_BACKEND=""
+AC_ARG_ENABLE(avahi, [ --enable-avahi turn on DNS Service Discovery support, default=no],
+ [if test x$enable_avahi = xyes; then
+ AC_MSG_CHECKING(for Avahi)
+ if $PKGCONFIG --exists avahi-client; then
+ AC_MSG_RESULT(yes)
+ CFLAGS="$CFLAGS `$PKGCONFIG --cflags avahi-client`"
+ DNSSDLIBS="`$PKGCONFIG --libs avahi-client`"
+ DNSSD_BACKEND="dnssd"
+ AC_DEFINE(HAVE_AVAHI)
+ enable_dnssd=no
+ else
+ AC_MSG_RESULT(no)
+ fi
+ fi])
+
if test x$enable_dnssd != xno; then
AC_CHECK_HEADER(dns_sd.h, [
case "$uname" in

1117
cups-avahi-2-backend.patch Normal file

File diff suppressed because it is too large Load Diff

341
cups-avahi-3-timeouts.patch Normal file
View File

@ -0,0 +1,341 @@
diff -up cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts cups-1.5.0/scheduler/cupsd.h
--- cups-1.5.0/scheduler/cupsd.h.avahi-3-timeouts 2011-05-11 23:17:34.000000000 +0100
+++ cups-1.5.0/scheduler/cupsd.h 2011-08-05 15:06:13.570811440 +0100
@@ -140,6 +140,15 @@ extern const char *cups_hstrerror(int);
typedef void (*cupsd_selfunc_t)(void *data);
+#ifdef HAVE_AVAHI
+/*
+ * Timeout callback function type...
+ */
+
+typedef struct _cupsd_timeout_s cupsd_timeout_t;
+typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
+#endif /* HAVE_AVAHI */
+
/*
* Globals...
@@ -173,6 +182,11 @@ VAR int Launchd VALUE(0);
/* Running from launchd */
#endif /* HAVE_LAUNCH_H */
+#ifdef HAVE_AVAHI
+VAR cups_array_t *Timeouts; /* Timed callbacks for main loop */
+#endif /* HAVE_AVAHI */
+
+
/*
* Prototypes...
@@ -242,6 +256,20 @@ extern void cupsdStopSelect(void);
extern void cupsdStartServer(void);
extern void cupsdStopServer(void);
+#ifdef HAVE_AVAHI
+extern void cupsdInitTimeouts(void);
+extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
+ cupsd_timeoutfunc_t cb,
+ void *data);
+extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
+extern void cupsdRunTimeout (cupsd_timeout_t *timeout);
+extern void cupsdUpdateTimeout (cupsd_timeout_t *timeout,
+ const struct timeval *tv);
+extern void cupsdRemoveTimeout (cupsd_timeout_t *timeout);
+#endif /* HAVE_AVAHI */
+
+extern int cupsdRemoveFile(const char *filename);
+
/*
* End of "$Id: cupsd.h 9766 2011-05-11 22:17:34Z mike $".
diff -up cups-1.5.0/scheduler/main.c.avahi-3-timeouts cups-1.5.0/scheduler/main.c
--- cups-1.5.0/scheduler/main.c.avahi-3-timeouts 2011-08-05 15:05:45.590700888 +0100
+++ cups-1.5.0/scheduler/main.c 2011-08-05 15:06:13.572811372 +0100
@@ -146,6 +146,10 @@ main(int argc, /* I - Number of comm
int launchd_idle_exit;
/* Idle exit on select timeout? */
#endif /* HAVE_LAUNCHD */
+#ifdef HAVE_AVAHI
+ cupsd_timeout_t *tmo; /* Next scheduled timed callback */
+ long tmo_delay; /* Time before it must be called */
+#endif /* HAVE_AVAHI */
#ifdef HAVE_GETEUID
@@ -535,6 +539,14 @@ main(int argc, /* I - Number of comm
httpInitialize();
+#ifdef HAVE_AVAHI
+ /*
+ * Initialize timed callback structures.
+ */
+
+ cupsdInitTimeouts();
+#endif /* HAVE_AVAHI */
+
cupsdStartServer();
/*
@@ -874,6 +886,16 @@ main(int argc, /* I - Number of comm
}
#endif /* __APPLE__ */
+#ifdef HAVE_AVAHI
+ /*
+ * If a timed callback is due, run it.
+ */
+
+ tmo = cupsdNextTimeout (&tmo_delay);
+ if (tmo && tmo_delay == 0)
+ cupsdRunTimeout (tmo);
+#endif /* HAVE_AVAHI */
+
#ifndef __APPLE__
/*
* Update the network interfaces once a minute...
@@ -1787,6 +1809,10 @@ select_timeout(int fds) /* I - Number
cupsd_job_t *job; /* Job information */
cupsd_subscription_t *sub; /* Subscription information */
const char *why; /* Debugging aid */
+#ifdef HAVE_AVAHI
+ cupsd_timeout_t *tmo; /* Timed callback */
+ long tmo_delay; /* Seconds before calling it */
+#endif /* HAVE_AVAHI */
/*
@@ -1829,6 +1855,19 @@ select_timeout(int fds) /* I - Number
}
#endif /* __APPLE__ */
+#ifdef HAVE_AVAHI
+ /*
+ * See if there are any scheduled timed callbacks to run.
+ */
+
+ tmo = cupsdNextTimeout (&tmo_delay);
+ if (tmo)
+ {
+ timeout = tmo_delay;
+ why = "run a timed callback";
+ }
+#endif /* HAVE_AVAHI */
+
/*
* Check whether we are accepting new connections...
*/
diff -up cups-1.5.0/scheduler/Makefile.avahi-3-timeouts cups-1.5.0/scheduler/Makefile
--- cups-1.5.0/scheduler/Makefile.avahi-3-timeouts 2011-08-05 15:05:45.673698248 +0100
+++ cups-1.5.0/scheduler/Makefile 2011-08-05 15:06:13.569811476 +0100
@@ -39,7 +39,8 @@ CUPSDOBJS = \
server.o \
statbuf.o \
subscriptions.o \
- sysman.o
+ sysman.o \
+ timeout.o
LIBOBJS = \
filter.o \
mime.o \
diff -up cups-1.5.0/scheduler/timeout.c.avahi-3-timeouts cups-1.5.0/scheduler/timeout.c
--- cups-1.5.0/scheduler/timeout.c.avahi-3-timeouts 2011-08-05 15:06:13.573811341 +0100
+++ cups-1.5.0/scheduler/timeout.c 2011-08-05 15:06:13.573811341 +0100
@@ -0,0 +1,195 @@
+/*
+ * "$Id$"
+ *
+ * Timeout functions for the Common UNIX Printing System (CUPS).
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Authors:
+ * Tim Waugh <twaugh@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/".
+ *
+ * Contents:
+ *
+ * cupsdInitTimeouts() - Initialise timeout structure.
+ * cupsdAddTimeout() - Add a timed callback.
+ * cupsdNextTimeout() - Find the next enabled timed callback.
+ * cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
+ * cupsdRemoveTimeout() - Discard a timed callback.
+ * compare_timeouts() - Compare timed callbacks for array sorting.
+ */
+
+#include <config.h>
+
+#ifdef HAVE_AVAHI /* Applies to entire file... */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cupsd.h"
+
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
+# include <malloc.h>
+#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
+
+#ifdef HAVE_AVAHI
+# include <avahi-common/timeval.h>
+#endif /* HAVE_AVAHI */
+
+
+struct _cupsd_timeout_s
+{
+ struct timeval when;
+ int enabled;
+ cupsd_timeoutfunc_t callback;
+ void *data;
+};
+
+/*
+ * Local functions...
+ */
+
+/*
+ * 'compare_timeouts()' - Compare timed callbacks for array sorting.
+ */
+
+static int
+compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
+{
+ if (!p0->enabled || !p1->enabled)
+ {
+ if (!p0->enabled && !p1->enabled)
+ return (0);
+
+ return (p0->enabled ? -1 : 1);
+ }
+
+ return (avahi_timeval_compare (&p0->when, &p1->when));
+}
+
+
+/*
+ * 'cupsdInitTimeouts()' - Initialise timeout structures.
+ */
+
+void
+cupsdInitTimeouts(void)
+{
+ Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
+}
+
+
+/*
+ * 'cupsdAddTimeout()' - Add a timed callback.
+ */
+
+cupsd_timeout_t * /* O - Timeout handle */
+cupsdAddTimeout(const struct timeval *tv, /* I - Absolute time */
+ cupsd_timeoutfunc_t cb, /* I - Callback function */
+ void *data) /* I - User data */
+{
+ cupsd_timeout_t *timeout;
+
+ timeout = malloc (sizeof(cupsd_timeout_t));
+ if (timeout != NULL)
+ {
+ timeout->enabled = (tv != NULL);
+ if (tv)
+ {
+ timeout->when.tv_sec = tv->tv_sec;
+ timeout->when.tv_usec = tv->tv_usec;
+ }
+
+ timeout->callback = cb;
+ timeout->data = data;
+ cupsArrayAdd (Timeouts, timeout);
+ }
+
+ return timeout;
+}
+
+
+/*
+ * 'cupsdNextTimeout()' - Find the next enabled timed callback.
+ */
+
+cupsd_timeout_t * /* O - Next enabled timeout or NULL */
+cupsdNextTimeout(long *delay) /* O - Seconds before scheduled */
+{
+ cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
+ struct timeval curtime;
+
+ if (first && !first->enabled)
+ first = NULL;
+
+ if (first && delay)
+ {
+ gettimeofday (&curtime, NULL);
+ if (avahi_timeval_compare (&curtime, &first->when) > 0)
+ {
+ *delay = 0;
+ } else {
+ *delay = 1 + first->when.tv_sec - curtime.tv_sec;
+ if (first->when.tv_usec < curtime.tv_usec)
+ (*delay)--;
+ }
+ }
+
+ return (first);
+}
+
+
+/*
+ * 'cupsdRunTimeout()' - Run a timed callback.
+ */
+
+void
+cupsdRunTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
+{
+ if (!timeout)
+ return;
+ timeout->enabled = 0;
+ if (!timeout->callback)
+ return;
+ timeout->callback (timeout, timeout->data);
+}
+
+/*
+ * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
+ */
+
+void
+cupsdUpdateTimeout(cupsd_timeout_t *timeout, /* I - Timeout */
+ const struct timeval *tv) /* I - Absolute time or NULL */
+{
+ cupsArrayRemove (Timeouts, timeout);
+ timeout->enabled = (tv != NULL);
+ if (tv)
+ {
+ timeout->when.tv_sec = tv->tv_sec;
+ timeout->when.tv_usec = tv->tv_usec;
+ }
+ cupsArrayAdd (Timeouts, timeout);
+}
+
+
+/*
+ * 'cupsdRemoveTimeout()' - Discard a timed callback.
+ */
+
+void
+cupsdRemoveTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
+{
+ cupsArrayRemove (Timeouts, timeout);
+ free (timeout);
+}
+
+
+#endif /* HAVE_AVAHI ... from top of file */
+
+/*
+ * End of "$Id$".
+ */

513
cups-avahi-4-poll.patch Normal file
View File

@ -0,0 +1,513 @@
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 @@
+/*
+ * "$Id$"
+ *
+ * Avahi poll implementation for the CUPS scheduler.
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Authors:
+ * Tim Waugh <twaugh@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/".
+ *
+ * Contents:
+ *
+ * watch_read_cb - Read callback for file descriptor
+ * watch_write_cb - Write callback for file descriptor
+ * watched_fd_add_select() - Call cupsdAddSelect() as needed
+ * watch_new() - Create a new file descriptor watch
+ * watch_free() - Free a file descriptor watch
+ * watch_update() - Update watched events for a file descriptor
+ * watch_get_events() - Get events that happened for a file descriptor
+ * timeout_cb() - Run a timed Avahi callback
+ * timeout_new() - Set a wakeup time
+ * 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
+ */
+
+#include <config.h>
+
+#ifdef HAVE_AVAHI /* Applies to entire file... */
+
+/*
+ * Include necessary headers...
+ */
+
+#include "cupsd.h"
+
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
+# include <malloc.h>
+#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
+
+#ifdef HAVE_AVAHI
+# include <avahi-common/timeval.h>
+#endif /* HAVE_AVAHI */
+
+
+typedef struct
+{
+ AvahiCupsPoll *cups_poll;
+
+ int fd;
+ AvahiWatchEvent occurred;
+ cups_array_t *watches;
+} cupsd_watched_fd_t;
+
+struct AvahiWatch
+{
+ cupsd_watched_fd_t *watched_fd;
+
+ AvahiWatchEvent events;
+ AvahiWatchCallback callback;
+ void *userdata;
+};
+
+struct AvahiTimeout
+{
+ AvahiCupsPoll *cups_poll;
+ AvahiTimeoutCallback callback;
+ void *userdata;
+ cupsd_timeout_t *cupsd_timeout;
+};
+
+/*
+ * Local functions...
+ */
+
+static AvahiWatch * watch_new(const AvahiPoll *api,
+ int fd,
+ AvahiWatchEvent events,
+ AvahiWatchCallback callback,
+ void *userdata);
+static void watch_free(AvahiWatch *watch);
+static void watch_update(AvahiWatch *watch,
+ AvahiWatchEvent events);
+static AvahiWatchEvent watch_get_events(AvahiWatch *watch);
+static int compare_watches(AvahiWatch *p0,
+ AvahiWatch *p1);
+
+
+/*
+ * 'watch_read_cb' - Read callback for file descriptor
+ */
+
+static void
+watch_read_cb (void *userdata)
+{
+ AvahiWatch *watch;
+ cupsd_watched_fd_t *watched_fd = userdata;
+ 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->callback) (watch, watched_fd->fd,
+ AVAHI_WATCH_IN, watch->userdata);
+ watched_fd->occurred &= ~AVAHI_WATCH_IN;
+ break;
+ }
+ }
+}
+
+
+/*
+ * 'watch_write_cb' - Write callback for file descriptor
+ */
+
+static void
+watch_write_cb (void *userdata)
+{
+ AvahiWatch *watch;
+ cupsd_watched_fd_t *watched_fd = userdata;
+ 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->callback) (watch, watched_fd->fd,
+ AVAHI_WATCH_OUT, watch->userdata);
+ watched_fd->occurred &= ~AVAHI_WATCH_OUT;
+ break;
+ }
+ }
+}
+
+
+/*
+ * 'watched_fd_add_select' - Call cupsdAddSelect() as needed
+ */
+
+static int /* O - Watches? */
+watched_fd_add_select (cupsd_watched_fd_t *watched_fd)
+{
+ AvahiWatch *watch;
+ cupsd_selfunc_t read_cb = NULL, write_cb = NULL;
+
+ for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
+ watch;
+ watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches)) {
+ if (watch->events & (AVAHI_WATCH_IN |
+ AVAHI_WATCH_ERR |
+ AVAHI_WATCH_HUP)) {
+ read_cb = (cupsd_selfunc_t)watch_read_cb;
+ if (write_cb != NULL)
+ break;
+ }
+
+ if (watch->events & AVAHI_WATCH_OUT) {
+ write_cb = (cupsd_selfunc_t)watch_write_cb;
+ if (read_cb != NULL)
+ break;
+ }
+ }
+
+ if (read_cb || write_cb)
+ cupsdAddSelect (watched_fd->fd, read_cb, write_cb, watched_fd);
+ else
+ cupsdRemoveSelect (watched_fd->fd);
+
+ return (read_cb || write_cb);
+}
+
+/*
+ * 'watch_new' - Create a new file descriptor watch
+ */
+
+static AvahiWatch *
+watch_new (const AvahiPoll *api,
+ int fd,
+ AvahiWatchEvent events,
+ AvahiWatchCallback callback,
+ void *userdata)
+{
+ cupsd_watched_fd_t key, *watched_fd;
+ AvahiCupsPoll *cups_poll = api->userdata;
+ AvahiWatch *watch = malloc(sizeof(AvahiWatch));
+ if (watch == NULL)
+ return (NULL);
+
+ watch->events = events;
+ watch->callback = callback;
+ watch->userdata = userdata;
+
+ key.fd = fd;
+ watched_fd = cupsArrayFind (cups_poll->watched_fds, &key);
+ if (watched_fd == NULL) {
+ watched_fd = malloc(sizeof(cupsd_watched_fd_t));
+ if (watched_fd == NULL) {
+ free (watch);
+ return (NULL);
+ }
+
+ 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);
+ }
+
+ watch->watched_fd = watched_fd;
+ cupsArrayAdd(watched_fd->watches, watch);
+ watched_fd_add_select (watched_fd);
+ return (watch);
+}
+
+
+/*
+ * 'watch_free' - Free a file descriptor watch
+ */
+
+static void
+watch_free (AvahiWatch *watch)
+{
+ cupsd_watched_fd_t *watched_fd = watch->watched_fd;
+ AvahiCupsPoll *cups_poll = watched_fd->cups_poll;
+
+ cupsArrayRemove (watched_fd->watches, watch);
+ free (watch);
+
+ if (!watched_fd_add_select (watched_fd)) {
+ /* No more watches */
+ cupsArrayRemove (cups_poll->watched_fds, watched_fd);
+ free (watched_fd);
+ }
+}
+
+
+/*
+ * 'watch_update' - Update watched events for a file descriptor
+ */
+
+static void
+watch_update (AvahiWatch *watch,
+ AvahiWatchEvent events)
+{
+ watch->events = events;
+ watched_fd_add_select (watch->watched_fd);
+}
+
+
+/*
+ * 'watch_get_events' - Get events that happened for a file descriptor
+ */
+
+static AvahiWatchEvent
+watch_get_events (AvahiWatch *watch)
+{
+ return (watch->watched_fd->occurred);
+}
+
+
+/*
+ * '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
+ */
+
+static void
+timeout_cb (cupsd_timeout_t *cupsd_timeout, void *userdata)
+{
+ AvahiTimeout *timeout = userdata;
+ (timeout->callback) (timeout, timeout->userdata);
+}
+
+
+/*
+ * 'timeout_new' - Set a wakeup time
+ */
+
+static AvahiTimeout *
+timeout_new (const AvahiPoll *api,
+ const struct timeval *tv,
+ AvahiTimeoutCallback callback,
+ void *userdata)
+{
+ AvahiTimeout *timeout;
+ AvahiCupsPoll *cups_poll = api->userdata;
+
+ timeout = malloc(sizeof(AvahiTimeout));
+ if (timeout == NULL)
+ return (NULL);
+
+ timeout->cups_poll = cups_poll;
+ timeout->callback = callback;
+ timeout->userdata = userdata;
+ timeout->cupsd_timeout = cupsdAddTimeout (tv,
+ (cupsd_timeoutfunc_t)timeout_cb,
+ timeout);
+ cupsArrayAdd (cups_poll->timeouts, timeout);
+ return (timeout);
+}
+
+
+/*
+ * 'timeout_update' - Update the expiration time for a timeout
+ */
+
+static void
+timeout_update (AvahiTimeout *timeout,
+ const struct timeval *tv)
+{
+ cupsdUpdateTimeout (timeout->cupsd_timeout, tv);
+}
+
+
+/*
+ * ' timeout_free' - Free a timeout
+ */
+
+static void
+timeout_free (AvahiTimeout *timeout)
+{
+ cupsArrayRemove (timeout->cups_poll->timeouts, timeout);
+ cupsdRemoveTimeout (timeout->cupsd_timeout);
+ free (timeout);
+}
+
+
+/*
+ * 'compare_watched_fds' - Compare watched file descriptors for array sorting
+ */
+static int
+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);
+
+ if (p0 == p1)
+ 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);
+}
+
+
+/*
+ * 'avahi_cups_poll_new' - Create a new Avahi main loop object for CUPS
+ */
+
+AvahiCupsPoll *
+avahi_cups_poll_new (void)
+{
+ AvahiCupsPoll *cups_poll = malloc(sizeof(AvahiCupsPoll));
+ if (cups_poll == NULL)
+ return (NULL);
+
+ 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->api.userdata = cups_poll;
+ cups_poll->api.watch_new = watch_new;
+ cups_poll->api.watch_free = watch_free;
+ cups_poll->api.watch_update = watch_update;
+ cups_poll->api.watch_get_events = watch_get_events;
+
+ cups_poll->api.timeout_new = timeout_new;
+ cups_poll->api.timeout_update = timeout_update;
+ cups_poll->api.timeout_free = timeout_free;
+
+ return (cups_poll);
+}
+
+
+/*
+ * 'avahi_cups_poll_free' - Free an Avahi main loop object for CUPS
+ */
+void
+avahi_cups_poll_free (AvahiCupsPoll *cups_poll)
+{
+ cupsd_watched_fd_t *watched_fd;
+
+ 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)){
+ cupsArrayClear (watched_fd->watches);
+ }
+
+ cupsArrayClear (cups_poll->watched_fds);
+ cupsArrayClear (cups_poll->timeouts);
+}
+
+
+/*
+ * 'avahi_cups_poll_get' - Get the abstract poll API structure
+ */
+
+const AvahiPoll *
+avahi_cups_poll_get (AvahiCupsPoll *cups_poll)
+{
+ return (&cups_poll->api);
+}
+
+
+#endif /* HAVE_AVAHI ... from top of file */
+
+/*
+ * 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 @@
+/*
+ * "$Id$"
+ *
+ * Avahi poll implementation for the CUPS scheduler.
+ *
+ * Copyright (C) 2010 Red Hat, Inc.
+ * Authors:
+ * Tim Waugh <twaugh@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/".
+ */
+
+#include <config.h>
+
+#ifdef HAVE_AVAHI
+# include <avahi-client/client.h>
+# include <avahi-client/publish.h>
+#endif /* HAVE_AVAHI */
+
+#ifdef HAVE_AUTHORIZATION_H
+# include <Security/Authorization.h>
+#endif /* HAVE_AUTHORIZATION_H */
+
+
+#ifdef HAVE_AVAHI
+typedef struct
+{
+ AvahiPoll api;
+ cups_array_t *watched_fds;
+ cups_array_t *timeouts;
+} AvahiCupsPoll;
+#endif /* HAVE_AVAHI */
+
+/*
+ * Prototypes...
+ */
+
+#ifdef HAVE_AVAHI
+extern AvahiCupsPoll * avahi_cups_poll_new(void);
+extern void avahi_cups_poll_free(AvahiCupsPoll *cups_poll);
+extern const AvahiPoll *avahi_cups_poll_get(AvahiCupsPoll *cups_poll);
+#endif /* HAVE_AVAHI */
+
+
+/*
+ * 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
@@ -17,6 +17,7 @@ include ../Makedefs
CUPSDOBJS = \
auth.o \
+ avahi.o \
banners.o \
cert.o \
classes.o \

1162
cups-avahi-5-services.patch Normal file

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,65 +1,6 @@
From 1db0a48375836c7e93ac30649007c2391be8b3b2 Mon Sep 17 00:00:00 2001
From: Lennart Poettering <lennart@poettering.net>
Date: Mon, 4 Jul 2011 01:37:01 +0200
Subject: [PATCH] systemd: add systemd socket activation and unit files
On newer Linux machines systemd supports launchd-style socket
activation. This patch adds support for this mechanism and also adds
systemd unit files as appropriate to hook this up with systemd.
This includes an MIT-licensed drop-in file that implements the most
basic interfaces needed to get the file descriptors from systemd. Most
of the systemd and Linux-specific code compiles to NOPs on other
systems.
Three triggers to start CUPS are defined: a) if new printer hardware is
plugged in, b) when a client accesses the CUPS socket and c) when a
spool file resides in /var/spool/cups.
---
Makedefs.in | 2 +
config-scripts/cups-systemd.m4 | 25 ++
configure.in | 4 +
data/Makefile | 9 +
data/cups.path.in | 8 +
data/cups.service.in | 9 +
data/cups.socket.in | 9 +
scheduler/Makefile | 9 +
scheduler/main.c | 107 ++++++++
scheduler/sd-daemon.c | 520 ++++++++++++++++++++++++++++++++++++++++
scheduler/sd-daemon.h | 277 +++++++++++++++++++++
11 files changed, 979 insertions(+), 0 deletions(-)
create mode 100644 config-scripts/cups-systemd.m4
create mode 100644 data/cups.path.in
create mode 100644 data/cups.service.in
create mode 100644 data/cups.socket.in
create mode 100644 scheduler/sd-daemon.c
create mode 100644 scheduler/sd-daemon.h
diff --git a/Makedefs.in b/Makedefs.in
index 654eea4..02c43b6 100644
--- a/Makedefs.in
+++ b/Makedefs.in
@@ -143,6 +143,7 @@ CXXFLAGS = @CPPFLAGS@ @CXXFLAGS@
CXXLIBS = @CXXLIBS@
DBUS_NOTIFIER = @DBUS_NOTIFIER@
DBUS_NOTIFIERLIBS = @DBUS_NOTIFIERLIBS@
+SYSTEMD_UNITS = @SYSTEMD_UNITS@
DNSSD_BACKEND = @DNSSD_BACKEND@
DSOFLAGS = -L../cups @DSOFLAGS@
DSOLIBS = @DSOLIBS@ $(COMMONLIBS)
@@ -267,6 +268,7 @@ PAMFILE = @PAMFILE@
DEFAULT_LAUNCHD_CONF = @DEFAULT_LAUNCHD_CONF@
DBUSDIR = @DBUSDIR@
+SYSTEMDUNITDIR = $(BUILDROOT)@systemdsystemunitdir@
#
diff --git a/config-scripts/cups-systemd.m4 b/config-scripts/cups-systemd.m4
new file mode 100644
index 0000000..fead8a9
--- /dev/null
+++ b/config-scripts/cups-systemd.m4
diff -up cups-1.5.0/config-scripts/cups-systemd.m4.systemd-socket cups-1.5.0/config-scripts/cups-systemd.m4
--- cups-1.5.0/config-scripts/cups-systemd.m4.systemd-socket 2011-08-05 15:09:00.789855786 +0100
+++ cups-1.5.0/config-scripts/cups-systemd.m4 2011-08-05 15:09:00.789855786 +0100
@@ -0,0 +1,25 @@
+dnl
+dnl "$Id$"
@ -86,10 +27,9 @@ index 0000000..fead8a9
+dnl
+dnl "$Id$"
+dnl
diff --git a/configure.in b/configure.in
index 560f4f8..b0c19a9 100644
--- a/configure.in
+++ b/configure.in
diff -up cups-1.5.0/configure.in.systemd-socket cups-1.5.0/configure.in
--- cups-1.5.0/configure.in.systemd-socket 2010-11-20 01:03:46.000000000 +0000
+++ cups-1.5.0/configure.in 2011-08-05 15:09:00.789855786 +0100
@@ -37,6 +37,7 @@ sinclude(config-scripts/cups-pam.m4)
sinclude(config-scripts/cups-largefile.m4)
sinclude(config-scripts/cups-dnssd.m4)
@ -108,10 +48,47 @@ index 560f4f8..b0c19a9 100644
desktop/cups.desktop
doc/help/ref-cupsd-conf.html
doc/help/standard.html
diff --git a/data/Makefile b/data/Makefile
index b9de21a..cccab85 100644
--- a/data/Makefile
+++ b/data/Makefile
diff -up cups-1.5.0/data/cups.path.in.systemd-socket cups-1.5.0/data/cups.path.in
--- cups-1.5.0/data/cups.path.in.systemd-socket 2011-08-05 15:09:00.790855758 +0100
+++ cups-1.5.0/data/cups.path.in 2011-08-05 15:09:00.790855758 +0100
@@ -0,0 +1,8 @@
+[Unit]
+Description=CUPS Printer Service Spool
+
+[Path]
+DirectoryNotEmpty=@CUPS_REQUESTS@
+
+[Install]
+WantedBy=multi-user.target
diff -up cups-1.5.0/data/cups.service.in.systemd-socket cups-1.5.0/data/cups.service.in
--- cups-1.5.0/data/cups.service.in.systemd-socket 2011-08-05 15:09:00.791855730 +0100
+++ cups-1.5.0/data/cups.service.in 2011-08-05 15:09:00.791855730 +0100
@@ -0,0 +1,9 @@
+[Unit]
+Description=CUPS Printing Service
+
+[Service]
+ExecStart=@sbindir@/cupsd -f
+
+[Install]
+Also=cups.socket cups.path
+WantedBy=printer.target
diff -up cups-1.5.0/data/cups.socket.in.systemd-socket cups-1.5.0/data/cups.socket.in
--- cups-1.5.0/data/cups.socket.in.systemd-socket 2011-08-05 15:09:00.791855730 +0100
+++ cups-1.5.0/data/cups.socket.in 2011-08-05 15:09:00.791855730 +0100
@@ -0,0 +1,9 @@
+[Unit]
+Description=CUPS Printing Service Sockets
+
+[Socket]
+ListenStream=@CUPS_DEFAULT_DOMAINSOCKET@
+ListenStream=631
+
+[Install]
+WantedBy=sockets.target
diff -up cups-1.5.0/data/Makefile.systemd-socket cups-1.5.0/data/Makefile
--- cups-1.5.0/data/Makefile.systemd-socket 2011-05-12 06:21:56.000000000 +0100
+++ cups-1.5.0/data/Makefile 2011-08-05 15:09:00.790855758 +0100
@@ -112,6 +112,12 @@ install-data:
$(INSTALL_DATA) $$file $(DATADIR)/ppdc; \
done
@ -135,81 +112,28 @@ index b9de21a..cccab85 100644
#
diff --git a/data/cups.path.in b/data/cups.path.in
new file mode 100644
index 0000000..c99e39b
--- /dev/null
+++ b/data/cups.path.in
@@ -0,0 +1,8 @@
+[Unit]
+Description=CUPS Printer Service Spool
+
+[Path]
+DirectoryNotEmpty=@CUPS_REQUESTS@
+
+[Install]
+WantedBy=multi-user.target
diff --git a/data/cups.service.in b/data/cups.service.in
new file mode 100644
index 0000000..007d0e6
--- /dev/null
+++ b/data/cups.service.in
@@ -0,0 +1,9 @@
+[Unit]
+Description=CUPS Printing Service
+
+[Service]
+ExecStart=@sbindir@/cupsd -f
+
+[Install]
+Also=cups.socket cups.path
+WantedBy=printer.target
diff --git a/data/cups.socket.in b/data/cups.socket.in
new file mode 100644
index 0000000..b940096
--- /dev/null
+++ b/data/cups.socket.in
@@ -0,0 +1,9 @@
+[Unit]
+Description=CUPS Printing Service Sockets
+
+[Socket]
+ListenStream=@CUPS_DEFAULT_DOMAINSOCKET@
+ListenStream=631
+
+[Install]
+WantedBy=sockets.target
diff --git a/scheduler/Makefile b/scheduler/Makefile
index 3c7da8e..05152a6 100644
--- a/scheduler/Makefile
+++ b/scheduler/Makefile
@@ -39,6 +39,7 @@ CUPSDOBJS = \
server.o \
statbuf.o \
subscriptions.o \
+ sd-daemon.o \
sysman.o
LIBOBJS = \
filter.o \
@@ -568,6 +569,14 @@ sloc:
diff -up cups-1.5.0/Makedefs.in.systemd-socket cups-1.5.0/Makedefs.in
--- cups-1.5.0/Makedefs.in.systemd-socket 2011-08-05 15:08:39.672435367 +0100
+++ cups-1.5.0/Makedefs.in 2011-08-05 15:09:00.788855814 +0100
@@ -143,6 +143,7 @@ CXXFLAGS = @CPPFLAGS@ @CXXFLAGS@
CXXLIBS = @CXXLIBS@
DBUS_NOTIFIER = @DBUS_NOTIFIER@
DBUS_NOTIFIERLIBS = @DBUS_NOTIFIERLIBS@
+SYSTEMD_UNITS = @SYSTEMD_UNITS@
DNSSD_BACKEND = @DNSSD_BACKEND@
DSOFLAGS = -L../cups @DSOFLAGS@
DSOLIBS = @DSOLIBS@ $(COMMONLIBS)
@@ -267,6 +268,7 @@ PAMFILE = @PAMFILE@
DEFAULT_LAUNCHD_CONF = @DEFAULT_LAUNCHD_CONF@
DBUSDIR = @DBUSDIR@
+SYSTEMDUNITDIR = $(BUILDROOT)@systemdsystemunitdir@
#
+# Update sd-daemon.[ch] drop-in file from upstream git
+#
+
+update-systemd:
+ curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c > sd-daemon.c
+ curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h > sd-daemon.h
+
+#
# Dependencies...
#
diff --git a/scheduler/main.c b/scheduler/main.c
index baaa3a1..5a4b8e1 100644
--- a/scheduler/main.c
+++ b/scheduler/main.c
diff -up cups-1.5.0/scheduler/main.c.systemd-socket cups-1.5.0/scheduler/main.c
--- cups-1.5.0/scheduler/main.c.systemd-socket 2011-08-05 15:08:39.755433088 +0100
+++ cups-1.5.0/scheduler/main.c 2011-08-05 15:09:00.795855621 +0100
@@ -26,6 +26,8 @@
* launchd_checkin() - Check-in with launchd and collect the listening
* fds.
@ -236,7 +160,7 @@ index baaa3a1..5a4b8e1 100644
static void parent_handler(int sig);
static void process_children(void);
static void sigchld_handler(int sig);
@@ -520,6 +525,11 @@ main(int argc, /* I - Number of command-line args */
@@ -538,6 +543,11 @@ main(int argc, /* I - Number of comm
#endif /* HAVE_LAUNCHD */
/*
@ -248,7 +172,7 @@ index baaa3a1..5a4b8e1 100644
* Startup the server...
*/
@@ -731,6 +741,12 @@ main(int argc, /* I - Number of command-line args */
@@ -760,6 +770,12 @@ main(int argc, /* I - Number of comm
#endif /* HAVE_LAUNCHD */
/*
@ -261,7 +185,7 @@ index baaa3a1..5a4b8e1 100644
* Startup the server...
*/
@@ -1535,6 +1551,97 @@ launchd_checkout(void)
@@ -1584,6 +1600,97 @@ launchd_checkout(void)
}
#endif /* HAVE_LAUNCHD */
@ -359,11 +283,35 @@ index baaa3a1..5a4b8e1 100644
/*
* 'parent_handler()' - Catch USR1/CHLD signals...
diff --git a/scheduler/sd-daemon.c b/scheduler/sd-daemon.c
new file mode 100644
index 0000000..a2ec74c
--- /dev/null
+++ b/scheduler/sd-daemon.c
diff -up cups-1.5.0/scheduler/Makefile.systemd-socket cups-1.5.0/scheduler/Makefile
--- cups-1.5.0/scheduler/Makefile.systemd-socket 2011-08-05 15:08:39.765432815 +0100
+++ cups-1.5.0/scheduler/Makefile 2011-08-05 15:09:22.170268932 +0100
@@ -41,6 +41,7 @@ CUPSDOBJS = \
server.o \
statbuf.o \
subscriptions.o \
+ sd-daemon.o \
sysman.o \
timeout.o
LIBOBJS = \
@@ -571,6 +572,14 @@ sloc:
#
+# Update sd-daemon.[ch] drop-in file from upstream git
+#
+
+update-systemd:
+ curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.c > sd-daemon.c
+ curl http://cgit.freedesktop.org/systemd/plain/src/sd-daemon.h > sd-daemon.h
+
+#
# Dependencies...
#
diff -up cups-1.5.0/scheduler/sd-daemon.c.systemd-socket cups-1.5.0/scheduler/sd-daemon.c
--- cups-1.5.0/scheduler/sd-daemon.c.systemd-socket 2011-08-05 15:09:00.796855594 +0100
+++ cups-1.5.0/scheduler/sd-daemon.c 2011-08-05 15:09:00.796855594 +0100
@@ -0,0 +1,520 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
@ -885,11 +833,9 @@ index 0000000..a2ec74c
+ return a.st_dev != b.st_dev;
+#endif
+}
diff --git a/scheduler/sd-daemon.h b/scheduler/sd-daemon.h
new file mode 100644
index 0000000..46dc7fd
--- /dev/null
+++ b/scheduler/sd-daemon.h
diff -up cups-1.5.0/scheduler/sd-daemon.h.systemd-socket cups-1.5.0/scheduler/sd-daemon.h
--- cups-1.5.0/scheduler/sd-daemon.h.systemd-socket 2011-08-05 15:09:00.797855566 +0100
+++ cups-1.5.0/scheduler/sd-daemon.h 2011-08-05 15:09:00.797855566 +0100
@@ -0,0 +1,277 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
@ -1168,6 +1114,3 @@ index 0000000..46dc7fd
+#endif
+
+#endif
--
1.7.6

View File

@ -13,7 +13,7 @@
Summary: Common Unix Printing System
Name: cups
Version: 1.5.0
Release: 1%{?dist}
Release: 2%{?dist}
License: GPLv2
Group: System Environment/Daemons
Source: http://ftp.easysw.com/pub/cups/%{version}/cups-%{version}-source.tar.bz2
@ -62,9 +62,14 @@ Patch27: cups-hp-deviceid-oid.patch
Patch28: cups-dnssd-deviceid.patch
Patch29: cups-ricoh-deviceid-oid.patch
Patch31: cups-avahi.patch
Patch32: cups-icc.patch
Patch33: cups-systemd-socket.patch
Patch30: cups-avahi-1-config.patch
Patch31: cups-avahi-2-backend.patch
Patch32: cups-avahi-3-timeouts.patch
Patch33: cups-avahi-4-poll.patch
Patch34: cups-avahi-5-services.patch
Patch35: cups-icc.patch
Patch36: cups-systemd-socket.patch
Patch100: cups-lspp.patch
@ -268,14 +273,21 @@ Sends IPP requests to the specified URI and tests and/or displays the results.
# Add an SNMP query for Ricoh's device ID OID (STR #3552).
%patch29 -p1 -b .ricoh-deviceid-oid
# Avahi support in the dnssd backend.
#%patch31 -p1 -b .avahi
# Avahi support:
# - discovery in the dnssd backend
# - service announcement in the scheduler
%patch30 -p1 -b .avahi-1-config
%patch31 -p1 -b .avahi-2-backend
%patch32 -p1 -b .avahi-3-timeouts
%patch33 -p1 -b .avahi-4-poll
%patch34 -p1 -b .avahi-5-services
# ICC colord support.
%patch32 -p1 -b .icc
%patch35 -p1 -b .icc
# Add support for systemd socket activation (patch from Lennart
# Poettering).
%patch33 -p1 -b .systemd-socket
%patch36 -p1 -b .systemd-socket
%if %lspp
# LSPP support.
@ -623,6 +635,9 @@ rm -rf $RPM_BUILD_ROOT
%{_mandir}/man1/ipptool.1.gz
%changelog
* Fri Aug 5 2011 Tim Waugh <twaugh@redhat.com> 1:1.5.0-2
- Ported avahi support from 1.4.
* Tue Jul 26 2011 Jiri Popelka <jpopelka@redhat.com> 1:1.5.0-1
- 1.5.0