summaryrefslogtreecommitdiffstats
path: root/server/util/debug.c
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/debug.c
parent6cec00b7fe2aed71b8df21d2a0d97df8b448cc85 (diff)
downloadsssd-05315b44feaa9819e62f18477f2c6d20914eb7ce.tar.gz
sssd-05315b44feaa9819e62f18477f2c6d20914eb7ce.tar.xz
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/debug.c')
-rw-r--r--server/util/debug.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/server/util/debug.c b/server/util/debug.c
index a7b3a0916..c6aa27c92 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;
+}