/*
- * "$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.
*
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...
*/
"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");
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);
}
}
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;
}
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));
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)
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;
}
}
{
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 */
* Setup the environment...
*/
- envc = cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
+ cupsdLoadEnv(envp, (int)(sizeof(envp) / sizeof(envp[0])));
/*
* Create pipes as needed...
/*
- * 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 $".
*/