1 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/Makefile cups-2.3.3/scheduler/Makefile
2 --- cups-2.3.3.org/scheduler/Makefile 2020-04-27 20:04:29.000000000 +0200
3 +++ cups-2.3.3/scheduler/Makefile 2021-04-20 22:45:53.873155054 +0200
4 @@ -12,6 +12,7 @@ include ../Makedefs
12 @@ -35,7 +36,8 @@ CUPSDOBJS = \
22 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/avahi.c cups-2.3.3/scheduler/avahi.c
23 --- cups-2.3.3.org/scheduler/avahi.c 1970-01-01 01:00:00.000000000 +0100
24 +++ cups-2.3.3/scheduler/avahi.c 2021-04-20 22:45:53.873155054 +0200
29 + * Avahi poll implementation for the CUPS scheduler.
31 + * Copyright (C) 2010, 2011 Red Hat, Inc.
33 + * Tim Waugh <twaugh@redhat.com>
35 + * Redistribution and use in source and binary forms, with or without
36 + * modification, are permitted provided that the following conditions
39 + * Redistributions of source code must retain the above copyright
40 + * notice, this list of conditions and the following disclaimer.
42 + * Redistributions in binary form must reproduce the above copyright
43 + * notice, this list of conditions and the following disclaimer in the
44 + * documentation and/or other materials provided with the distribution.
46 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
47 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
48 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
49 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
50 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
51 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
52 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
53 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
55 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
56 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
57 + * OF THE POSSIBILITY OF SUCH DAMAGE.
61 + * watch_read_cb - Read callback for file descriptor
62 + * watch_write_cb - Write callback for file descriptor
63 + * watched_fd_add_select() - Call cupsdAddSelect() as needed
64 + * watch_new() - Create a new file descriptor watch
65 + * watch_free() - Free a file descriptor watch
66 + * watch_update() - Update watched events for a file descriptor
67 + * watch_get_events() - Get events that happened for a file descriptor
68 + * timeout_cb() - Run a timed Avahi callback
69 + * timeout_new() - Set a wakeup time
70 + * timeout_update() - Update the expiration time for a timeout
71 + * timeout_free() - Free a timeout
72 + * compare_watched_fds() - Compare watched file descriptors for array sorting
73 + * avahi_cups_poll_new() - Create a new Avahi main loop object for CUPS
74 + * avahi_cups_poll_free() - Free an Avahi main loop object for CUPS
75 + * avahi_cups_poll_get() - Get the abstract poll API structure
80 +#ifdef HAVE_AVAHI /* Applies to entire file... */
83 + * Include necessary headers...
88 +#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
90 +#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
93 +# include <avahi-common/timeval.h>
94 +#endif /* HAVE_AVAHI */
99 + AvahiCupsPoll *cups_poll;
102 + AvahiWatchEvent occurred;
103 + cups_array_t *watches;
104 +} cupsd_watched_fd_t;
108 + cupsd_watched_fd_t *watched_fd;
110 + AvahiWatchEvent events;
111 + AvahiWatchCallback callback;
117 + AvahiCupsPoll *cups_poll;
118 + AvahiTimeoutCallback callback;
120 + cupsd_timeout_t *cupsd_timeout;
124 + * Local functions...
127 +static AvahiWatch * watch_new(const AvahiPoll *api,
129 + AvahiWatchEvent events,
130 + AvahiWatchCallback callback,
132 +static void watch_free(AvahiWatch *watch);
133 +static void watch_update(AvahiWatch *watch,
134 + AvahiWatchEvent events);
135 +static AvahiWatchEvent watch_get_events(AvahiWatch *watch);
139 + * 'watch_read_cb' - Read callback for file descriptor
143 +watch_read_cb (void *userdata)
146 + cupsd_watched_fd_t *watched_fd = userdata;
147 + watched_fd->occurred |= AVAHI_WATCH_IN;
148 + for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
150 + watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
152 + if (watch->events & watched_fd->occurred)
154 + (watch->callback) (watch, watched_fd->fd,
155 + AVAHI_WATCH_IN, watch->userdata);
156 + watched_fd->occurred &= ~AVAHI_WATCH_IN;
164 + * 'watch_write_cb' - Write callback for file descriptor
168 +watch_write_cb (void *userdata)
171 + cupsd_watched_fd_t *watched_fd = userdata;
172 + watched_fd->occurred |= AVAHI_WATCH_OUT;
173 + for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
175 + watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
177 + if (watch->events & watched_fd->occurred)
179 + (watch->callback) (watch, watched_fd->fd,
180 + AVAHI_WATCH_OUT, watch->userdata);
181 + watched_fd->occurred &= ~AVAHI_WATCH_OUT;
189 + * 'watched_fd_add_select' - Call cupsdAddSelect() as needed
192 +static int /* O - Watches? */
193 +watched_fd_add_select (cupsd_watched_fd_t *watched_fd)
196 + cupsd_selfunc_t read_cb = NULL, write_cb = NULL;
197 + int any_watches = 0;
199 + for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
201 + watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
204 + if (watch->events & (AVAHI_WATCH_IN |
208 + read_cb = (cupsd_selfunc_t)watch_read_cb;
209 + if (write_cb != NULL)
213 + if (watch->events & AVAHI_WATCH_OUT)
215 + write_cb = (cupsd_selfunc_t)watch_write_cb;
216 + if (read_cb != NULL)
221 + if (read_cb || write_cb)
222 + cupsdAddSelect (watched_fd->fd, read_cb, write_cb, watched_fd);
224 + cupsdRemoveSelect (watched_fd->fd);
226 + return (any_watches);
230 + * 'watch_new' - Create a new file descriptor watch
234 +watch_new (const AvahiPoll *api,
236 + AvahiWatchEvent events,
237 + AvahiWatchCallback callback,
240 + cupsd_watched_fd_t key, *watched_fd;
241 + AvahiCupsPoll *cups_poll = api->userdata;
242 + AvahiWatch *watch = malloc(sizeof(AvahiWatch));
246 + watch->events = events;
247 + watch->callback = callback;
248 + watch->userdata = userdata;
251 + watched_fd = cupsArrayFind (cups_poll->watched_fds, &key);
252 + if (watched_fd == NULL)
254 + watched_fd = malloc(sizeof(cupsd_watched_fd_t));
255 + if (watched_fd == NULL)
261 + watched_fd->fd = fd;
262 + watched_fd->occurred = 0;
263 + watched_fd->cups_poll = cups_poll;
264 + watched_fd->watches = cupsArrayNew (NULL, NULL);
265 + cupsArrayAdd (cups_poll->watched_fds, watched_fd);
268 + watch->watched_fd = watched_fd;
269 + cupsArrayAdd(watched_fd->watches, watch);
270 + watched_fd_add_select (watched_fd);
276 + * 'watch_free' - Free a file descriptor watch
280 +watch_free (AvahiWatch *watch)
282 + cupsd_watched_fd_t *watched_fd = watch->watched_fd;
283 + AvahiCupsPoll *cups_poll = watched_fd->cups_poll;
285 + cupsArrayRemove (watched_fd->watches, watch);
288 + if (!watched_fd_add_select (watched_fd))
290 + /* No more watches */
291 + cupsArrayRemove (cups_poll->watched_fds, watched_fd);
298 + * 'watch_update' - Update watched events for a file descriptor
302 +watch_update (AvahiWatch *watch,
303 + AvahiWatchEvent events)
305 + watch->events = events;
306 + watched_fd_add_select (watch->watched_fd);
311 + * 'watch_get_events' - Get events that happened for a file descriptor
314 +static AvahiWatchEvent
315 +watch_get_events (AvahiWatch *watch)
317 + return (watch->watched_fd->occurred);
322 + * 'timeout_cb()' - Run a timed Avahi callback
326 +timeout_cb (cupsd_timeout_t *cupsd_timeout, void *userdata)
328 + AvahiTimeout *timeout = userdata;
329 + (timeout->callback) (timeout, timeout->userdata);
334 + * 'timeout_new' - Set a wakeup time
337 +static AvahiTimeout *
338 +timeout_new (const AvahiPoll *api,
339 + const struct timeval *tv,
340 + AvahiTimeoutCallback callback,
343 + AvahiTimeout *timeout;
344 + AvahiCupsPoll *cups_poll = api->userdata;
346 + timeout = malloc(sizeof(AvahiTimeout));
347 + if (timeout == NULL)
350 + timeout->cups_poll = cups_poll;
351 + timeout->callback = callback;
352 + timeout->userdata = userdata;
353 + timeout->cupsd_timeout = cupsdAddTimeout (tv,
354 + (cupsd_timeoutfunc_t)timeout_cb,
356 + cupsArrayAdd (cups_poll->timeouts, timeout);
362 + * 'timeout_update' - Update the expiration time for a timeout
366 +timeout_update (AvahiTimeout *timeout,
367 + const struct timeval *tv)
369 + cupsdUpdateTimeout (timeout->cupsd_timeout, tv);
374 + * ' timeout_free' - Free a timeout
378 +timeout_free (AvahiTimeout *timeout)
380 + cupsArrayRemove (timeout->cups_poll->timeouts, timeout);
381 + cupsdRemoveTimeout (timeout->cupsd_timeout);
387 + * 'compare_watched_fds' - Compare watched file descriptors for array sorting
390 +compare_watched_fds(cupsd_watched_fd_t *p0,
391 + cupsd_watched_fd_t *p1)
394 + * Compare by fd (no two elements have the same fd)
397 + if (p0->fd == p1->fd)
400 + return (p0->fd < p1->fd ? -1 : 1);
405 + * 'avahi_cups_poll_new' - Create a new Avahi main loop object for CUPS
409 +avahi_cups_poll_new (void)
411 + AvahiCupsPoll *cups_poll = malloc(sizeof(AvahiCupsPoll));
412 + if (cups_poll == NULL)
415 + cups_poll->watched_fds = cupsArrayNew ((cups_array_func_t)compare_watched_fds,
417 + cups_poll->timeouts = cupsArrayNew (NULL, NULL);
419 + cups_poll->api.userdata = cups_poll;
420 + cups_poll->api.watch_new = watch_new;
421 + cups_poll->api.watch_free = watch_free;
422 + cups_poll->api.watch_update = watch_update;
423 + cups_poll->api.watch_get_events = watch_get_events;
425 + cups_poll->api.timeout_new = timeout_new;
426 + cups_poll->api.timeout_update = timeout_update;
427 + cups_poll->api.timeout_free = timeout_free;
429 + return (cups_poll);
434 + * 'avahi_cups_poll_free' - Free an Avahi main loop object for CUPS
437 +avahi_cups_poll_free (AvahiCupsPoll *cups_poll)
439 + cupsd_watched_fd_t *watched_fd;
441 + for (watched_fd = (cupsd_watched_fd_t*)cupsArrayFirst(cups_poll->watched_fds);
443 + watched_fd = (cupsd_watched_fd_t*)cupsArrayNext(cups_poll->watched_fds))
444 + cupsArrayClear (watched_fd->watches);
446 + cupsArrayClear (cups_poll->watched_fds);
447 + cupsArrayClear (cups_poll->timeouts);
452 + * 'avahi_cups_poll_get' - Get the abstract poll API structure
456 +avahi_cups_poll_get (AvahiCupsPoll *cups_poll)
458 + return (&cups_poll->api);
462 +#endif /* HAVE_AVAHI ... from top of file */
467 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/avahi.h cups-2.3.3/scheduler/avahi.h
468 --- cups-2.3.3.org/scheduler/avahi.h 1970-01-01 01:00:00.000000000 +0100
469 +++ cups-2.3.3/scheduler/avahi.h 2021-04-20 22:45:53.873155054 +0200
474 + * Avahi poll implementation for the CUPS scheduler.
476 + * Copyright (C) 2010, 2011 Red Hat, Inc.
478 + * Tim Waugh <twaugh@redhat.com>
480 + * Redistribution and use in source and binary forms, with or without
481 + * modification, are permitted provided that the following conditions
484 + * Redistributions of source code must retain the above copyright
485 + * notice, this list of conditions and the following disclaimer.
487 + * Redistributions in binary form must reproduce the above copyright
488 + * notice, this list of conditions and the following disclaimer in the
489 + * documentation and/or other materials provided with the distribution.
491 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
492 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
493 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
494 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
495 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
496 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
497 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
498 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
499 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
500 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
501 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
502 + * OF THE POSSIBILITY OF SUCH DAMAGE.
508 +# include <avahi-client/client.h>
509 +# include <avahi-client/publish.h>
510 +#endif /* HAVE_AVAHI */
512 +#ifdef HAVE_AUTHORIZATION_H
513 +# include <Security/Authorization.h>
514 +#endif /* HAVE_AUTHORIZATION_H */
521 + cups_array_t *watched_fds;
522 + cups_array_t *timeouts;
524 +#endif /* HAVE_AVAHI */
531 +extern AvahiCupsPoll * avahi_cups_poll_new(void);
532 +extern void avahi_cups_poll_free(AvahiCupsPoll *cups_poll);
533 +extern const AvahiPoll *avahi_cups_poll_get(AvahiCupsPoll *cups_poll);
534 +#endif /* HAVE_AVAHI */
540 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/cupsd.h cups-2.3.3/scheduler/cupsd.h
541 --- cups-2.3.3.org/scheduler/cupsd.h 2020-04-27 20:04:29.000000000 +0200
542 +++ cups-2.3.3/scheduler/cupsd.h 2021-04-20 22:45:53.873155054 +0200
543 @@ -115,6 +115,7 @@ extern const char *cups_hstrerror(int);
544 #include "colorman.h"
550 #include "subscriptions.h"
551 @@ -135,6 +136,15 @@ extern const char *cups_hstrerror(int);
553 typedef void (*cupsd_selfunc_t)(void *data);
557 + * Timeout callback function type...
560 +typedef struct _cupsd_timeout_s cupsd_timeout_t;
561 +typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
562 +#endif /* HAVE_AVAHI */
567 @@ -159,6 +169,9 @@ VAR int OnDemand VALUE(0);
568 /* Launched on demand */
569 #endif /* HAVE_ONDEMAND */
572 +VAR cups_array_t *Timeouts; /* Timed callbacks for main loop */
573 +#endif /* HAVE_AVAHI */
577 @@ -220,3 +233,15 @@ extern void cupsdStopSelect(void);
579 extern void cupsdStartServer(void);
580 extern void cupsdStopServer(void);
583 +extern void cupsdInitTimeouts(void);
584 +extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
585 + cupsd_timeoutfunc_t cb,
587 +extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
588 +extern void cupsdRunTimeout (cupsd_timeout_t *timeout);
589 +extern void cupsdUpdateTimeout (cupsd_timeout_t *timeout,
590 + const struct timeval *tv);
591 +extern void cupsdRemoveTimeout (cupsd_timeout_t *timeout);
592 +#endif /* HAVE_AVAHI */
593 \ No newline at end of file
594 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/dirsvc.c cups-2.3.3/scheduler/dirsvc.c
595 --- cups-2.3.3.org/scheduler/dirsvc.c 2020-04-27 20:04:29.000000000 +0200
596 +++ cups-2.3.3/scheduler/dirsvc.c 2021-04-20 22:45:53.873155054 +0200
597 @@ -190,7 +190,7 @@ cupsdStartBrowsing(void)
598 cupsdUpdateDNSSDName();
600 # else /* HAVE_AVAHI */
601 - if ((DNSSDMaster = avahi_threaded_poll_new()) == NULL)
602 + if ((DNSSDMaster = avahi_cups_poll_new()) == NULL)
604 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create DNS-SD thread.");
606 @@ -201,7 +201,7 @@ cupsdStartBrowsing(void)
608 int error; /* Error code, if any */
610 - DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
611 + DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
613 if (DNSSDClient == NULL)
615 @@ -212,11 +212,9 @@ cupsdStartBrowsing(void)
616 if (FatalErrors & CUPSD_FATAL_BROWSE)
617 cupsdEndProcess(getpid(), 0);
619 - avahi_threaded_poll_free(DNSSDMaster);
620 + avahi_cups_poll_free(DNSSDMaster);
624 - avahi_threaded_poll_start(DNSSDMaster);
626 # endif /* HAVE_DNSSD */
628 @@ -632,7 +630,7 @@ dnssdClientCallback(
629 * Renew Avahi client...
632 - DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
633 + DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
637 @@ -698,17 +696,11 @@ dnssdDeregisterInstance(
640 # else /* HAVE_AVAHI */
641 - if (!from_callback)
642 - avahi_threaded_poll_lock(DNSSDMaster);
646 avahi_entry_group_free(*srv);
650 - if (!from_callback)
651 - avahi_threaded_poll_unlock(DNSSDMaster);
652 # endif /* HAVE_DNSSD */
655 @@ -1027,16 +1019,10 @@ dnssdRegisterInstance(
658 # else /* HAVE_AVAHI */
659 - if (!from_callback)
660 - avahi_threaded_poll_lock(DNSSDMaster);
663 *srv = avahi_entry_group_new(DNSSDClient, dnssdRegisterCallback, NULL);
666 - if (!from_callback)
667 - avahi_threaded_poll_unlock(DNSSDMaster);
669 cupsdLogMessage(CUPSD_LOG_WARN, "DNS-SD registration of \"%s\" failed: %s",
670 name, dnssdErrorString(avahi_client_errno(DNSSDClient)));
672 @@ -1151,9 +1137,6 @@ dnssdRegisterInstance(
673 cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD commit of \"%s\" failed.",
677 - if (!from_callback)
678 - avahi_threaded_poll_unlock(DNSSDMaster);
679 # endif /* HAVE_DNSSD */
682 @@ -1324,9 +1307,6 @@ dnssdStop(void)
685 # else /* HAVE_AVAHI */
687 - avahi_threaded_poll_stop(DNSSDMaster);
691 avahi_client_free(DNSSDClient);
692 @@ -1335,7 +1315,7 @@ dnssdStop(void)
696 - avahi_threaded_poll_free(DNSSDMaster);
697 + avahi_cups_poll_free(DNSSDMaster);
700 # endif /* HAVE_DNSSD */
701 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/dirsvc.h cups-2.3.3/scheduler/dirsvc.h
702 --- cups-2.3.3.org/scheduler/dirsvc.h 2020-04-27 20:04:29.000000000 +0200
703 +++ cups-2.3.3/scheduler/dirsvc.h 2021-04-20 22:45:53.873155054 +0200
704 @@ -45,7 +45,7 @@ VAR cups_array_t *DNSSDPrinters VALUE(NU
705 VAR DNSServiceRef DNSSDMaster VALUE(NULL);
706 /* Master DNS-SD service reference */
707 # else /* HAVE_AVAHI */
708 -VAR AvahiThreadedPoll *DNSSDMaster VALUE(NULL);
709 +VAR AvahiCupsPoll *DNSSDMaster VALUE(NULL);
710 /* Master polling interface for Avahi */
711 VAR AvahiClient *DNSSDClient VALUE(NULL);
712 /* Client information */
713 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/main.c cups-2.3.3/scheduler/main.c
714 --- cups-2.3.3.org/scheduler/main.c 2021-04-20 22:45:53.709821838 +0200
715 +++ cups-2.3.3/scheduler/main.c 2021-04-20 22:45:53.873155054 +0200
716 @@ -132,7 +132,10 @@ main(int argc, /* I - Number of comm
717 int service_idle_exit = 0;
718 /* Idle exit on select timeout? */
719 #endif /* HAVE_ONDEMAND */
722 + cupsd_timeout_t *tmo; /* Next scheduled timed callback */
723 + long tmo_delay; /* Time before it must be called */
724 +#endif /* HAVE_AVAHI */
728 @@ -600,6 +603,14 @@ main(int argc, /* I - Number of comm
734 + * Initialize timed callback structures.
737 + cupsdInitTimeouts();
738 +#endif /* HAVE_AVAHI */
743 @@ -934,6 +945,16 @@ main(int argc, /* I - Number of comm
745 #endif /* __APPLE__ */
749 + * If a timed callback is due, run it.
752 + tmo = cupsdNextTimeout (&tmo_delay);
753 + if (tmo && tmo_delay == 0)
754 + cupsdRunTimeout (tmo);
755 +#endif /* HAVE_AVAHI */
759 * Update the network interfaces once a minute...
760 @@ -1643,6 +1664,10 @@ select_timeout(int fds) /* I - Number
761 cupsd_client_t *con; /* Client information */
762 cupsd_job_t *job; /* Job information */
763 const char *why; /* Debugging aid */
765 + cupsd_timeout_t *tmo; /* Timed callback */
766 + long tmo_delay; /* Seconds before calling it */
767 +#endif /* HAVE_AVAHI */
770 cupsdLogMessage(CUPSD_LOG_DEBUG2, "select_timeout: JobHistoryUpdate=%ld",
771 @@ -1688,6 +1713,19 @@ select_timeout(int fds) /* I - Number
773 #endif /* __APPLE__ */
777 + * See if there are any scheduled timed callbacks to run.
780 + if ((tmo = cupsdNextTimeout(&tmo_delay)) != NULL &&
781 + (now + tmo_delay) < timeout)
783 + timeout = tmo_delay;
784 + why = "run a timed callback";
786 +#endif /* HAVE_AVAHI */
789 * Check whether we are accepting new connections...
791 diff -urNp -x '*.orig' cups-2.3.3.org/scheduler/timeout.c cups-2.3.3/scheduler/timeout.c
792 --- cups-2.3.3.org/scheduler/timeout.c 1970-01-01 01:00:00.000000000 +0100
793 +++ cups-2.3.3/scheduler/timeout.c 2021-04-20 22:45:53.873155054 +0200
798 + * Timeout functions for the Common UNIX Printing System (CUPS).
800 + * Copyright (C) 2010, 2011 Red Hat, Inc.
802 + * Tim Waugh <twaugh@redhat.com>
804 + * Redistribution and use in source and binary forms, with or without
805 + * modification, are permitted provided that the following conditions
808 + * Redistributions of source code must retain the above copyright
809 + * notice, this list of conditions and the following disclaimer.
811 + * Redistributions in binary form must reproduce the above copyright
812 + * notice, this list of conditions and the following disclaimer in the
813 + * documentation and/or other materials provided with the distribution.
815 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
816 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
817 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
818 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
819 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
820 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
821 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
822 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
823 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
824 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
825 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
826 + * OF THE POSSIBILITY OF SUCH DAMAGE.
830 + * cupsdInitTimeouts() - Initialise timeout structure.
831 + * cupsdAddTimeout() - Add a timed callback.
832 + * cupsdNextTimeout() - Find the next enabled timed callback.
833 + * cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
834 + * cupsdRemoveTimeout() - Discard a timed callback.
835 + * compare_timeouts() - Compare timed callbacks for array sorting.
840 +#ifdef HAVE_AVAHI /* Applies to entire file... */
843 + * Include necessary headers...
848 +#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
849 +# include <malloc.h>
850 +#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
853 +# include <avahi-common/timeval.h>
854 +#endif /* HAVE_AVAHI */
857 +struct _cupsd_timeout_s
859 + struct timeval when;
861 + cupsd_timeoutfunc_t callback;
866 + * Local functions...
870 + * 'compare_timeouts()' - Compare timed callbacks for array sorting.
874 +compare_addrs (void *p0, void *p1)
884 +compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
886 + int addrsdiff = compare_addrs (p0, p1);
889 + if (addrsdiff == 0)
892 + if (!p0->enabled || !p1->enabled)
894 + if (!p0->enabled && !p1->enabled)
895 + return (addrsdiff);
897 + return (p0->enabled ? -1 : 1);
900 + tvdiff = avahi_timeval_compare (&p0->when, &p1->when);
904 + return (addrsdiff);
909 + * 'cupsdInitTimeouts()' - Initialise timeout structures.
913 +cupsdInitTimeouts(void)
915 + Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
920 + * 'cupsdAddTimeout()' - Add a timed callback.
923 +cupsd_timeout_t * /* O - Timeout handle */
924 +cupsdAddTimeout(const struct timeval *tv, /* I - Absolute time */
925 + cupsd_timeoutfunc_t cb, /* I - Callback function */
926 + void *data) /* I - User data */
928 + cupsd_timeout_t *timeout;
930 + timeout = malloc (sizeof(cupsd_timeout_t));
931 + if (timeout != NULL)
933 + timeout->enabled = (tv != NULL);
936 + timeout->when.tv_sec = tv->tv_sec;
937 + timeout->when.tv_usec = tv->tv_usec;
940 + timeout->callback = cb;
941 + timeout->data = data;
942 + cupsArrayAdd (Timeouts, timeout);
950 + * 'cupsdNextTimeout()' - Find the next enabled timed callback.
953 +cupsd_timeout_t * /* O - Next enabled timeout or NULL */
954 +cupsdNextTimeout(long *delay) /* O - Seconds before scheduled */
956 + cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
957 + struct timeval curtime;
959 + if (first && !first->enabled)
962 + if (first && delay)
964 + gettimeofday (&curtime, NULL);
965 + if (avahi_timeval_compare (&curtime, &first->when) > 0)
969 + *delay = 1 + first->when.tv_sec - curtime.tv_sec;
970 + if (first->when.tv_usec < curtime.tv_usec)
980 + * 'cupsdRunTimeout()' - Run a timed callback.
984 +cupsdRunTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
988 + timeout->enabled = 0;
989 + if (!timeout->callback)
991 + timeout->callback (timeout, timeout->data);
995 + * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
999 +cupsdUpdateTimeout(cupsd_timeout_t *timeout, /* I - Timeout */
1000 + const struct timeval *tv) /* I - Absolute time or NULL */
1002 + cupsArrayRemove (Timeouts, timeout);
1003 + timeout->enabled = (tv != NULL);
1006 + timeout->when.tv_sec = tv->tv_sec;
1007 + timeout->when.tv_usec = tv->tv_usec;
1009 + cupsArrayAdd (Timeouts, timeout);
1014 + * 'cupsdRemoveTimeout()' - Discard a timed callback.
1018 +cupsdRemoveTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
1020 + cupsArrayRemove (Timeouts, timeout);
1025 +#endif /* HAVE_AVAHI ... from top of file */