~ubuntu-branches/ubuntu/utopic/cups/utopic

« back to all changes in this revision

Viewing changes to scheduler/timeout.c

  • Committer: Package Import Robot
  • Author(s): Didier Raboud, Till Kamppeter, Steve Langasek, Didier Raboud
  • Date: 2014-01-03 18:42:39 UTC
  • mfrom: (99.2.3 sid)
  • Revision ID: package-import@ubuntu.com-20140103184239-85wju2l7weie4dgo
Tags: 1.7.0-1
* New 1.7.0 upstream release

[ Till Kamppeter ]
* Refresh most patches with quilt
* Removed usb-backend-do-not-crash-if-usb-disabled-in-bios and
  cupsd-no-crash-on-avahi-threaded-poll-shutdown patches as they got
  applied upstream
* Removed drop-arch-specifics-from-doc patch as it is not needed
  anymore
* Updated drop_unnecessary_dependencies, manpage-hyphen-minus,
  manpage-translations and ppd-poll-with-client-conf patches manually
  to apply to the new CUPS version
* Added error counting exception from
  usb-backend-do-not-crash-if-usb-disabled-in-bios to
  tests-ignore-warnings
* Install the newly added ippfind utility and its manpage in
  cups-client
* Added pwg.h to libcups2-dev package
* Call dh_auto_clean only if the file Makedefs is present, to avoid a
  FTBFS
* Added color management extensions from Joe Simon's GSoC 2013
  project.
* Patch cups-files.conf to activate CUPS daemon syncing of files when
  closing, so that config files (like printers.conf) do not
  mysteriously disappear (LP: #1157972)
* In the AppArmor profile, allow execution of programs in
  /etc/cups/interfaces/, needed to make CUPS working with queues based
  on System V interface scripts, especially PPD-less queues
  auto-generated by cups-browsed from cups-filters 1.0.41 on.
* Silenced AppArmor noise from udev.conf in syslog (LP: #1229766)

[ Steve Langasek ]
* Add cups-filters (>= 1.0.42) as alternative to foomatic-filters
  (which is deprecated) in package relationships

[ Didier Raboud ]
* Remove Roger Leigh from uploaders on his request with thanks for his
  past work!
* Switch avahi LSB Should-Start dependency to be avahi-daemon; also
  bump package relationship to >= 0.6.31-3~ (Closes: #731608)
* Refresh the manpage translation files
* Move the USB backend quirk rules file to cups-server-common
* Add 38 new 1.7.0 libcups2 symbols
* Mark one C++ libcupsppdc1 symbol as optional as it isn't exported in
  1.7.0 anymore
* Import Fedora patches:
  - to avoid sign-extending CRCs in gz decompression
  - to build with full read-only relocations
  - to fix job history logging (upstream patch)
  - to set the internal default for SyncOnClose to Yes, instead of
    only configuring it to Yes
  - to fix a stringpool corruption issue
  - to prevent USB timeouts causing incorrect print output
* Import Fedora patch updates:
  - to dont-use-dbus-from-two-threads patch so it removes a call to
    avahi_threaded_poll_stop()
  - to avoid_stale_lockfile_in_dbus_notifier patch to call _exit when
    handling SIGTERM
* Move manpage-translations patch at the very end of the patch series
  to have it include all our patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * "$Id$"
 
3
 *
 
4
 *   Timeout functions for the Common UNIX Printing System (CUPS).
 
5
 *
 
6
 *   Copyright (C) 2010, 2011 Red Hat, Inc.
 
7
 *   Authors:
 
8
 *     Tim Waugh <twaugh@redhat.com>
 
9
 *
 
10
 *   Redistribution and use in source and binary forms, with or without
 
11
 *   modification, are permitted provided that the following conditions
 
12
 *   are met:
 
13
 *
 
14
 *   Redistributions of source code must retain the above copyright
 
15
 *   notice, this list of conditions and the following disclaimer.
 
16
 *
 
17
 *   Redistributions in binary form must reproduce the above copyright
 
18
 *   notice, this list of conditions and the following disclaimer in the
 
19
 *   documentation and/or other materials provided with the distribution.
 
20
 *
 
21
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
22
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
23
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
24
 *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
25
 *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
26
 *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
27
 *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
28
 *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
29
 *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
30
 *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
31
 *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
32
 *   OF THE POSSIBILITY OF SUCH DAMAGE.
 
33
 *
 
34
 * Contents:
 
35
 *
 
36
 *   cupsdInitTimeouts()  - Initialise timeout structure.
 
37
 *   cupsdAddTimeout()    - Add a timed callback.
 
38
 *   cupsdNextTimeout()   - Find the next enabled timed callback.
 
39
 *   cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
 
40
 *   cupsdRemoveTimeout() - Discard a timed callback.
 
41
 *   compare_timeouts()   - Compare timed callbacks for array sorting.
 
42
 */
 
43
 
 
44
#include <config.h>
 
45
 
 
46
#ifdef HAVE_AVAHI /* Applies to entire file... */
 
47
 
 
48
/*
 
49
 * Include necessary headers...
 
50
 */
 
51
 
 
52
#include "cupsd.h"
 
53
 
 
54
#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
 
55
#  include <malloc.h>
 
56
#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
 
57
 
 
58
#ifdef HAVE_AVAHI
 
59
#  include <avahi-common/timeval.h>
 
60
#endif /* HAVE_AVAHI */
 
61
 
 
62
 
 
63
struct _cupsd_timeout_s
 
64
{
 
65
  struct timeval when;
 
66
  int enabled;
 
67
  cupsd_timeoutfunc_t callback;
 
68
  void *data;
 
69
};
 
70
 
 
71
/*
 
72
 * Local functions...
 
73
 */
 
74
 
 
75
/*
 
76
 * 'compare_timeouts()' - Compare timed callbacks for array sorting.
 
77
 */
 
78
 
 
79
static int
 
80
compare_addrs (void *p0, void *p1)
 
81
{
 
82
  if (p0 == p1)
 
83
    return (0);
 
84
  if (p0 < p1)
 
85
    return (-1);
 
86
  return (1);
 
87
}
 
88
 
 
89
static int
 
90
compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
 
91
{
 
92
  int addrsdiff = compare_addrs (p0, p1);
 
93
  int tvdiff;
 
94
 
 
95
  if (addrsdiff == 0)
 
96
    return (0);
 
97
 
 
98
  if (!p0->enabled || !p1->enabled)
 
99
  {
 
100
    if (!p0->enabled && !p1->enabled)
 
101
      return (addrsdiff);
 
102
 
 
103
    return (p0->enabled ? -1 : 1);
 
104
  }
 
105
 
 
106
  tvdiff = avahi_timeval_compare (&p0->when, &p1->when);
 
107
  if (tvdiff != 0)
 
108
    return (tvdiff);
 
109
 
 
110
  return (addrsdiff);
 
111
}
 
112
 
 
113
 
 
114
/*
 
115
 * 'cupsdInitTimeouts()' - Initialise timeout structures.
 
116
 */
 
117
 
 
118
void
 
119
cupsdInitTimeouts(void)
 
120
{
 
121
  Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
 
122
}
 
123
 
 
124
 
 
125
/*
 
126
 * 'cupsdAddTimeout()' - Add a timed callback.
 
127
 */
 
128
 
 
129
cupsd_timeout_t *                               /* O - Timeout handle */
 
130
cupsdAddTimeout(const struct timeval *tv,       /* I - Absolute time */
 
131
                cupsd_timeoutfunc_t cb,         /* I - Callback function */
 
132
                void *data)                     /* I - User data */
 
133
{
 
134
  cupsd_timeout_t *timeout;
 
135
 
 
136
  timeout = malloc (sizeof(cupsd_timeout_t));
 
137
  if (timeout != NULL)
 
138
  {
 
139
    timeout->enabled = (tv != NULL);
 
140
    if (tv)
 
141
    {
 
142
      timeout->when.tv_sec = tv->tv_sec;
 
143
      timeout->when.tv_usec = tv->tv_usec;
 
144
    }
 
145
 
 
146
    timeout->callback = cb;
 
147
    timeout->data = data;
 
148
    cupsArrayAdd (Timeouts, timeout);
 
149
  }
 
150
 
 
151
  return timeout;
 
152
}
 
153
 
 
154
 
 
155
/*
 
156
 * 'cupsdNextTimeout()' - Find the next enabled timed callback.
 
157
 */
 
158
 
 
159
cupsd_timeout_t *               /* O - Next enabled timeout or NULL */
 
160
cupsdNextTimeout(long *delay)   /* O - Seconds before scheduled */
 
161
{
 
162
  cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
 
163
  struct timeval curtime;
 
164
 
 
165
  if (first && !first->enabled)
 
166
    first = NULL;
 
167
 
 
168
  if (first && delay)
 
169
  {
 
170
    gettimeofday (&curtime, NULL);
 
171
    if (avahi_timeval_compare (&curtime, &first->when) > 0)
 
172
    {
 
173
      *delay = 0;
 
174
    } else {
 
175
      *delay = 1 + first->when.tv_sec - curtime.tv_sec;
 
176
      if (first->when.tv_usec < curtime.tv_usec)
 
177
        (*delay)--;
 
178
    }
 
179
  }
 
180
 
 
181
  return (first);
 
182
}
 
183
 
 
184
 
 
185
/*
 
186
 * 'cupsdRunTimeout()' - Run a timed callback.
 
187
 */
 
188
 
 
189
void
 
190
cupsdRunTimeout(cupsd_timeout_t *timeout)       /* I - Timeout */
 
191
{
 
192
  if (!timeout)
 
193
    return;
 
194
  timeout->enabled = 0;
 
195
  if (!timeout->callback)
 
196
    return;
 
197
  timeout->callback (timeout, timeout->data);
 
198
}
 
199
 
 
200
/*
 
201
 * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
 
202
 */
 
203
 
 
204
void
 
205
cupsdUpdateTimeout(cupsd_timeout_t *timeout,    /* I - Timeout */
 
206
                   const struct timeval *tv)    /* I - Absolute time or NULL */
 
207
{
 
208
  cupsArrayRemove (Timeouts, timeout);
 
209
  timeout->enabled = (tv != NULL);
 
210
  if (tv)
 
211
  {
 
212
    timeout->when.tv_sec = tv->tv_sec;
 
213
    timeout->when.tv_usec = tv->tv_usec;
 
214
  }
 
215
  cupsArrayAdd (Timeouts, timeout);
 
216
}
 
217
 
 
218
 
 
219
/*
 
220
 * 'cupsdRemoveTimeout()' - Discard a timed callback.
 
221
 */
 
222
 
 
223
void
 
224
cupsdRemoveTimeout(cupsd_timeout_t *timeout)    /* I - Timeout */
 
225
{
 
226
  cupsArrayRemove (Timeouts, timeout);
 
227
  free (timeout);
 
228
}
 
229
 
 
230
 
 
231
#endif /* HAVE_AVAHI ... from top of file */
 
232
 
 
233
/*
 
234
 * End of "$Id$".
 
235
 */