0001-Better-handle-damage-of-queues-created-by-cups-browsed.patch 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. From 57d9351ea45f47b3bd185f263b1e37d276cf17b8 Mon Sep 17 00:00:00 2001
  2. From: Till Kamppeter <till.kamppeter@gmail.com>
  3. Date: Wed, 6 Dec 2023 01:03:48 +0100
  4. Subject: [PATCH] Better handle damage of queues created by cups-browsed
  5. Fixes #429
  6. In issue #429 queues created by cups-browsed (with
  7. "implicitclass://..." device URI) and left over after cups-browsed
  8. shuts down (or crashes or gets killed) lose their cups-browsed flag
  9. "cups-browsed=true" for some unknown reason and are not identified as
  10. created by cups-browsed any more, making cups-browsed creating a fresh
  11. queue with another name while the user continues printing on the old
  12. queue which cups-browsed does not take care of any more (assign
  13. destination printers for the jobs). So the user gets the message "No
  14. destination host name supplied by cups-browsed for printer ..." in
  15. the error_log of CUPS.
  16. Done the following changes:
  17. - Queues with "implicitclass://..." device URI are always created by
  18. cups-browsed, so consider them as such regardless of the
  19. "cups-browsed=true" attribute.
  20. - If a queue gets overwritten and cups-browsed gets note of that by a
  21. printer-modified D-Bus notification, we will only drop control from
  22. this queue and create a new queue with a new name if the device URI
  23. gets replace by something different from "implicitclass://...". If
  24. the device URI stays intact and the PPD gets modified, we recover
  25. the PPD by regenerating the queue under its current name.
  26. This especially prevents from queues with "implicitclass://..." device
  27. URI not being handled by cups-browsed.
  28. ---
  29. daemon/cups-browsed.c | 27 ++++++++++++++++++++++++---
  30. 1 file changed, 24 insertions(+), 3 deletions(-)
  31. diff --git a/daemon/cups-browsed.c b/daemon/cups-browsed.c
  32. index c1e64fab..29fd34a1 100644
  33. --- a/daemon/cups-browsed.c
  34. +++ b/daemon/cups-browsed.c
  35. @@ -4090,6 +4090,13 @@ get_local_printers (void)
  36. cups_browsed_controlled = val && (!strcasecmp (val, "yes") ||
  37. !strcasecmp (val, "on") ||
  38. !strcasecmp (val, "true"));
  39. + if (!cups_browsed_controlled &&
  40. + strncmp(device_uri, "implicitclass://", 16) == 0)
  41. + {
  42. + cups_browsed_controlled = 1;
  43. + debug_printf ("Printer %s with URI %s does not have the \"cups-browsed=true\" attribute set, considering cups-browsed-created anyway, due to the implicitclass backend being used.\n",
  44. + dest->name, device_uri);
  45. + }
  46. httpAssembleURIf(HTTP_URI_CODING_ALL, uri, sizeof(uri), "ipp", NULL,
  47. "localhost", 0, "/printers/%s", dest->name);
  48. printer = new_local_printer (device_uri, get_printer_uuid(conn, uri),
  49. @@ -7176,7 +7183,11 @@ on_printer_deleted (CupsNotifier *object,
  50. }
  51. -static int
  52. +static int // 0: Queue OK, keep
  53. + // 1: Device URI overwritten, drop
  54. + // control
  55. + // 2: URI OK, PPD overwritten,
  56. + // recreate queue
  57. queue_overwritten (remote_printer_t *p)
  58. {
  59. http_t *conn = NULL;
  60. @@ -7306,7 +7317,7 @@ queue_overwritten (remote_printer_t *p)
  61. p->queue_name, (p->nickname ? p->nickname : "(no PPD)"),
  62. (makemodel ? makemodel :
  63. "(NickName not readable)"));
  64. - overwritten = 1;
  65. + overwritten = 2;
  66. }
  67. }
  68. }
  69. @@ -7349,7 +7360,7 @@ on_printer_modified (CupsNotifier *object,
  70. // avoid an infinite recursion
  71. goto end;
  72. - if (queue_overwritten(p))
  73. + if (queue_overwritten(p) == 1)
  74. {
  75. // Our generated local queue pointing to a remote printer got
  76. // overwritten by an externally created queue with the same
  77. @@ -7470,6 +7481,16 @@ on_printer_modified (CupsNotifier *object,
  78. if (in_shutdown == 0)
  79. recheck_timer();
  80. }
  81. + else if (queue_overwritten(p) == 2)
  82. + {
  83. + // Only the PPD got overwritten, the device URI is still
  84. + // "implicitclass://...", so we have a totally broken queue
  85. + // and simply re-create it under its original name
  86. + p->status = STATUS_TO_BE_CREATED;
  87. + p->timeout = time(NULL) + TIMEOUT_IMMEDIATELY;
  88. + debug_printf("CUPS queue %s with URI %s got damaged (PPD overwritten). Re-create it.",
  89. + printer, p->uri);
  90. + }
  91. else
  92. {
  93. if (terminating)