]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Update CUPS-Create-Local-Printer to preserve the existing printer based on the
authorMichael R Sweet <msweet@msweet.org>
Wed, 27 Mar 2024 18:38:46 +0000 (14:38 -0400)
committerMichael R Sweet <msweet@msweet.org>
Wed, 27 Mar 2024 18:38:46 +0000 (14:38 -0400)
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
cups/dest.c
scheduler/ipp.c
scheduler/printers.c

index 0775df7c4e3097df5aeeb2bde6aec0a0862116ac..39c3eff1b6abc81f9eaecd31528b48e3eee35ceb 100644 (file)
@@ -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
index 8c27cb5e714bca2876c3070483cb506d6bba45c5..9c589b0d0b20be4f20be0c8cc50692372d62336e 100644 (file)
@@ -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);
index a01d30d714c07b57397ca493d02ecc942f33e4e3..c5c9ac9cdb3344e80a352a880d909b8c76f3c6ef 100644 (file)
@@ -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...
   */
index 2bb80455f133e1bc526ef2ba89d268f4f4e16783..b857b26de864b72f3e2fd45bae54169ebfa10e91 100644 (file)
@@ -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))
   {