From 9383b377eba6ddb5ed80ebb244907e9be6ccd169 Mon Sep 17 00:00:00 2001 From: Michael R Sweet Date: Wed, 27 Mar 2024 14:38:46 -0400 Subject: [PATCH] Update CUPS-Create-Local-Printer to preserve the existing printer based on the device URI (Issue #871) Also keep the temporary printer for up to 5 minutes without activity, and update the state change time every time CUPS-Create-Local-Printer is called. --- CHANGES.md | 5 ++++- cups/dest.c | 2 ++ scheduler/ipp.c | 13 ++++++++++++- scheduler/printers.c | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 0775df7c4e..39c3eff1b6 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -5,7 +5,8 @@ Changes in CUPS v2.5b1 (TBA) ---------------------------- - Added `cupsDNSSD` APIs. -- Added `cupsConcatString` and `cupsCopyString` string APIs. +- Added `cupsConcatString`, `cupsCopyString`, and `cupsFormatString` string + APIs. - Added new APIs for form, JSON, JWT, IPP, and raster setup. - Added OpenSSL support for `cupsHashData` (Issue #762) - Added warning if the device has to do IPP request for 'all,media-col-database' @@ -56,6 +57,8 @@ Changes in CUPS v2.5b1 (TBA) numbers as strings instead of keywords as `InputSlot` values (Issue #859) - Fixed IPP backend to support the "print-scaling" option with IPP printers (Issue #862) +- Fixed potential race condition for the creation of temporary queues + (Issue #871) - Fixed Oki 407 freeze when printing larger jobs (Issue #877) - Fixed checking for required attributes during PPD generation (Issue #890) - Fixed pwg-raster-document-resolution-supported and urf-supported values diff --git a/cups/dest.c b/cups/dest.c index 8c27cb5e71..9c589b0d0b 100644 --- a/cups/dest.c +++ b/cups/dest.c @@ -814,7 +814,9 @@ _cupsCreateDest(const char *name, // I - Printer name response = cupsDoRequest(http, request, "/"); if ((attr = ippFindAttribute(response, "printer-uri-supported", IPP_TAG_URI)) != NULL) + { cupsCopyString(uri, ippGetString(attr, 0, NULL), urisize); + } else { ippDelete(response); diff --git a/scheduler/ipp.c b/scheduler/ipp.c index a01d30d714..c5c9ac9cdb 100644 --- a/scheduler/ipp.c +++ b/scheduler/ipp.c @@ -5592,10 +5592,21 @@ create_local_printer( if ((printer = cupsdFindDest(name)) != NULL) { - send_ipp_status(con, IPP_STATUS_ERROR_NOT_POSSIBLE, _("Printer \"%s\" already exists."), name); + printer->state_time = time(NULL); + send_ipp_status(con, IPP_STATUS_OK, _("Printer \"%s\" already exists."), name); goto add_printer_attributes; } + for (printer = (cupsd_printer_t *)cupsArrayGetFirst(Printers); printer; printer = (cupsd_printer_t *)cupsArrayGetNext(Printers)) + { + if (printer->device_uri && !strcmp(ptr, printer->device_uri)) + { + printer->state_time = time(NULL); + send_ipp_status(con, IPP_STATUS_OK, _("Printer \"%s\" already exists."), printer->name); + goto add_printer_attributes; + } + } + /* * Create the printer... */ diff --git a/scheduler/printers.c b/scheduler/printers.c index 2bb80455f1..b857b26de8 100644 --- a/scheduler/printers.c +++ b/scheduler/printers.c @@ -778,11 +778,11 @@ cupsdDeleteTemporaryPrinters(int force) /* I - Force deletion instead of auto? * "cupsdDeleteTemporaryPrinters: Removing unused temporary printers"); /* - * Allow temporary printers to stick around for 60 seconds after the last job + * Allow temporary printers to stick around for 5 minutes after the last job * completes. */ - unused_time = time(NULL) - 60; + unused_time = time(NULL) - 300; for (p = (cupsd_printer_t *)cupsArrayFirst(Printers); p; p = (cupsd_printer_t *)cupsArrayNext(Printers)) { -- 2.47.2