]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - scheduler/log.c
Fix source file header text duplication text duplication.
[thirdparty/cups.git] / scheduler / log.c
index fce8797c84b39b703ad5556bf996a133e45f7eef..243742d1720aff750a73fb1feac67a2d532bdf02 100644 (file)
@@ -1,16 +1,14 @@
 /*
- * "$Id$"
- *
  * Log file routines for the CUPS scheduler.
  *
- * Copyright 2007-2015 by Apple Inc.
+ * Copyright 2007-2016 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  * These coded instructions, statements, and computer programs are the
  * property of Apple Inc. and are protected by Federal copyright
  * law.  Distribution and use rights are outlined in the file "LICENSE.txt"
  * which should have been included with this file.  If this file is
- * file is missing or damaged, see the license at "http://www.cups.org/".
+ * missing or damaged, see the license at "http://www.cups.org/".
  */
 
 /*
@@ -227,20 +225,11 @@ cupsdCheckLogFile(cups_file_t **lf,       /* IO - Log file */
 
       if (*lf == NULL)
       {
-#ifdef HAVE_ASL_H
-       asl_object_t    m;              /* Log message */
-
-       m = asl_new(ASL_TYPE_MSG);
-       asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-       asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
-       asl_release(m);
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
         sd_journal_print(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
-
 #else
        syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
-#endif /* HAVE_ASL_H */
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
         if (FatalErrors & CUPSD_FATAL_LOG)
          cupsdEndProcess(getpid(), 0);
@@ -281,20 +270,12 @@ cupsdCheckLogFile(cups_file_t **lf,       /* IO - Log file */
 
     if ((*lf = cupsFileOpen(filename, "a")) == NULL)
     {
-#ifdef HAVE_ASL_H
-       asl_object_t    m;              /* Log message */
-
-       m = asl_new(ASL_TYPE_MSG);
-       asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-       asl_log(NULL, m, ASL_LEVEL_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
-       asl_release(m);
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
-        sd_journal_print(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
+      sd_journal_print(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
 
 #else
-       syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
-#endif /* HAVE_ASL_H */
+      syslog(LOG_ERR, "Unable to open log file \"%s\" - %s", filename, strerror(errno));
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
       if (FatalErrors & CUPSD_FATAL_LOG)
        cupsdEndProcess(getpid(), 0);
@@ -584,57 +565,10 @@ cupsdLogJob(cupsd_job_t *job,             /* I - Job */
   if (TestConfigFile || !ErrorLog)
     return (1);
 
-  if ((level > LogLevel ||
-       (level == CUPSD_LOG_INFO && LogLevel < CUPSD_LOG_DEBUG)) &&
-      LogDebugHistory <= 0)
+  if (level > LogLevel && LogDebugHistory <= 0)
     return (1);
 
-#ifdef HAVE_ASL_H
-  if (!strcmp(ErrorLog, "syslog"))
-  {
-    asl_object_t       m;              /* Log message */
-    char               job_id[32],     /* job-id string */
-                       completed[32];  /* job-impressions-completed string */
-    cupsd_printer_t *printer = job ? (job->printer ? job->printer : (job->dest ? cupsdFindDest(job->dest) : NULL)) : NULL;
-    static const char * const job_states[] =
-    {                                  /* job-state strings */
-      "Pending",
-      "PendingHeld",
-      "Processing",
-      "ProcessingStopped",
-      "Canceled",
-      "Aborted",
-      "Completed"
-    };
-
-    m = asl_new(ASL_TYPE_MSG);
-    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-    if (printer)
-      asl_set(m, PWG_ServiceURI, printer->uri);
-    if (job)
-    {
-      snprintf(job_id, sizeof(job_id), "%d", job->id);
-
-      asl_set(m, PWG_Event, "JobStateChanged");
-      asl_set(m, PWG_JobID, job_id);
-      asl_set(m, PWG_JobState, job->state_value < IPP_JSTATE_PENDING ? "" : job_states[job->state_value - IPP_JSTATE_PENDING]);
-
-      if (job->impressions)
-      {
-       snprintf(completed, sizeof(completed), "%d", ippGetInteger(job->impressions, 0));
-       asl_set(m, PWG_JobImpressionsCompleted, completed);
-      }
-    }
-
-    va_start(ap, message);
-    asl_vlog(NULL, m, log_levels[level], message, ap);
-    va_end(ap);
-
-    asl_release(m);
-    return (1);
-  }
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
   if (!strcmp(ErrorLog, "syslog"))
   {
     cupsd_printer_t *printer = job ? (job->printer ? job->printer : (job->dest ? cupsdFindDest(job->dest) : NULL)) : NULL;
@@ -677,7 +611,7 @@ cupsdLogJob(cupsd_job_t *job,               /* I - Job */
 
     return (1);
   }
-#endif /* HAVE_ASL_H */
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
  /*
   * Format and write the log message...
@@ -702,10 +636,7 @@ cupsdLogJob(cupsd_job_t *job,              /* I - Job */
 
   if (status > 0)
   {
-    if (job &&
-        (level > LogLevel ||
-         (level == CUPSD_LOG_INFO && LogLevel < CUPSD_LOG_DEBUG)) &&
-       LogDebugHistory > 0)
+    if (job && level > LogLevel && LogDebugHistory > 0)
     {
      /*
       * Add message to the job history...
@@ -744,8 +675,7 @@ cupsdLogJob(cupsd_job_t *job,               /* I - Job */
 
       return (1);
     }
-    else if (level <= LogLevel &&
-             (level != CUPSD_LOG_INFO || LogLevel >= CUPSD_LOG_DEBUG))
+    else if (level <= LogLevel)
       return (cupsdWriteErrorLog(level, log_line));
     else
       return (1);
@@ -777,15 +707,7 @@ cupsdLogMessage(int        level,  /* I - Log level */
   {
     va_start(ap, message);
 
-#ifdef HAVE_ASL_H
-    asl_object_t       m;              /* Log message */
-
-    m = asl_new(ASL_TYPE_MSG);
-    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-    asl_vlog(NULL, m, log_levels[level], message, ap);
-    asl_release(m);
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
     sd_journal_printv(log_levels[level], message, ap);
 
 #elif defined(HAVE_VSYSLOG)
@@ -794,7 +716,7 @@ cupsdLogMessage(int        level,   /* I - Log level */
 #else
     vfprintf(stderr, message, ap);
     putc('\n', stderr);
-#endif /* HAVE_VSYSLOG */
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
     va_end(ap);
 
@@ -804,23 +726,7 @@ cupsdLogMessage(int        level,  /* I - Log level */
   if (level > LogLevel || !ErrorLog)
     return (1);
 
-#ifdef HAVE_ASL_H
-  if (!strcmp(ErrorLog, "syslog"))
-  {
-    asl_object_t       m;              /* Log message */
-
-    m = asl_new(ASL_TYPE_MSG);
-    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-
-    va_start(ap, message);
-    asl_vlog(NULL, m, log_levels[level], message, ap);
-    va_end(ap);
-
-    asl_release(m);
-    return (1);
-  }
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
   if (!strcmp(ErrorLog, "syslog"))
   {
     va_start(ap, message);
@@ -828,7 +734,7 @@ cupsdLogMessage(int        level,   /* I - Log level */
     va_end(ap);
     return (1);
   }
-#endif /* HAVE_ASL_H */
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
  /*
   * Format and write the log message...
@@ -1043,45 +949,7 @@ cupsdLogPage(cupsd_job_t *job,            /* I - Job being printed */
 
   *bufptr = '\0';
 
-#ifdef HAVE_ASL_H
-  if (!strcmp(ErrorLog, "syslog"))
-  {
-    asl_object_t       m;              /* Log message */
-    char               job_id[32],     /* job-id string */
-                       completed[32];  /* job-impressions-completed string */
-    static const char * const job_states[] =
-    {                                  /* job-state strings */
-      "Pending",
-      "PendingHeld",
-      "Processing",
-      "ProcessingStopped",
-      "Canceled",
-      "Aborted",
-      "Completed"
-    };
-
-    snprintf(job_id, sizeof(job_id), "%d", job->id);
-
-    m = asl_new(ASL_TYPE_MSG);
-    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-    asl_set(m, PWG_Event, "JobStateChanged");
-    asl_set(m, PWG_ServiceURI, job->printer->uri);
-    asl_set(m, PWG_JobID, job_id);
-    asl_set(m, PWG_JobState, job_states[job->state_value - IPP_JSTATE_PENDING]);
-
-    if (job->impressions)
-    {
-      snprintf(completed, sizeof(completed), "%d", ippGetInteger(job->impressions, 0));
-      asl_set(m, PWG_JobImpressionsCompleted, completed);
-    }
-
-    asl_log(NULL, m, ASL_LEVEL_INFO, "%s", buffer);
-
-    asl_release(m);
-    return (1);
-  }
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
   if (!strcmp(ErrorLog, "syslog"))
   {
     static const char * const job_states[] =
@@ -1117,7 +985,7 @@ cupsdLogPage(cupsd_job_t *job,             /* I - Job being printed */
 
     return (1);
   }
-#endif /* HAVE_ASL_H */
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
  /*
   * Not using syslog; check the log file...
@@ -1278,29 +1146,7 @@ cupsdLogRequest(cupsd_client_t *con,     /* I - Request to log */
     }
   }
 
-#ifdef HAVE_ASL_H
-  if (!strcmp(ErrorLog, "syslog"))
-  {
-    asl_object_t       m;              /* Log message */
-
-    m = asl_new(ASL_TYPE_MSG);
-    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-
-    asl_log(NULL, m, ASL_LEVEL_INFO, "REQUEST %s - %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT " %s %s\n",
-           con->http->hostname, con->username[0] != '\0' ? con->username : "-",
-          states[con->operation], _httpEncodeURI(temp, con->uri, sizeof(temp)),
-          con->http->version / 100, con->http->version % 100,
-          code, CUPS_LLCAST con->bytes,
-          con->request ?
-              ippOpString(con->request->request.op.operation_id) : "-",
-          con->response ?
-              ippErrorString(con->response->request.status.status_code) : "-");
-
-    asl_release(m);
-    return (1);
-  }
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
   if (!strcmp(ErrorLog, "syslog"))
   {
     sd_journal_print(LOG_INFO, "REQUEST %s - %s \"%s %s HTTP/%d.%d\" %d " CUPS_LLFMT " %s %s", con->http->hostname, con->username[0] != '\0' ? con->username : "-", states[con->operation], _httpEncodeURI(temp, con->uri, sizeof(temp)), con->http->version / 100, con->http->version % 100, code, CUPS_LLCAST con->bytes, con->request ? ippOpString(con->request->request.op.operation_id) : "-", con->response ? ippErrorString(con->response->request.status.status_code) : "-");
@@ -1327,7 +1173,7 @@ cupsdLogRequest(cupsd_client_t *con,      /* I - Request to log */
 
     return (1);
   }
-#endif /* HAVE_ASL_H */
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
  /*
   * Not using syslog; check the log file...
@@ -1385,20 +1231,7 @@ cupsdWriteErrorLog(int        level,     /* I - Log level */
                };
 
 
-#ifdef HAVE_ASL_H
-  if (!strcmp(ErrorLog, "syslog"))
-  {
-    asl_object_t       m;              /* Log message */
-
-    m = asl_new(ASL_TYPE_MSG);
-    asl_set(m, ASL_KEY_FACILITY, "org.cups.cupsd");
-    asl_log(NULL, m, ASL_LEVEL_INFO, "%s", message);
-
-    asl_release(m);
-    return (1);
-  }
-
-#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#ifdef HAVE_SYSTEMD_SD_JOURNAL_H
   if (!strcmp(ErrorLog, "syslog"))
   {
     sd_journal_print(log_levels[level], "%s", message);
@@ -1415,7 +1248,7 @@ cupsdWriteErrorLog(int        level,      /* I - Log level */
     syslog(log_levels[level], "%s", message);
     return (1);
   }
-#endif /* HAVE_ASL_H */
+#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
 
  /*
   * Not using syslog; check the log file...
@@ -1476,7 +1309,7 @@ format_log_line(const char *message,      /* I - Printf-style format string */
   * Format the log message...
   */
 
-  len = vsnprintf(log_line, log_linesize, message, ap);
+  len = _cups_safe_vsnprintf(log_line, log_linesize, message, ap);
 
  /*
   * Resize the buffer as needed...
@@ -1486,7 +1319,6 @@ format_log_line(const char *message,      /* I - Printf-style format string */
   {
     char       *temp;                  /* Temporary string pointer */
 
-
     len ++;
 
     if (len < 8192)
@@ -1507,8 +1339,3 @@ format_log_line(const char *message,      /* I - Printf-style format string */
 
   return (1);
 }
-
-
-/*
- * End of "$Id$".
- */