]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add support for logging to stderr (STR #4505)
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 3 Jun 2015 19:49:54 +0000 (19:49 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Wed, 3 Jun 2015 19:49:54 +0000 (19:49 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@12689 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES.txt
scheduler/conf.c
scheduler/conf.h
scheduler/log.c
scheduler/main.c
scheduler/server.c

index f4f6c4aa6c8c3b57c97ca83c71e66d93e16ab5c0..11d5bdd2e0ecb5e5820eef15b20f84f0e33293c5 100644 (file)
@@ -37,3 +37,5 @@ CHANGES IN CUPS V2.1b1
          (STR #4630)
        - The scheduler now supports advanced ASL and journald logging when
          "syslog" output is configured (STR #4474)
+       - The scheduler now supports logging to stderr when running in the
+         foreground (STR #4505)
index a58de4204b019058d3dfeb95c3875146589f3b6d..8c61870d827d36efd63a025fd692634200e2c2b5 100644 (file)
 #include <stdarg.h>
 #include <grp.h>
 #include <sys/utsname.h>
+#ifdef HAVE_ASL_H
+#  include <asl.h>
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#  define SD_JOURNAL_SUPPRESS_LOCATION
+#  include <systemd/sd-journal.h>
+#endif /* HAVE_ASL_H */
 #include <syslog.h>
 
 #ifdef HAVE_LIBPAPER
@@ -269,8 +275,20 @@ cupsdCheckPermissions(
                          "Unable to create directory \"%s\" - %s", filename,
                          strerror(errno));
         else
-         syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename,
-                strerror(errno));
+#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 create directory \"%s\" - %s", filename, strerror(errno));
+         asl_release(m);
+       }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+         sd_journal_print(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
+#else
+         syslog(LOG_ERR, "Unable to create directory \"%s\" - %s", filename, strerror(errno));
+#endif /* HAVE_ASL_H */
 
         return (-1);
       }
@@ -307,7 +325,20 @@ cupsdCheckPermissions(
     if (create_dir >= 0)
       cupsdLogMessage(CUPSD_LOG_ERROR, "\"%s\" is not a directory.", filename);
     else
+#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, "\"%s\" is not a directory.", filename);
+      asl_release(m);
+    }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+      sd_journal_print(LOG_ERR, "\"%s\" is not a directory.", filename);
+#else
       syslog(LOG_ERR, "\"%s\" is not a directory.", filename);
+#endif /* HAVE_ASL_H */
 
     return (-1);
   }
@@ -336,8 +367,20 @@ cupsdCheckPermissions(
                        "Unable to change ownership of \"%s\" - %s", filename,
                        strerror(errno));
       else
-       syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename,
-              strerror(errno));
+#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 change ownership of \"%s\" - %s", filename, strerror(errno));
+       asl_release(m);
+      }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+       sd_journal_print(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
+#else
+       syslog(LOG_ERR, "Unable to change ownership of \"%s\" - %s", filename, strerror(errno));
+#endif /* HAVE_ASL_H */
 
       return (1);
     }
@@ -356,8 +399,20 @@ cupsdCheckPermissions(
                        "Unable to change permissions of \"%s\" - %s", filename,
                        strerror(errno));
       else
-       syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename,
-              strerror(errno));
+#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 change permissions of \"%s\" - %s", filename, strerror(errno));
+       asl_release(m);
+      }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+       sd_journal_print(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
+#else
+       syslog(LOG_ERR, "Unable to change permissions of \"%s\" - %s", filename, strerror(errno));
+#endif /* HAVE_ASL_H */
 
       return (1);
     }
@@ -782,8 +837,20 @@ cupsdReadConfiguration(void)
       if (TestConfigFile)
         printf("\"%s\" contains errors.\n", CupsFilesFile);
       else
-        syslog(LOG_LPR, "Unable to read \"%s\" due to errors.",
-               CupsFilesFile);
+#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 read \"%s\" due to errors.", CupsFilesFile);
+       asl_release(m);
+      }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+       sd_journal_print(LOG_ERR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
+#else
+        syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", CupsFilesFile);
+#endif /* HAVE_ASL_H */
 
       return (0);
     }
@@ -792,8 +859,20 @@ cupsdReadConfiguration(void)
     cupsdLogMessage(CUPSD_LOG_INFO, "No %s, using defaults.", CupsFilesFile);
   else
   {
-    syslog(LOG_LPR, "Unable to open \"%s\": %s", CupsFilesFile,
-          strerror(errno));
+#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 \"%s\" - %s", CupsFilesFile, strerror(errno));
+    asl_release(m);
+
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+    sd_journal_print(LOG_ERR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
+#else
+    syslog(LOG_LPR, "Unable to open \"%s\" - %s", CupsFilesFile, strerror(errno));
+#endif /* HAVE_ASL_H */
+
     return (0);
   }
 
@@ -806,8 +885,19 @@ cupsdReadConfiguration(void)
 
   if ((fp = cupsFileOpen(ConfigurationFile, "r")) == NULL)
   {
-    syslog(LOG_LPR, "Unable to open \"%s\": %s", ConfigurationFile,
-          strerror(errno));
+#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 \"%s\" - %s", ConfigurationFile, strerror(errno));
+    asl_release(m);
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+    sd_journal_print(LOG_ERR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
+#else
+    syslog(LOG_LPR, "Unable to open \"%s\" - %s", ConfigurationFile, strerror(errno));
+#endif /* HAVE_ASL_H */
+
     return (0);
   }
 
@@ -820,8 +910,20 @@ cupsdReadConfiguration(void)
     if (TestConfigFile)
       printf("\"%s\" contains errors.\n", ConfigurationFile);
     else
-      syslog(LOG_LPR, "Unable to read \"%s\" due to errors.",
-            ConfigurationFile);
+#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 read \"%s\" due to errors.", ConfigurationFile);
+      asl_release(m);
+    }
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+      sd_journal_print(LOG_ERR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
+#else
+      syslog(LOG_LPR, "Unable to read \"%s\" due to errors.", ConfigurationFile);
+#endif /* HAVE_ASL_H */
 
     return (0);
   }
@@ -948,12 +1050,24 @@ cupsdReadConfiguration(void)
   * Open the system log for cupsd if necessary...
   */
 
-#ifdef HAVE_VSYSLOG
+  if (!LogStderr)
+  {
+    if (!strcmp(AccessLog, "stderr"))
+      cupsdSetString(&AccessLog, "syslog");
+
+    if (!strcmp(ErrorLog, "stderr"))
+      cupsdSetString(&ErrorLog, "syslog");
+
+    if (!strcmp(PageLog, "stderr"))
+      cupsdSetString(&PageLog, "syslog");
+  }
+
+#if defined(HAVE_VSYSLOG) && !defined(HAVE_ASL_H) && !defined(HAVE_SYSTEMD_SD_JOURNAL_H)
   if (!strcmp(AccessLog, "syslog") ||
       !strcmp(ErrorLog, "syslog") ||
       !strcmp(PageLog, "syslog"))
     openlog("cupsd", LOG_PID | LOG_NOWAIT | LOG_NDELAY, LOG_LPR);
-#endif /* HAVE_VSYSLOG */
+#endif /* HAVE_VSYSLOG && !HAVE_ASL_H && !HAVE_SYSTEMD_SD_JOURNAL_H */
 
  /*
   * Make sure each of the log files exists and gets rotated as necessary...
index dd69bdf7368b5ae9d204fa2f7fbc5326ab36641d..714fb4e90f1eceea06bf338b4ae7a7ce31f444b5 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Configuration file definitions for the CUPS scheduler.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2015 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  * These coded instructions, statements, and computer programs are the
@@ -182,6 +182,8 @@ VAR cupsd_loglevel_t        LogLevel                VALUE(CUPSD_LOG_WARN);
                                        /* Error log level */
 VAR cupsd_time_t       LogTimeFormat           VALUE(CUPSD_TIME_STANDARD);
                                        /* Log file time format */
+VAR cups_file_t                *LogStderr              VALUE(NULL);
+                                       /* Stderr file, if any */
 VAR cupsd_sandboxing_t Sandboxing              VALUE(CUPSD_SANDBOXING_STRICT);
                                        /* Sandboxing level */
 VAR int                        UseSandboxing   VALUE(1);
index 5ade44aa3159eb021f0cdcd8d6bf72585a4d80a7..ac229e380c190e72cc222c5125040b42f5c2dc55 100644 (file)
@@ -124,6 +124,16 @@ cupsdCheckLogFile(cups_file_t **lf,        /* IO - Log file */
   if (!lf || !logname || !logname[0])
     return (1);
 
+ /*
+  * Handle logging to stderr...
+  */
+
+  if (!strcmp(logname, "stderr"))
+  {
+    *lf = LogStderr;
+    return (1);
+  }
+
  /*
   * Format the filename as needed...
   */
index 64675e77068610981e46c41a07fb9c1a08406cca..d5015aa4d770348db0ef1f7c73617d788d5470ce 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Main loop for the CUPS scheduler.
  *
- * Copyright 2007-2014 by Apple Inc.
+ * Copyright 2007-2015 by Apple Inc.
  * Copyright 1997-2007 by Easy Software Products, all rights reserved.
  *
  * These coded instructions, statements, and computer programs are the
 #define _MAIN_C_
 #include "cupsd.h"
 #include <sys/resource.h>
+#ifdef HAVE_ASL_H
+#  include <asl.h>
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+#  define SD_JOURNAL_SUPPRESS_LOCATION
+#  include <systemd/sd-journal.h>
+#endif /* HAVE_ASL_H */
 #include <syslog.h>
 #include <grp.h>
 
@@ -396,6 +402,8 @@ main(int  argc,                             /* I - Number of command-line args */
       close(i);
     }
   }
+  else
+    LogStderr = cupsFileStderr();
 
  /*
   * Run in the background as needed...
@@ -728,8 +736,19 @@ main(int  argc,                            /* I - Number of command-line args */
 
         if (!cupsdReadConfiguration())
         {
-          syslog(LOG_LPR, "Unable to read configuration file \'%s\' - exiting!",
-                ConfigurationFile);
+#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 read configuration file \"%s\" - exiting.", ConfigurationFile);
+         asl_release(m);
+#elif defined(HAVE_SYSTEMD_SD_JOURNAL_H)
+         sd_journal_print(LOG_ERR, "Unable to read configuration file \"%s\" - exiting.", ConfigurationFile);
+#else
+          syslog(LOG_LPR, "Unable to read configuration file \'%s\' - exiting.", ConfigurationFile);
+#endif /* HAVE_ASL_H */
+
           break;
        }
 
index a83e7c40d3d288f24719b14bcf3cdd0800764bfc..e53a5c11f494597eac16f8780920e4b2a8be4a8d 100644 (file)
@@ -142,21 +142,24 @@ cupsdStopServer(void)
 
   if (AccessFile != NULL)
   {
-    cupsFileClose(AccessFile);
+    if (AccessFile != LogStderr)
+      cupsFileClose(AccessFile);
 
     AccessFile = NULL;
   }
 
   if (ErrorFile != NULL)
   {
-    cupsFileClose(ErrorFile);
+    if (ErrorFile != LogStderr)
+      cupsFileClose(ErrorFile);
 
     ErrorFile = NULL;
   }
 
   if (PageFile != NULL)
   {
-    cupsFileClose(PageFile);
+    if (PageFile != LogStderr)
+      cupsFileClose(PageFile);
 
     PageFile = NULL;
   }