Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No way of logging to stdout/stderr when run with -f #4505

Closed
michaelrsweet opened this issue Oct 21, 2014 · 3 comments
Closed

No way of logging to stdout/stderr when run with -f #4505

michaelrsweet opened this issue Oct 21, 2014 · 3 comments
Labels
enhancement New feature or request
Milestone

Comments

@michaelrsweet
Copy link
Collaborator

Version: 2.1-feature
CUPS.org User: twaugh.redhat

When running 'cupsd -f', there is no way of having e.g. ErrorLog output sent to stderr.

The straightforward approach of putting "ErrorLog /dev/stderr" in /etc/cups/cups-files.conf fails, at least on Linux, because /dev/stderr is a symlink (-> /proc/self/fd/2 -> /dev/pts/...) and opening symlinks is disallowed.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

OK, moving this to 2.1-feature; I'll look into adding a command-line argument to override specific cups-files.conf/cupsd.conf directives, and support stdout/stderr as values for the *Log directives.

@michaelrsweet
Copy link
Collaborator Author

CUPS.org User: mike

Fixed in Subversion repository.

@michaelrsweet
Copy link
Collaborator Author

"str4505.patch":

Index: scheduler/conf.c

--- scheduler/conf.c (revision 12688)
+++ scheduler/conf.c (working copy)
@@ -21,6 +21,12 @@
#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,9 +275,21 @@
"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 @@
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,9 +367,21 @@
    "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,9 +399,21 @@
    "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,9 +837,21 @@
    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 @@
    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 @@

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,9 +910,21 @@
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 @@

  • 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: scheduler/conf.h

    --- scheduler/conf.h (revision 12688)
    +++ scheduler/conf.h (working copy)
    @@ -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 @@
      /* 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: scheduler/log.c

    --- scheduler/log.c (revision 12688)
    +++ scheduler/log.c (working copy)
    @@ -125,6 +125,16 @@
    return (1);

    /*

  • * Handle logging to stderr...

  • */

  • if (!strcmp(logname, "stderr"))
  • {
  • *lf = LogStderr;
  • return (1);
  • }
  • /*
    • Format the filename as needed...
      */

Index: scheduler/main.c

--- scheduler/main.c (revision 12688)
+++ scheduler/main.c (working copy)
@@ -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
    @@ -20,6 +20,12 @@
    #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 @@
close(i);
}
}

  • else
  • LogStderr = cupsFileStderr();

/*

  • Run in the background as needed...
    @@ -728,8 +736,19 @@

    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: scheduler/server.c

--- scheduler/server.c (revision 12688)
+++ scheduler/server.c (working copy)
@@ -142,21 +142,24 @@

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;
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant