[cups] Allow "journal" log type for log output to system journal.

Tim Waugh twaugh at fedoraproject.org
Mon Oct 21 16:35:40 UTC 2013


commit 4fb45e11e67ecb6453ac04da022fa4b5127b0a3e
Author: Tim Waugh <twaugh at redhat.com>
Date:   Fri Oct 18 16:24:48 2013 +0100

    Allow "journal" log type for log output to system journal.

 cups-journal.patch |  510 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 cups.spec          |    8 +-
 2 files changed, 517 insertions(+), 1 deletions(-)
---
diff --git a/cups-journal.patch b/cups-journal.patch
new file mode 100644
index 0000000..5c309d9
--- /dev/null
+++ b/cups-journal.patch
@@ -0,0 +1,510 @@
+diff -up cups-1.7rc1/Makedefs.in.journal cups-1.7rc1/Makedefs.in
+--- cups-1.7rc1/Makedefs.in.journal	2013-10-21 16:18:06.323038476 +0100
++++ cups-1.7rc1/Makedefs.in	2013-10-21 16:18:06.373038711 +0100
+@@ -143,6 +143,7 @@ IPPFIND_BIN	=	@IPPFIND_BIN@
+ IPPFIND_MAN	=	@IPPFIND_MAN@
+ LAUNCHDLIBS	=	@LAUNCHDLIBS@
+ SDLIBS		=	@SDLIBS@
++SDJLIBS		=	@SDJLIBS@
+ LDFLAGS		=	-L../cgi-bin -L../cups -L../filter -L../ppdc \
+ 			-L../scheduler @LDARCHFLAGS@ \
+ 			@LDFLAGS@ @RELROFLAGS@ @PIEFLAGS@ $(OPTIM)
+diff -up cups-1.7rc1/config-scripts/cups-systemd.m4.journal cups-1.7rc1/config-scripts/cups-systemd.m4
+--- cups-1.7rc1/config-scripts/cups-systemd.m4.journal	2013-10-21 16:18:06.311038420 +0100
++++ cups-1.7rc1/config-scripts/cups-systemd.m4	2013-10-21 16:18:06.373038711 +0100
+@@ -22,6 +22,15 @@ if test "x$with_systemdsystemunitdir" !=
+ 	fi
+ fi
+ 
++SDJLIBS=""
++AC_MSG_CHECKING(for libsystemd-journal)
++if $PKGCONFIG --exists libsystemd-journal; then
++	AC_MSG_RESULT(yes)
++	SDJLIBS=`$PKGCONFIG --libs libsystemd-journal`
++	AC_DEFINE(HAVE_JOURNAL)
++else
++	AC_MSG_RESULT(no)
++fi
+ if test -n "$with_systemdsystemunitdir" -a "x$with_systemdsystemunitdir" != xno ; then
+         SYSTEMD_UNITS="cups.service cups.socket cups.path"
+ else
+@@ -30,6 +39,7 @@ fi
+ 
+ AC_SUBST(SYSTEMD_UNITS)
+ AC_SUBST(SDLIBS)
++AC_SUBST(SDJLIBS)
+ 
+ dnl
+ dnl "$Id$"
+diff -up cups-1.7rc1/config.h.in.journal cups-1.7rc1/config.h.in
+--- cups-1.7rc1/config.h.in.journal	2013-10-21 16:18:06.311038420 +0100
++++ cups-1.7rc1/config.h.in	2013-10-21 16:18:06.373038711 +0100
+@@ -458,6 +458,13 @@
+ 
+ 
+ /*
++ * Do we have systemd-journal support?
++ */
++
++#undef HAVE_JOURNAL
++
++
++/*
+  * Various scripting languages...
+  */
+ 
+diff -up cups-1.7rc1/scheduler/Makefile.journal cups-1.7rc1/scheduler/Makefile
+--- cups-1.7rc1/scheduler/Makefile.journal	2013-10-21 16:18:06.354038622 +0100
++++ cups-1.7rc1/scheduler/Makefile	2013-10-21 16:18:06.373038711 +0100
+@@ -383,7 +383,7 @@ cupsd:	$(CUPSDOBJS) $(LIBCUPSMIME) ../cu
+ 	$(CC) $(LDFLAGS) -o cupsd $(CUPSDOBJS) -L. -lcupsmime \
+ 		$(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \
+ 		$(LIBPAPER) $(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBS) \
+-		$(LIBGSSAPI) $(LIBWRAP) $(SDLIBS)
++		$(LIBGSSAPI) $(LIBWRAP) $(SDLIBS) $(SDJLIBS)
+ 
+ cupsd-static:	$(CUPSDOBJS) libcupsmime.a ../cups/$(LIBCUPSSTATIC)
+ 	echo Linking $@...
+@@ -391,7 +391,7 @@ cupsd-static:	$(CUPSDOBJS) libcupsmime.a
+ 		$(LIBZ) $(SSLLIBS) $(LIBSLP) $(LIBLDAP) $(PAMLIBS) \
+ 		../cups/$(LIBCUPSSTATIC) $(COMMONLIBS) $(LIBZ) $(LIBPAPER) \
+ 		$(LIBMALLOC) $(SERVERLIBS) $(DNSSDLIBS) $(LIBGSSAPI) \
+-		$(LIBWRAP)  $(SDLIBS)
++		$(LIBWRAP)  $(SDLIBS) $(SDJLIBS)
+ 
+ tls.o:	tls-darwin.c tls-gnutls.c tls-openssl.c
+ 
+diff -up cups-1.7rc1/scheduler/conf.c.journal cups-1.7rc1/scheduler/conf.c
+--- cups-1.7rc1/scheduler/conf.c.journal	2013-10-21 16:31:27.980798750 +0100
++++ cups-1.7rc1/scheduler/conf.c	2013-10-21 16:42:14.927834827 +0100
+@@ -973,9 +973,9 @@ cupsdReadConfiguration(void)
+   */
+ 
+ #ifdef HAVE_VSYSLOG
+-  if (!strcmp(AccessLog, "syslog") ||
+-      !strcmp(ErrorLog, "syslog") ||
+-      !strcmp(PageLog, "syslog"))
++  if (!strcmp(AccessLog, "syslog") || !strcmp(AccessLog, "journal") ||
++      !strcmp(ErrorLog, "syslog") || !strcmp(ErrorLog, "journal") ||
++      !strcmp(PageLog, "syslog") || !strcmp(PageLog, "journal"))
+     openlog("cupsd", LOG_PID | LOG_NOWAIT | LOG_NDELAY, LOG_LPR);
+ #endif /* HAVE_VSYSLOG */
+ 
+@@ -983,13 +983,13 @@ cupsdReadConfiguration(void)
+   * Make sure each of the log files exists and gets rotated as necessary...
+   */
+ 
+-  if (strcmp(AccessLog, "syslog"))
++  if (strcmp(AccessLog, "syslog") && strcmp(AccessLog, "journal"))
+     cupsdCheckLogFile(&AccessFile, AccessLog);
+ 
+-  if (strcmp(ErrorLog, "syslog"))
++  if (strcmp(ErrorLog, "syslog") && strcmp(ErrorLog, "journal"))
+     cupsdCheckLogFile(&ErrorFile, ErrorLog);
+ 
+-  if (strcmp(PageLog, "syslog"))
++  if (strcmp(PageLog, "syslog") && strcmp(PageLog, "journal"))
+     cupsdCheckLogFile(&PageFile, PageLog);
+ 
+  /*
+diff -up cups-1.7rc1/scheduler/conf.h.journal cups-1.7rc1/scheduler/conf.h
+--- cups-1.7rc1/scheduler/conf.h.journal	2013-10-21 16:18:06.369038692 +0100
++++ cups-1.7rc1/scheduler/conf.h	2013-10-21 16:18:06.373038711 +0100
+@@ -297,6 +297,8 @@ extern int	cupsdLogMessage(int level, co
+ extern int	cupsdLogPage(cupsd_job_t *job, const char *page);
+ extern int	cupsdLogRequest(cupsd_client_t *con, http_status_t code);
+ extern int	cupsdReadConfiguration(void);
++extern int	cupsdWriteErrorLogJob(cupsd_job_t *job, int level,
++				      const char *message);
+ extern int	cupsdWriteErrorLog(int level, const char *message);
+ 
+ 
+diff -up cups-1.7rc1/scheduler/job.c.journal cups-1.7rc1/scheduler/job.c
+--- cups-1.7rc1/scheduler/job.c.journal	2013-10-21 16:18:06.371038701 +0100
++++ cups-1.7rc1/scheduler/job.c	2013-10-21 16:18:06.374038716 +0100
+@@ -312,8 +312,7 @@ cupsdCheckJobs(void)
+ 
+     if (job->kill_time && job->kill_time <= curtime)
+     {
+-      cupsdLogMessage(CUPSD_LOG_ERROR, "[Job %d] Stopping unresponsive job.",
+-		      job->id);
++      cupsdLogJob(job, CUPSD_LOG_ERROR, "Stopping unresponsive job.");
+ 
+       stop_job(job, CUPSD_JOB_FORCE);
+       continue;
+@@ -1696,7 +1695,7 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+   * Load job attributes...
+   */
+ 
+-  cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] Loading attributes...", job->id);
++  cupsdLogJob(job, CUPSD_LOG_DEBUG, "Loading attributes...");
+ 
+   snprintf(jobfile, sizeof(jobfile), "%s/c%05d", RequestRoot, job->id);
+   if ((fp = cupsdOpenConfFile(jobfile)) == NULL)
+@@ -1704,9 +1703,8 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+ 
+   if (ippReadIO(fp, (ipp_iocb_t)cupsFileRead, 1, NULL, job->attrs) != IPP_DATA)
+   {
+-    cupsdLogMessage(CUPSD_LOG_ERROR,
+-		    "[Job %d] Unable to read job control file \"%s\".", job->id,
+-		    jobfile);
++    cupsdLogJob(job, CUPSD_LOG_ERROR,
++		"Unable to read job control file \"%s\".", jobfile);
+     cupsFileClose(fp);
+     goto error;
+   }
+@@ -1719,18 +1717,16 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+ 
+   if (!ippFindAttribute(job->attrs, "time-at-creation", IPP_TAG_INTEGER))
+   {
+-    cupsdLogMessage(CUPSD_LOG_ERROR,
+-		    "[Job %d] Missing or bad time-at-creation attribute in "
+-		    "control file.", job->id);
++    cupsdLogJob(job, CUPSD_LOG_ERROR,
++		"Missing or bad time-at-creation attribute in control file.");
+     goto error;
+   }
+ 
+   if ((job->state = ippFindAttribute(job->attrs, "job-state",
+                                      IPP_TAG_ENUM)) == NULL)
+   {
+-    cupsdLogMessage(CUPSD_LOG_ERROR,
+-		    "[Job %d] Missing or bad job-state attribute in control "
+-		    "file.", job->id);
++    cupsdLogJob(job, CUPSD_LOG_ERROR,
++		"Missing or bad job-state attribute in control file.");
+     goto error;
+   }
+ 
+@@ -1770,18 +1766,17 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+     if ((attr = ippFindAttribute(job->attrs, "job-printer-uri",
+                                  IPP_TAG_URI)) == NULL)
+     {
+-      cupsdLogMessage(CUPSD_LOG_ERROR,
+-		      "[Job %d] No job-printer-uri attribute in control file.",
+-		      job->id);
++      cupsdLogJob(job, CUPSD_LOG_ERROR,
++		  "No job-printer-uri attribute in control file.");
+       goto error;
+     }
+ 
+     if ((dest = cupsdValidateDest(attr->values[0].string.text, &(job->dtype),
+                                   &destptr)) == NULL)
+     {
+-      cupsdLogMessage(CUPSD_LOG_ERROR,
+-		      "[Job %d] Unable to queue job for destination \"%s\".",
+-		      job->id, attr->values[0].string.text);
++      cupsdLogJob(job, CUPSD_LOG_ERROR,
++		  "Unable to queue job for destination \"%s\".",
++		  attr->values[0].string.text);
+       goto error;
+     }
+ 
+@@ -1789,9 +1784,9 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+   }
+   else if ((destptr = cupsdFindDest(job->dest)) == NULL)
+   {
+-    cupsdLogMessage(CUPSD_LOG_ERROR,
+-		    "[Job %d] Unable to queue job for destination \"%s\".",
+-		    job->id, job->dest);
++    cupsdLogJob(job, CUPSD_LOG_ERROR,
++		"Unable to queue job for destination \"%s\".",
++		job->dest);
+     goto error;
+   }
+ 
+@@ -1800,9 +1795,8 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+   {
+     const char	*reason;		/* job-state-reason keyword */
+ 
+-    cupsdLogMessage(CUPSD_LOG_DEBUG,
+-		    "[Job %d] Adding missing job-state-reasons attribute to "
+-		    " control file.", job->id);
++    cupsdLogJob(job, CUPSD_LOG_DEBUG,
++		"Adding missing job-state-reasons attribute to  control file.");
+ 
+     switch (job->state_value)
+     {
+@@ -1867,9 +1861,8 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+     if ((attr = ippFindAttribute(job->attrs, "job-priority",
+                         	 IPP_TAG_INTEGER)) == NULL)
+     {
+-      cupsdLogMessage(CUPSD_LOG_ERROR,
+-		      "[Job %d] Missing or bad job-priority attribute in "
+-		      "control file.", job->id);
++      cupsdLogJob(job, CUPSD_LOG_ERROR,
++		  "Missing or bad job-priority attribute in control file.");
+       goto error;
+     }
+ 
+@@ -1881,9 +1874,9 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+     if ((attr = ippFindAttribute(job->attrs, "job-originating-user-name",
+                         	 IPP_TAG_NAME)) == NULL)
+     {
+-      cupsdLogMessage(CUPSD_LOG_ERROR,
+-		      "[Job %d] Missing or bad job-originating-user-name "
+-		      "attribute in control file.", job->id);
++      cupsdLogJob(job, CUPSD_LOG_ERROR,
++		  "Missing or bad job-originating-user-name "
++		  "attribute in control file.");
+       goto error;
+     }
+ 
+@@ -1928,9 +1921,8 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+       if (access(jobfile, 0))
+         break;
+ 
+-      cupsdLogMessage(CUPSD_LOG_DEBUG,
+-		      "[Job %d] Auto-typing document file \"%s\"...", job->id,
+-		      jobfile);
++      cupsdLogJob(job, CUPSD_LOG_DEBUG,
++		  "Auto-typing document file \"%s\"...", jobfile);
+ 
+       if (fileid > job->num_files)
+       {
+@@ -1956,9 +1948,8 @@ cupsdLoadJob(cupsd_job_t *job)		/* I - J
+ 
+         if (!compressions || !filetypes)
+ 	{
+-          cupsdLogMessage(CUPSD_LOG_ERROR,
+-	                  "[Job %d] Ran out of memory for job file types.",
+-			  job->id);
++          cupsdLogJob(job, CUPSD_LOG_ERROR,
++		      "Ran out of memory for job file types.");
+ 
+ 	  ippDelete(job->attrs);
+ 	  job->attrs = NULL;
+@@ -2266,8 +2257,7 @@ cupsdSaveJob(cupsd_job_t *job)		/* I - J
+   if (ippWriteIO(fp, (ipp_iocb_t)cupsFileWrite, 1, NULL,
+                  job->attrs) != IPP_DATA)
+   {
+-    cupsdLogMessage(CUPSD_LOG_ERROR,
+-                    "[Job %d] Unable to write job control file.", job->id);
++    cupsdLogJob(job, CUPSD_LOG_ERROR, "Unable to write job control file.");
+     cupsFileClose(fp);
+     return;
+   }
+@@ -2944,15 +2934,15 @@ dump_job_history(cupsd_job_t *job)	/* I
+   snprintf(temp, sizeof(temp),
+            "[Job %d] The following messages were recorded from %s to %s",
+            job->id, start, end);
+-  cupsdWriteErrorLog(CUPSD_LOG_DEBUG, temp);
++  cupsdWriteErrorLogJob(job, CUPSD_LOG_DEBUG, temp);
+ 
+   for (message = (cupsd_joblog_t *)cupsArrayFirst(job->history);
+        message;
+        message = (cupsd_joblog_t *)cupsArrayNext(job->history))
+-    cupsdWriteErrorLog(CUPSD_LOG_DEBUG, message->message);
++    cupsdWriteErrorLogJob(job, CUPSD_LOG_DEBUG, message->message);
+ 
+   snprintf(temp, sizeof(temp), "[Job %d] End of messages", job->id);
+-  cupsdWriteErrorLog(CUPSD_LOG_DEBUG, temp);
++  cupsdWriteErrorLogJob(job, CUPSD_LOG_DEBUG, temp);
+ 
+  /*
+   * Log the printer state values...
+@@ -2968,11 +2958,11 @@ dump_job_history(cupsd_job_t *job)	/* I
+ 	     printer->state == IPP_PRINTER_IDLE ? "idle" :
+ 	         printer->state == IPP_PRINTER_PROCESSING ? "processing" :
+ 		 "stopped");
+-    cupsdWriteErrorLog(CUPSD_LOG_DEBUG, temp);
++    cupsdWriteErrorLogJob(job, CUPSD_LOG_DEBUG, temp);
+ 
+     snprintf(temp, sizeof(temp), "[Job %d] printer-state-message=\"%s\"",
+              job->id, printer->state_message);
+-    cupsdWriteErrorLog(CUPSD_LOG_DEBUG, temp);
++    cupsdWriteErrorLogJob(job, CUPSD_LOG_DEBUG, temp);
+ 
+     snprintf(temp, sizeof(temp), "[Job %d] printer-state-reasons=", job->id);
+     ptr = temp + strlen(temp);
+@@ -2991,7 +2981,7 @@ dump_job_history(cupsd_job_t *job)	/* I
+ 	ptr += strlen(ptr);
+       }
+     }
+-    cupsdWriteErrorLog(CUPSD_LOG_DEBUG, temp);
++    cupsdWriteErrorLogJob(job, CUPSD_LOG_DEBUG, temp);
+   }
+ 
+  /*
+@@ -4132,8 +4122,7 @@ load_job_cache(const char *filename)	/*
+       job->status_pipes[0] = -1;
+       job->status_pipes[1] = -1;
+ 
+-      cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] Loading from cache...",
+-                      job->id);
++      cupsdLogJob(job, CUPSD_LOG_DEBUG, "Loading from cache...");
+     }
+     else if (!job)
+     {
+@@ -4202,8 +4191,7 @@ load_job_cache(const char *filename)	/*
+ 	         job->id);
+         if (access(jobfile, 0))
+ 	{
+-	  cupsdLogMessage(CUPSD_LOG_INFO, "[Job %d] Data files have gone away.",
+-	                  job->id);
++	  cupsdLogJob(job, CUPSD_LOG_INFO, "Data files have gone away.");
+           job->num_files = 0;
+ 	  continue;
+ 	}
+@@ -4213,9 +4201,9 @@ load_job_cache(const char *filename)	/*
+ 
+         if (!job->filetypes || !job->compressions)
+ 	{
+-	  cupsdLogMessage(CUPSD_LOG_EMERG,
+-		          "[Job %d] Unable to allocate memory for %d files.",
+-		          job->id, job->num_files);
++	  cupsdLogJob(job, CUPSD_LOG_EMERG,
++		      "Unable to allocate memory for %d files.",
++		      job->num_files);
+           break;
+ 	}
+       }
+@@ -4253,9 +4241,9 @@ load_job_cache(const char *filename)	/*
+         * If the original MIME type is unknown, auto-type it!
+ 	*/
+ 
+-        cupsdLogMessage(CUPSD_LOG_ERROR,
+-		        "[Job %d] Unknown MIME type %s/%s for file %d.",
+-		        job->id, super, type, number + 1);
++        cupsdLogJob(job, CUPSD_LOG_ERROR,
++		    "Unknown MIME type %s/%s for file %d.",
++		    super, type, number + 1);
+ 
+         snprintf(jobfile, sizeof(jobfile), "%s/d%05d-%03d", RequestRoot,
+ 	         job->id, number + 1);
+@@ -4767,7 +4755,7 @@ unload_job(cupsd_job_t *job)		/* I - Job
+   if (!job->attrs)
+     return;
+ 
+-  cupsdLogMessage(CUPSD_LOG_DEBUG, "[Job %d] Unloading...", job->id);
++  cupsdLogJob(job, CUPSD_LOG_DEBUG, "Unloading...");
+ 
+   ippDelete(job->attrs);
+ 
+diff -up cups-1.7rc1/scheduler/log.c.journal cups-1.7rc1/scheduler/log.c
+--- cups-1.7rc1/scheduler/log.c.journal	2013-10-21 16:18:06.296038350 +0100
++++ cups-1.7rc1/scheduler/log.c	2013-10-21 16:31:07.826704189 +0100
+@@ -21,6 +21,7 @@
+  *   cupsdLogMessage()    - Log a message to the error log file.
+  *   cupsdLogPage()       - Log a page to the page log file.
+  *   cupsdLogRequest()    - Log an HTTP request in Common Log Format.
++ *   cupsdWriteErrorLogJob() - Write a job message to the ErrorLog.
+  *   cupsdWriteErrorLog() - Write a line to the ErrorLog.
+  *   format_log_line()    - Format a line for a log file.
+  */
+@@ -35,6 +36,9 @@
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <unistd.h>
++#ifdef HAVE_JOURNAL
++# include <systemd/sd-journal.h>
++#endif /* HAVE_JOURNAL */
+ 
+ 
+ /*
+@@ -558,8 +562,17 @@ cupsdLogJob(cupsd_job_t *job,		/* I - Jo
+     }
+     else if (level <= LogLevel &&
+              (level != CUPSD_LOG_INFO || LogLevel >= CUPSD_LOG_DEBUG))
+-      return (cupsdWriteErrorLog(level, log_line));
+-    else
++    {
++      if (!strcmp (ErrorLog, "journal"))
++#ifdef HAVE_JOURNAL
++	return (sd_journal_send ("MESSAGE=%s", log_line,
++				 "PRIORITY=%d", syslevels[level],
++				 "CUPS_JOB_ID=%d", job ? job->id : -1,
++				 NULL)) ? 0 : 1;
++      else
++#endif /* HAVE_JOURNAL */
++	return (cupsdWriteErrorLog(level, log_line));
++    } else
+       return (1);
+   }
+   else
+@@ -788,6 +801,15 @@ cupsdLogPage(cupsd_job_t *job,		/* I - J
+ 
+   *bufptr = '\0';
+ 
++#ifdef HAVE_JOURNAL
++  if (!strcmp(PageLog, "journal"))
++    return (sd_journal_send ("MESSAGE=%s", buffer,
++			     "PRIORITY=%d", LOG_INFO,
++			     "CUPS_JOB_ID=%d", job->id,
++			     "CUPS_PAGE_NUMBER=%d", number,
++			     NULL) ? 0 : 1);
++#endif /* HAVE_JOURNAL */
++
+ #ifdef HAVE_VSYSLOG
+  /*
+   * See if we are logging pages via syslog...
+@@ -963,7 +985,7 @@ cupsdLogRequest(cupsd_client_t *con,	/*
+   * See if we are logging accesses via syslog...
+   */
+ 
+-  if (!strcmp(AccessLog, "syslog"))
++  if (!strcmp(AccessLog, "syslog") || !strcmp(AccessLog, "journal"))
+   {
+     syslog(LOG_INFO,
+            "REQUEST %s - %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT " %s %s\n",
+@@ -1017,9 +1039,11 @@ cupsdLogRequest(cupsd_client_t *con,	/*
+  */
+ 
+ int					/* O - 1 on success, 0 on failure */
+-cupsdWriteErrorLog(int        level,	/* I - Log level */
+-                   const char *message)	/* I - Message string */
++cupsdWriteErrorLogJob(cupsd_job_t *job,	/* I - Job or NULL */
++		      int          level, /* I - Log level */
++		      const char  *message) /* I - Message string */
+ {
++  char			jobmsg[1024];	/* Format string for job message */
+   static const char	levels[] =	/* Log levels... */
+ 		{
+ 		  ' ',
+@@ -1035,12 +1059,26 @@ cupsdWriteErrorLog(int        level,	/*
+ 		};
+ 
+ 
++#ifdef HAVE_JOURNAL
++  if (!strcmp(ErrorLog, "journal"))
++  {
++    if (job)
++    {
++      snprintf(jobmsg, sizeof(jobmsg), "[Job %d] %s", job->id, message);
++      return (sd_journal_send ("MESSAGE=%s", jobmsg,
++			       "PRIORITY=%d", syslevels[level],
++			       "CUPS_JOB_ID=%d", job->id,
++			       NULL) ? 0 : 1);
++    } else
++      return (sd_journal_print (syslevels[level], message) ? 0 : 1);
++  }
++#endif /* HAVE_JOURNAL */
+ #ifdef HAVE_VSYSLOG
+  /*
+   * See if we are logging errors via syslog...
+   */
+ 
+-  if (!strcmp(ErrorLog, "syslog"))
++  if (!strcmp(ErrorLog, "syslog") || !strcmp(ErrorLog, "journal"))
+   {
+     syslog(syslevels[level], "%s", message);
+     return (1);
+@@ -1066,6 +1104,18 @@ cupsdWriteErrorLog(int        level,	/*
+ }
+ 
+ 
++/*
++ * 'cupsdWriteErrorLog()' - Write a line to the ErrorLog.
++ */
++
++int					/* O - 1 on success, 0 on failure */
++cupsdWriteErrorLog(int          level,	/* I - Log level */
++		   const char  *message) /* I - Message string */
++{
++  return (cupsdWriteErrorLogJob(NULL, level, message));
++}
++
++
+ /*
+  * 'format_log_line()' - Format a line for a log file.
+  *
diff --git a/cups.spec b/cups.spec
index 29017c1..4845f28 100644
--- a/cups.spec
+++ b/cups.spec
@@ -14,7 +14,7 @@ Summary: CUPS printing system
 Name: cups
 Epoch: 1
 Version: 1.7
-Release: 0.26.%{prever}%{?dist}
+Release: 0.27.%{prever}%{?dist}
 License: GPLv2
 Group: System Environment/Daemons
 Url: http://www.cups.org/
@@ -73,6 +73,7 @@ Patch40: cups-full-relro.patch
 Patch41: cups-web-devices-timeout.patch
 Patch42: cups-synconclose.patch
 Patch43: cups-final-content-type.patch
+Patch44: cups-journal.patch
 
 Patch100: cups-lspp.patch
 
@@ -272,6 +273,8 @@ Sends IPP requests to the specified URI and tests and/or displays the results.
 # Reverted upstream change to FINAL_CONTENT_TYPE in order to fix
 # printing to remote CUPS servers (bug #1010580).
 %patch43 -p1 -b .final-content-type
+# Allow "journal" log type for log output to system journal.
+%patch44 -p1 -b .journal
 
 %if %lspp
 # LSPP support.
@@ -646,6 +649,9 @@ rm -f %{cups_serverbin}/backend/smb
 %{_mandir}/man5/ipptoolfile.5.gz
 
 %changelog
+* Mon Oct 21 2013 Tim Waugh <twaugh at redhat.com> - 1:1.7-0.27.rc1
+- Allow "journal" log type for log output to system journal.
+
 * Fri Sep 27 2013 Tim Waugh <twaugh at redhat.com> - 1:1.7-0.26.rc1
 - Reverted upstream change to FINAL_CONTENT_TYPE in order to fix
   printing to remote CUPS servers (bug #1010580).


More information about the scm-commits mailing list