]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/subscriptions.c
Load cups into easysw/current.
[thirdparty/cups.git] / scheduler / subscriptions.c
index 72ae19a5ee959f449276a166d693a1a9a57e0904..f3a320594776364db53d70ad64be4dba41193300 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: subscriptions.c 181 2006-06-22 20:01:18Z jlovell $"
+ * "$Id: subscriptions.c 5878 2006-08-24 15:55:42Z mike $"
  *
  *   Subscription routines for the Common UNIX Printing System (CUPS) scheduler.
  *
@@ -89,6 +89,11 @@ cupsdAddEvent(
   cupsd_subscription_t *sub;           /* Current subscription */
 
 
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
+                  "cupsdAddEvent(event=%s, dest=%p(%s), job=%p(%d), text=\"%s\", ...)",
+                 cupsdEventName(event), dest, dest ? dest->name : "",
+                 job, job ? job->id : 0, text);
+
  /*
   * Keep track of events with any OS-supplied notification mechanisms...
   */
@@ -262,7 +267,7 @@ cupsdAddEvent(
                           "job-stopped");
               break;
 
-         case IPP_JOB_CANCELLED :
+         case IPP_JOB_CANCELED :
               ippAddString(temp->attrs, IPP_TAG_EVENT_NOTIFICATION,
                           IPP_TAG_KEYWORD, "job-state-reasons", NULL,
                           "job-canceled-by-user");
@@ -284,13 +289,13 @@ cupsdAddEvent(
        ippAddInteger(temp->attrs, IPP_TAG_EVENT_NOTIFICATION, IPP_TAG_INTEGER,
                      "job-impressions-completed",
                      job->sheets ? job->sheets->values[0].integer : 0);
+      }
 
-       /*
-       * Send the notification for this subscription...
-       */
+     /*
+      * Send the notification for this subscription...
+      */
 
-       cupsd_send_notification(sub, temp);
-      }
+      cupsd_send_notification(sub, temp);
     }
   }
 
@@ -1240,13 +1245,12 @@ cupsdStopAllNotifiers(void)
 void
 cupsdUpdateNotifierStatus(void)
 {
-  char         *ptr,                   /* Pointer to end of line in buffer */
-               message[1024];          /* Pointer to message text */
+  char         message[1024];          /* Pointer to message text */
   int          loglevel;               /* Log level for message */
 
 
-  while ((ptr = cupsdStatBufUpdate(NotifierStatusBuffer, &loglevel,
-                                   message, sizeof(message))) != NULL)
+  while (cupsdStatBufUpdate(NotifierStatusBuffer, &loglevel,
+                            message, sizeof(message)))
     if (!strchr(NotifierStatusBuffer->buffer, '\n'))
       break;
 }
@@ -1379,7 +1383,7 @@ cupsd_send_notification(
   ipp_state_t  state;                  /* IPP event state */
 
 
-  cupsdLogMessage(CUPSD_LOG_DEBUG,
+  cupsdLogMessage(CUPSD_LOG_DEBUG2,
                   "cupsd_send_notification(sub=%p(%d), event=%p(%s))\n",
                   sub, sub->id, event, cupsdEventName(event->event));
 
@@ -1435,13 +1439,16 @@ cupsd_send_notification(
 
   if (sub->recipient)
   {
-    if (sub->pipe < 0)
-      cupsd_start_notifier(sub);
+    for (;;)
+    {
+      if (sub->pipe < 0)
+       cupsd_start_notifier(sub);
 
-    cupsdLogMessage(CUPSD_LOG_DEBUG, "sub->pipe=%d", sub->pipe);
+      cupsdLogMessage(CUPSD_LOG_DEBUG2, "sub->pipe=%d", sub->pipe);
+
+      if (sub->pipe < 0)
+       break;
 
-    if (sub->pipe >= 0)
-    {
       event->attrs->state = IPP_IDLE;
 
       while ((state = ippWriteFile(sub->pipe, event->attrs)) != IPP_DATA)
@@ -1449,9 +1456,34 @@ cupsd_send_notification(
          break;
 
       if (state == IPP_ERROR)
+      {
+        if (errno == EPIPE)
+       {
+        /*
+         * Notifier died, try restarting it...
+         */
+
+          cupsdLogMessage(CUPSD_LOG_WARN,
+                         "Notifier for subscription %d (%s) went away, "
+                         "retrying!",
+                         sub->id, sub->recipient);
+         cupsdEndProcess(sub->pid, 0);
+
+         close(sub->pipe);
+         sub->pipe = -1;
+          continue;
+       }
+
         cupsdLogMessage(CUPSD_LOG_ERROR,
                        "Unable to send event for subscription %d (%s)!",
                        sub->id, sub->recipient);
+      }
+
+     /*
+      * If we get this far, break out of the loop...
+      */
+
+      break;
     }
   }
 
@@ -1473,7 +1505,6 @@ cupsd_start_notifier(
 {
   int  pid;                            /* Notifier process ID */
   int  fds[2];                         /* Pipe file descriptors */
-  int  envc;                           /* Number of environment variables */
   char *argv[4],                       /* Command-line arguments */
        *envp[MAX_ENV],                 /* Environment variables */
        user_data[128],                 /* Base-64 encoded user data */
@@ -1513,7 +1544,7 @@ cupsd_start_notifier(
   * Setup the environment...
   */
 
-  envc = cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+  cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
 
  /*
   * Create pipes as needed...
@@ -1591,5 +1622,5 @@ cupsd_start_notifier(
 
 
 /*
- * End of "$Id: subscriptions.c 181 2006-06-22 20:01:18Z jlovell $".
+ * End of "$Id: subscriptions.c 5878 2006-08-24 15:55:42Z mike $".
  */