diff options
author | Jakub Hrozek <jhrozek@redhat.com> | 2009-09-25 13:20:13 +0200 |
---|---|---|
committer | Stephen Gallagher <sgallagh@redhat.com> | 2009-09-25 10:19:56 -0400 |
commit | 05315b44feaa9819e62f18477f2c6d20914eb7ce (patch) | |
tree | 82e28792e306de9e461ea9dde5203d6a3a9de7fa /server | |
parent | 6cec00b7fe2aed71b8df21d2a0d97df8b448cc85 (diff) | |
download | sssd-05315b44feaa9819e62f18477f2c6d20914eb7ce.tar.gz sssd-05315b44feaa9819e62f18477f2c6d20914eb7ce.tar.bz2 sssd-05315b44feaa9819e62f18477f2c6d20914eb7ce.zip |
Send debug messages to logfile
Introduces a new option --debug-to-files which makes SSSD output its
debug information to a file instead of stderr, which is still the
default.
Also introduces a new confdb option debug_to_files which does the same,
but can be specified per-service in the config file.
The logfiles are stored in /var/log/sssd by default.
Changes the initscript to log to files by default.
Diffstat (limited to 'server')
-rw-r--r-- | server/Makefile.am | 4 | ||||
-rw-r--r-- | server/conf_macros.m4 | 17 | ||||
-rw-r--r-- | server/confdb/confdb.h | 1 | ||||
-rw-r--r-- | server/configure.ac | 1 | ||||
-rw-r--r-- | server/man/sssd.8.xml | 12 | ||||
-rw-r--r-- | server/monitor/monitor.c | 18 | ||||
-rw-r--r-- | server/providers/data_provider.c | 4 | ||||
-rw-r--r-- | server/providers/data_provider_be.c | 4 | ||||
-rw-r--r-- | server/responder/nss/nsssrv.c | 4 | ||||
-rw-r--r-- | server/responder/pam/pamsrv.c | 4 | ||||
-rw-r--r-- | server/sysv/sssd | 2 | ||||
-rw-r--r-- | server/util/debug.c | 37 | ||||
-rw-r--r-- | server/util/server.c | 26 | ||||
-rw-r--r-- | server/util/util.h | 5 |
14 files changed, 128 insertions, 11 deletions
diff --git a/server/Makefile.am b/server/Makefile.am index a5555204..f43cf188 100644 --- a/server/Makefile.am +++ b/server/Makefile.am @@ -20,7 +20,7 @@ pluginpath = @pluginpath@ pidpath = @pidpath@ pipepath = @pipepath@ initdir = @initdir@ -shadow_utils_path = @shadow_utils_path@ +logpath = @logpath@ AM_CFLAGS = if WANT_AUX_INFO @@ -555,7 +555,7 @@ installsssddirs:: $(DESTDIR)$(dbpath) \ $(DESTDIR)$(pidpath) \ $(DESTDIR)$(initdir) \ - $(DESTDIR)$(shadow_utils_path) + $(DESTDIR)$(logpath) install-exec-hook: installsssddirs diff --git a/server/conf_macros.m4 b/server/conf_macros.m4 index 9ab2003e..410914e7 100644 --- a/server/conf_macros.m4 +++ b/server/conf_macros.m4 @@ -49,6 +49,23 @@ AC_DEFUN([WITH_PID_PATH], AC_DEFINE_UNQUOTED(PID_PATH, "$config_pidpath", [Where to store pid files for the SSSD]) ]) +AC_DEFUN([WITH_LOG_PATH], + [ AC_ARG_WITH([log-path], + [AC_HELP_STRING([--with-log-path=PATH], + [Where to store log files for the SSSD [/var/log/sssd]] + ) + ] + ) + config_logpath="\"VARDIR\"/log/sssd" + logpath="${localstatedir}/log/sssd" + if test x"$with_log_path" != x; then + config_logpath=$with_log_path + logpath=$with_log_path + fi + AC_SUBST(logpath) + AC_DEFINE_UNQUOTED(LOG_PATH, "$config_logpath", [Where to store log files for the SSSD]) + ]) + AC_DEFUN([WITH_PIPE_PATH], [ AC_ARG_WITH([pipe-path], [AC_HELP_STRING([--with-pipe-path=PATH], diff --git a/server/confdb/confdb.h b/server/confdb/confdb.h index 7ca85507..eef9a260 100644 --- a/server/confdb/confdb.h +++ b/server/confdb/confdb.h @@ -41,6 +41,7 @@ #define CONFDB_SERVICE_COMMAND "command" #define CONFDB_SERVICE_DEBUG_LEVEL "debug_level" #define CONFDB_SERVICE_DEBUG_TIMESTAMPS "debug_timestamps" +#define CONFDB_SERVICE_DEBUG_TO_FILES "debug_to_files" #define CONFDB_SERVICE_TIMEOUT "timeout" #define CONFDB_SERVICE_RECON_RETRIES "reconnection_retries" diff --git a/server/configure.ac b/server/configure.ac index 03d2885a..31dd87d8 100644 --- a/server/configure.ac +++ b/server/configure.ac @@ -42,6 +42,7 @@ m4_include(conf_macros.m4) WITH_DB_PATH WITH_PLUGIN_PATH WITH_PID_PATH +WITH_LOG_PATH WITH_PIPE_PATH WITH_INIT_DIR WITH_SHADOW_UTILS_PATH diff --git a/server/man/sssd.8.xml b/server/man/sssd.8.xml index f6f71c6c..880cf769 100644 --- a/server/man/sssd.8.xml +++ b/server/man/sssd.8.xml @@ -56,6 +56,18 @@ </varlistentry> <varlistentry> <term> + <option>-f</option>,<option>--debug-to-files</option> + </term> + <listitem> + <para> + Send the debug output to files instead of stderr. By default, the + log files are stored in <filename>/var/log/sssd</filename> and + there are separate log files for every SSSD service and domain. + </para> + </listitem> + </varlistentry> + <varlistentry> + <term> <option>-D</option>,<option>--daemon</option> </term> <listitem> diff --git a/server/monitor/monitor.c b/server/monitor/monitor.c index b78a768c..9972397e 100644 --- a/server/monitor/monitor.c +++ b/server/monitor/monitor.c @@ -938,11 +938,13 @@ static int get_service_config(struct mt_ctx *ctx, const char *name, } if (!svc->command) { - svc->command = talloc_asprintf(svc, "%s/sssd_%s -d %d%s", + svc->command = talloc_asprintf(svc, "%s/sssd_%s -d %d%s%s", SSSD_LIBEXEC_PATH, svc->name, debug_level, (debug_timestamps? - " --debug-timestamps":"")); + " --debug-timestamps":""), + (debug_to_file ? + " --debug-to-files":"")); if (!svc->command) { talloc_free(svc); return ENOMEM; @@ -1053,9 +1055,10 @@ static int get_provider_config(struct mt_ctx *ctx, const char *name, /* if there are no custom commands, build a default one */ if (!svc->command) { svc->command = talloc_asprintf(svc, - "%s/sssd_be -d %d%s --domain %s", + "%s/sssd_be -d %d%s%s --domain %s", SSSD_LIBEXEC_PATH, debug_level, (debug_timestamps?" --debug-timestamps":""), + (debug_to_file?" --debug-to-files":""), svc->name); if (!svc->command) { talloc_free(svc); @@ -2427,6 +2430,15 @@ int main(int argc, const char *argv[]) /* we want a pid file check */ flags |= FLAGS_PID_FILE; + /* Open before server_setup() does to have logging + * during configuration checking */ + if (debug_to_file) { + ret = open_debug_file(); + if (ret) { + return 7; + } + } + /* Parse config file, fail if cannot be done */ ret = load_configuration(tmp_ctx, config_file, &monitor); if (ret != EOK) return 4; diff --git a/server/providers/data_provider.c b/server/providers/data_provider.c index f727c555..0838cd02 100644 --- a/server/providers/data_provider.c +++ b/server/providers/data_provider.c @@ -992,7 +992,9 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); - /* set up things like debug , signals, daemonization, etc... */ + /* set up things like debug, signals, daemonization, etc... */ + debug_log_file = "sssd_dp"; + ret = server_setup("sssd[dp]", 0, CONFDB_DP_CONF_ENTRY, &main_ctx); if (ret != EOK) return 2; diff --git a/server/providers/data_provider_be.c b/server/providers/data_provider_be.c index 62ce7bbe..29d6fa0e 100644 --- a/server/providers/data_provider_be.c +++ b/server/providers/data_provider_be.c @@ -947,7 +947,11 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); + /* set up things like debug , signals, daemonization, etc... */ + debug_log_file = talloc_asprintf(NULL, "sssd_%s", be_domain); + if (!debug_log_file) return 2; + srv_name = talloc_asprintf(NULL, "sssd[be[%s]]", be_domain); if (!srv_name) return 2; diff --git a/server/responder/nss/nsssrv.c b/server/responder/nss/nsssrv.c index e000dfa1..6cdd19a9 100644 --- a/server/responder/nss/nsssrv.c +++ b/server/responder/nss/nsssrv.c @@ -353,7 +353,9 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); - /* set up things like debug , signals, daemonization, etc... */ + /* set up things like debug, signals, daemonization, etc... */ + debug_log_file = "sssd_nss"; + ret = server_setup("sssd[nss]", 0, CONFDB_NSS_CONF_ENTRY, &main_ctx); if (ret != EOK) return 2; diff --git a/server/responder/pam/pamsrv.c b/server/responder/pam/pamsrv.c index 50acc26c..dbc8ec12 100644 --- a/server/responder/pam/pamsrv.c +++ b/server/responder/pam/pamsrv.c @@ -190,7 +190,9 @@ int main(int argc, const char *argv[]) poptFreeContext(pc); - /* set up things like debug , signals, daemonization, etc... */ + /* set up things like debug, signals, daemonization, etc... */ + debug_log_file = "sssd_pam"; + ret = server_setup("sssd[pam]", 0, CONFDB_PAM_CONF_ENTRY, &main_ctx); if (ret != EOK) return 2; diff --git a/server/sysv/sssd b/server/sysv/sssd index 13854016..6ef7862c 100644 --- a/server/sysv/sssd +++ b/server/sysv/sssd @@ -38,7 +38,7 @@ PID_FILE=/var/run/sssd.pid start() { [ -x $SSSD ] || exit 5 echo -n $"Starting $prog: " - daemon $SSSD -D 2>/dev/null && success || failure + daemon $SSSD -f -D && success || failure RETVAL=$? echo [ "$RETVAL" = 0 ] && touch $LOCK_FILE diff --git a/server/util/debug.c b/server/util/debug.c index a7b3a091..c6aa27c9 100644 --- a/server/util/debug.c +++ b/server/util/debug.c @@ -24,12 +24,19 @@ #include <stdarg.h> #include <stdlib.h> +#include <sys/types.h> +#include <sys/stat.h> + #include "util/util.h" const char *debug_prg_name = "sssd"; int debug_level = 0; int debug_timestamps = 0; +int debug_to_file = 0; +const char *debug_log_file = "sssd"; +FILE *debug_file = NULL; + void debug_fn(const char *format, ...) { va_list ap; @@ -47,7 +54,8 @@ void debug_fn(const char *format, ...) va_end(ap); /*write(state.fd, s, strlen(s));*/ - fprintf(stderr, s); + fprintf(debug_file ? debug_file : stderr, s); + fflush(debug_file ? debug_file : stderr); free(s); } @@ -90,3 +98,30 @@ void ldb_debug_messages(void *context, enum ldb_debug_level level, } free(message); } + +int open_debug_file() +{ + FILE *f = NULL; + char *logpath; + mode_t old_umask; + int ret; + + ret = asprintf(&logpath, "%s/%s.log", LOG_PATH, debug_log_file); + if (ret == -1) { + return ENOMEM; + } + + if (debug_file) fclose(debug_file); + + old_umask = umask(0177); + f = fopen(logpath, "a"); + if (f == NULL) { + free(logpath); + return EIO; + } + umask(old_umask); + + debug_file = f; + free(logpath); + return EOK; +} diff --git a/server/util/server.c b/server/util/server.c index a8c50240..e8daf87c 100644 --- a/server/util/server.c +++ b/server/util/server.c @@ -298,6 +298,7 @@ int server_setup(const char *name, int flags, char *conf_db; int ret = EOK; bool dt; + bool dl; debug_prg_name = strdup(name); if (!debug_prg_name) { @@ -352,7 +353,6 @@ int server_setup(const char *name, int flags, DEBUG(0,("Out of memory, aborting!\n")); return ENOMEM; } - DEBUG(3, ("CONFDB: %s\n", conf_db)); ret = confdb_init(ctx, &ctx->confdb_ctx, conf_db); if (ret != EOK) { @@ -382,6 +382,30 @@ int server_setup(const char *name, int flags, } if (dt) debug_timestamps = 1; + /* same for debug to file */ + dl = (debug_to_file != 0); + ret = confdb_get_bool(ctx->confdb_ctx, ctx, conf_entry, + CONFDB_SERVICE_DEBUG_TO_FILES, + dl, &dl); + if (ret != EOK) { + DEBUG(0, ("Error reading from confdb (%d) [%s]\n", + ret, strerror(ret))); + return ret; + } + if (dl) debug_to_file = 1; + + /* open log file if told so */ + if (debug_to_file) { + ret = open_debug_file(); + if (ret != EOK) { + DEBUG(0, ("Error setting up logging (%d) [%s]\n", + ret, strerror(ret))); + return ret; + } + } + + DEBUG(3, ("CONFDB: %s\n", conf_db)); + if (flags & FLAGS_INTERACTIVE) { /* terminate when stdin goes away */ stdin_event_flags = TEVENT_FD_READ; diff --git a/server/util/util.h b/server/util/util.h index ea7f44e8..0212df06 100644 --- a/server/util/util.h +++ b/server/util/util.h @@ -43,11 +43,15 @@ typedef int errno_t; extern const char *debug_prg_name; extern int debug_level; extern int debug_timestamps; +extern int debug_to_file; +extern const char *debug_log_file; void debug_fn(const char *format, ...); #define SSSD_DEBUG_OPTS \ {"debug-level", 'd', POPT_ARG_INT, &debug_level, 0, \ "Debug level", NULL}, \ + {"debug-to-files", 'f', POPT_ARG_NONE, &debug_to_file, 0, \ + "Send the debug output to files instead of stderr", NULL }, \ {"debug-timestamps", 0, POPT_ARG_NONE, &debug_timestamps, 0, \ "Add debug timestamps", NULL}, @@ -133,6 +137,7 @@ void debug_fn(const char *format, ...); /* From debug.c */ void ldb_debug_messages(void *context, enum ldb_debug_level level, const char *fmt, va_list ap); +int open_debug_file(void); /* from server.c */ struct main_context { |