summaryrefslogtreecommitdiff
path: root/server/util
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2009-09-25 13:20:13 +0200
committerStephen Gallagher <sgallagh@redhat.com>2009-09-25 10:19:56 -0400
commit05315b44feaa9819e62f18477f2c6d20914eb7ce (patch)
tree82e28792e306de9e461ea9dde5203d6a3a9de7fa /server/util
parent6cec00b7fe2aed71b8df21d2a0d97df8b448cc85 (diff)
downloadsssd-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/util')
-rw-r--r--server/util/debug.c37
-rw-r--r--server/util/server.c26
-rw-r--r--server/util/util.h5
3 files changed, 66 insertions, 2 deletions
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 {