Blame SOURCES/cups-filters-deleted-master.patch

905cb0
diff -up cups-filters-1.0.35/utils/cups-browsed.c.deleted-master cups-filters-1.0.35/utils/cups-browsed.c
905cb0
--- cups-filters-1.0.35/utils/cups-browsed.c.deleted-master	2020-03-24 12:39:38.535487257 +0100
905cb0
+++ cups-filters-1.0.35/utils/cups-browsed.c	2020-03-24 12:39:38.538487233 +0100
905cb0
@@ -358,6 +358,7 @@ static unsigned int CreateRemoteCUPSPrin
905cb0
 static int NewIPPPrinterQueuesShared = 0;
905cb0
 static load_balancing_type_t LoadBalancingType = QUEUE_ON_CLIENT;
905cb0
 static const char *DefaultOptions = NULL;
905cb0
+static remote_printer_t *deleted_master = NULL;
905cb0
 static int terminating = 0; /* received SIGTERM, ignore callbacks,
905cb0
 			       break loops */
905cb0
 static int in_shutdown = 0;
905cb0
@@ -3179,6 +3180,30 @@ gboolean handle_cups_queues(gpointer unu
905cb0
   const char *customval;
905cb0
   const char *val = NULL;
905cb0
 
905cb0
+  /* Create dummy entry to point slaves at when their master is about to
905cb0
+     get removed now (if we point them to NULL, we would try to remove
905cb0
+     the already removed CUPS queue again when it comes to the removal
905cb0
+     of the slave. */
905cb0
+  if (deleted_master == NULL) {
905cb0
+    if ((deleted_master =
905cb0
+	 (remote_printer_t *)calloc(1, sizeof(remote_printer_t))) == NULL) {
905cb0
+      debug_printf("ERROR: Unable to allocate memory.\n");
905cb0
+      if (in_shutdown == 0)
905cb0
+	recheck_timer ();
905cb0
+      return FALSE;
905cb0
+    }
905cb0
+    memset(deleted_master, 0, sizeof(remote_printer_t));
905cb0
+    deleted_master->uri = "<DELETED>";
905cb0
+  }
905cb0
+
905cb0
+  /* Now redirect the slave_of pointers of the masters which get deleted now
905cb0
+     to this dummy entry */
905cb0
+  for (p = (remote_printer_t *)cupsArrayFirst(remote_printers);
905cb0
+       p; p = (remote_printer_t *)cupsArrayNext(remote_printers))
905cb0
+    if (p->status == STATUS_DISAPPEARED &&
905cb0
+        (q = p->duplicate_of) != NULL && q->status == STATUS_DISAPPEARED )
905cb0
+      p->duplicate_of = deleted_master;
905cb0
+
905cb0
   debug_printf("Processing printer list ...\n");
905cb0
   for (p = (remote_printer_t *)cupsArrayFirst(remote_printers);
905cb0
        p; p = (remote_printer_t *)cupsArrayNext(remote_printers)) {
905cb0
@@ -3303,7 +3328,8 @@ gboolean handle_cups_queues(gpointer unu
905cb0
       } else {
905cb0
 	/* "master printer" of this duplicate */
905cb0
 	q = p->duplicate_of;
905cb0
-	if (q->status != STATUS_DISAPPEARED) {
905cb0
+        /* Don't update the deleted master */
905cb0
+	if (q != deleted_master && q->status != STATUS_DISAPPEARED) {
905cb0
 	  debug_printf("Removed duplicate printer %s on %s:%d, scheduling its master printer %s on host %s, port %d for update.\n",
905cb0
 		       p->name, p->host, p->port, q->name, q->host, q->port);
905cb0
 	  /* Schedule for update */
905cb0
@@ -6915,6 +6941,8 @@ fail:
905cb0
   if (debug_logfile == 1)
905cb0
     stop_debug_logging();
905cb0
   
905cb0
+  if (deleted_master != NULL)
905cb0
+    free(deleted_master);
905cb0
   if (DefaultOptions != NULL)
905cb0
     free(DefaultOptions);
905cb0
   if (DomainSocket != NULL)