-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/25/2009 01:50 PM, Simo Sorce wrote:
>>> Please update sysv/sssd to use debug-to-files by default (at level
>> > 0),
>>> > > so that critical failures will appear in the logs.
>> > 
>> > Done, also with Simo's comments about dup-ing static strings.
> ack by me.
> 
> Simo.

attached is a patch rebased on top of the latest confdb patches.

The only change is that sssd.spec.in is patched to own the /var/log/sssd
directory.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkq8xOMACgkQHsardTLnvCVRdwCdGhYGes2GiNtQG3HSu25S7h71
duwAoIlfXgtynTv7IIMYo7oLZmqYm8m6
=xUDw
-----END PGP SIGNATURE-----
>From d4be63eabe9549c2271e8b559e9d57c913096149 Mon Sep 17 00:00:00 2001
From: Jakub Hrozek <jhro...@redhat.com>
Date: Fri, 25 Sep 2009 13:20:13 +0200
Subject: [PATCH] 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.
---
 contrib/sssd.spec.in                |    1 +
 server/Makefile.am                  |    4 +-
 server/conf_macros.m4               |   17 ++++++++++++++++
 server/confdb/confdb.h              |    1 +
 server/configure.ac                 |    1 +
 server/man/sssd.8.xml               |   12 +++++++++++
 server/monitor/monitor.c            |   18 ++++++++++++++--
 server/providers/data_provider.c    |    4 ++-
 server/providers/data_provider_be.c |    4 +++
 server/responder/nss/nsssrv.c       |    4 ++-
 server/responder/pam/pamsrv.c       |    4 ++-
 server/sysv/sssd                    |    2 +-
 server/util/debug.c                 |   37 ++++++++++++++++++++++++++++++++++-
 server/util/server.c                |   26 +++++++++++++++++++++++-
 server/util/util.h                  |    5 ++++
 15 files changed, 129 insertions(+), 11 deletions(-)

diff --git a/contrib/sssd.spec.in b/contrib/sssd.spec.in
index 79448e6..a762cea 100644
--- a/contrib/sssd.spec.in
+++ b/contrib/sssd.spec.in
@@ -128,6 +128,7 @@ rm -rf $RPM_BUILD_ROOT
 %attr(700,root,root) %dir %{dbpath}
 %attr(755,root,root) %dir %{pipepath}
 %attr(700,root,root) %dir %{pipepath}/private
+%attr(750,root,root) %dir %{_var}/log/audit
 %dir %{_sysconfdir}/sssd
 %config(noreplace) %{_sysconfdir}/sssd/sssd.conf
 %{_mandir}/man5/sssd.conf.5*
diff --git a/server/Makefile.am b/server/Makefile.am
index dc44fd9..076a792 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
@@ -563,7 +563,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 9ab2003..410914e 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 7ca8550..eef9a26 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 03d2885..31dd87d 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 f6f71c6..880cf76 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 0b013b5..fe5b5da 100644
--- a/server/monitor/monitor.c
+++ b/server/monitor/monitor.c
@@ -939,11 +939,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;
@@ -1054,9 +1056,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);
@@ -2479,6 +2482,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 f727c55..0838cd0 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 62ce7bb..29d6fa0 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 e000dfa..6cdd19a 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 50acc26..dbc8ec1 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 1385401..6ef7862 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 a7b3a09..c6aa27c 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 a8c5024..e8daf87 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 6e243d2..389d3a2 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},
 
@@ -135,6 +139,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 {
-- 
1.6.2.5

_______________________________________________
sssd-devel mailing list
sssd-devel@lists.fedorahosted.org
https://fedorahosted.org/mailman/listinfo/sssd-devel

Reply via email to