scheduler: Fix cleaning jobs by loading times when needed
Currently if we load jobs from job.cache, we don't set correct times
for `history_time` and `file_time`, resulting them in being 0 and the
jobs avoids the cleanup by cupsd when needed, leading into eating up
memory space.
It happens because none of the functions which set those job members are
not called - `cupsdSetJobState()` is used when changing job states,
`cupsdUpdateJobs()` during partial reload and `cupsdLoadJob()` is
guarded by condition in `load_job_cache()`.
The fix is to change conditional in `load_job_cache()` which will cause
loading of the job if cupsd is set to clean up job history, or if cupsd
should clean up job files and the job still has some.
Introduce print-as-raster as printer/job attribute
Some printers do not take kindly newer PDF versions which results in
omitting font characters in the printout. Such jobs print fine as a
raster, however retrying as raster depends on benevolence of the printer
firmware what it counts as an unrecoverable printing error.
In the past, we preferred raster over PDF in cups-filters, causing other
issues like with finishings, or solutions like generating PCLm PPD were
mentioned, however it would require a way how to define for which models
it should be used, and take of such database.
Thus introducing print-as-raster job attribute, which makes the job
to be printed as raster, and print-as-raster-default printer attributes,
which makes any job coming into the printer object to be printed as raster.
Internally it uses similar mechanism as raster retry, which was adjusted
to match both use cases now.
Changed the end-of-search criteria for ippfind -T 0
Previously, with the -T 0 option ("search quickly with automatic
timeout"), ippfind used the following criteria to determine when the
search was complete:
1. At least one service was discovered, and
2. Either all discovered services were resolved or 2.5 seconds had
passed since the last update.
However, this algorithm caused unreliable behavior when a mix of devices
was present—some that could be discovered quickly (such as cached or
locally published devices via ipp-usb) and others that required more
time (such as network devices). As a result, ippfind often terminated
prematurely, missing network devices in its output.
The updated end-of-search criteria are as follows:
1. All discovered services must be either resolved or have at least 1.0
second since their last update, and
2. The total discovery time of at least 2.5 seconds has passed.
This updated algorithm significantly improves discovery reliability.
- avahi_simple_poll_set_func and poll_callback removed
- avahi_simple_poll_iterate timeout reduced to 100 ms
ippfind previously used avahi_simple_poll_set_func() to replace the
system-provided poll() function with a custom poll_callback() that
enforced a fixed 100 ms timeout.
The original code comment claimed that Avahi always calls this callback
with a zero timeout (referencing Avahi #127). However, after
instrumenting poll_callback() with printf to log the actual timeout
values, I observed that Avahi sometimes passes zero and sometimes passes
the timeout provided to avahi_simple_poll_iterate(). Despite this, there
was no CPU overuse—as would be expected if a zero timeout were always
used.
In reality, there is no bug in Avahi.
The timeout passed to the poll callback represents the time remaining
until Avahi's next scheduled time-based event. Avahi may set internal
timers with short or even zero timeouts, causing poll() to be called
with a timeout shorter than the one passed to
avahi_simple_poll_iterate(). This is normal and expected behavior.
Additionally, the Avahi API reference states that
avahi_simple_poll_iterate() blocks for AT MOST the specified timeout. In
practice, it blocks until the nearest event occurs, but never longer
than the given timeout. We cannot assume that this function will always
delay execution for the full duration of its argument.
To improve precision, I also reduced the avahi_simple_poll_iterate()
timeout from 500 ms to 100 ms. This change only affects how accurately
ippfind measures search time when the search ends due to deadline
expiration.
With these adjustments, ippfind maintains the same behavior as before
but no longer misuses the Avahi API.
Zdenek Dohnal [Fri, 14 Mar 2025 06:42:25 +0000 (07:42 +0100)]
Avoid NULL strcmp argument
It is possible for format to be NULL (as described in the function signature)
which causes a segmentation fault when it is passed to strcmp. This patch changes
the conditional to short-circuit if format is NULL and only call strcmp otherwise.
Zdenek Dohnal [Wed, 12 Mar 2025 15:26:55 +0000 (16:26 +0100)]
backend/ipp.c: Raise alert if there is issue with cert
Currently we show more detailed info about this error in debug logs, but
since there are not many desktops to pick up our dBUS notification, it
would be great to report it in CUPS log too.
Zdenek Dohnal [Tue, 7 Jan 2025 14:12:15 +0000 (15:12 +0100)]
Add `NoSystem` SSLOptions value
In case using system crypto policy breaks communication with device
irreversibly (f.e. if device does not support better key exchange
algorithm), the new option value gives a way how to opt-out from crypto
policy if user do not want to change default system crypto policy for
the whole machine.
Zdenek Dohnal [Fri, 6 Dec 2024 06:59:16 +0000 (07:59 +0100)]
tls-gnutls.c: Use system crypto policy if available
Some Linux systems provide a way how to control cryptography on system or service level via cryptographic policies. OpenSSL implementation reflects system changes to some degree, however GnuTLS implementation does not take system policy into account.
GnuTLS supports fallback mechanism, so we can fallback to NORMAL if @System is not defined on the system.
Fortunately, the current GnuTLS implementation allows overrides via priority strings (so no "this cipher/hash is disabled" if we enabled them in our application by priority string), so allowing to honor system policy can save us work if someone wants to disable a specific cipher, so we don't have to implement it in libcups.
Zdenek Dohnal [Mon, 2 Dec 2024 13:20:26 +0000 (14:20 +0100)]
scheduler: Clean up failed IPP Everywhere permanent queues
If creating of permanent queue with IPP Everywhere model fails
in separate thread, the print queue is created as raw.
It would be great if we remove such queue if creation fails,
and marking them as temporary would make them to be removed automatically.
> A slice unit is a concept for hierarchically managing resources of a group of processes.
Benefits of collecting our two systemd services into a slice include
* ease of configuring resource limits on the entire CUPS system,
* ``systemctl status`` showing the CUPS units in an indented subtree,
making it more organized,
* and the possibility of viewing all interlaced logs from all of the CUPS
daemons using ``journalctl -u system-cups.slice``.
[1]:
https://www.freedesktop.org/software/systemd/man/latest/systemd.slice.html
or ``man systemd.slice(5)``