summaryrefslogtreecommitdiffstats
path: root/server/util
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2009-09-18 12:35:34 +0200
committerStephen Gallagher <sgallagh@redhat.com>2009-09-21 10:35:10 -0400
commit8c50bd085c0efe5fde354deee2c8118887aae29d (patch)
treeb3968a8878c533438aef689b79825915e2720ef2 /server/util
parent9570ca098cd0e92d1eb6aabc00fb8cac9fddd442 (diff)
downloadsssd-8c50bd085c0efe5fde354deee2c8118887aae29d.tar.gz
sssd-8c50bd085c0efe5fde354deee2c8118887aae29d.tar.xz
sssd-8c50bd085c0efe5fde354deee2c8118887aae29d.zip
Use syslog for logging error conditions in SSSD
This is just a band-aid until ELAPI is fully functional and ready to use.
Diffstat (limited to 'server/util')
-rw-r--r--server/util/debug.c1
-rw-r--r--server/util/server.c34
-rw-r--r--server/util/util.h16
3 files changed, 34 insertions, 17 deletions
diff --git a/server/util/debug.c b/server/util/debug.c
index a7b3a0916..f0b5865e1 100644
--- a/server/util/debug.c
+++ b/server/util/debug.c
@@ -29,6 +29,7 @@
const char *debug_prg_name = "sssd";
int debug_level = 0;
int debug_timestamps = 0;
+int send_syslog = 1;
void debug_fn(const char *format, ...)
{
diff --git a/server/util/server.c b/server/util/server.c
index 0760e60f2..c195864ff 100644
--- a/server/util/server.c
+++ b/server/util/server.c
@@ -62,11 +62,11 @@ static void close_low_fds(bool stderr_too)
if (fd < 0)
fd = open("/dev/null",O_WRONLY,0);
if (fd < 0) {
- DEBUG(0,("Can't open /dev/null\n"));
+ SYSLOG_ERROR("Can't open /dev/null\n");
return;
}
if (fd != i) {
- DEBUG(0,("Didn't get file descriptor %d\n",i));
+ SYSLOG_ERROR("Didn't get file descriptor %d\n",i);
return;
}
}
@@ -94,8 +94,8 @@ void become_daemon(bool Fork)
errno = 0;
if(chdir("/") == -1) {
ret = errno;
- DEBUG(0, ("Cannot change directory (%d [%s])\n",
- ret, strerror(ret)));
+ SYSLOG_ERROR("Cannot change directory (%d [%s])\n",
+ ret, strerror(ret));
return;
}
@@ -187,7 +187,7 @@ static void sig_term(int sig)
#if HAVE_GETPGRP
static int done_sigterm;
if (done_sigterm == 0 && getpgrp() == getpid()) {
- DEBUG(0,("SIGTERM: killing children\n"));
+ SYSLOG_NOTICE("SIGTERM: killing children\n");
done_sigterm = 1;
kill(-getpgrp(), SIGTERM);
}
@@ -201,7 +201,7 @@ static void sig_segv_abrt(int sig)
#if HAVE_GETPGRP
static int done;
if (done == 0 && getpgrp() == getpid()) {
- DEBUG(0,("%s: killing children\n", strsignal(sig)));
+ SYSLOG_NOTICE("%s: killing children\n", strsignal(sig));
done = 1;
kill(-getpgrp(), SIGTERM);
}
@@ -258,7 +258,7 @@ static void server_stdin_handler(struct tevent_context *event_ctx,
const char *binary_name = (const char *)private;
uint8_t c;
if (read(0, &c, 1) == 0) {
- DEBUG(0,("%s: EOF on stdin - terminating\n", binary_name));
+ SYSLOG_NOTICE("%s: EOF on stdin - terminating\n", binary_name);
#if HAVE_GETPGRP
if (getpgrp() == getpid()) {
kill(-getpgrp(), SIGTERM);
@@ -320,8 +320,8 @@ int server_setup(const char *name, int flags,
if (flags & FLAGS_PID_FILE) {
ret = pidfile(PID_PATH, name);
if (ret != EOK) {
- DEBUG(0, ("Error creating pidfile! (%d [%s])\n",
- ret, strerror(ret)));
+ SYSLOG_ERROR("Error creating pidfile! (%d [%s])\n",
+ ret, strerror(ret));
return ret;
}
}
@@ -335,13 +335,13 @@ int server_setup(const char *name, int flags,
* Everything else should hang off that */
event_ctx = tevent_context_init(talloc_autofree_context());
if (event_ctx == NULL) {
- DEBUG(0,("The event context initialiaziton failed\n"));
+ SYSLOG_ERROR("The event context initialiaziton failed\n");
return 1;
}
ctx = talloc(event_ctx, struct main_context);
if (ctx == NULL) {
- DEBUG(0,("Out of memory, aborting!\n"));
+ SYSLOG_ERROR("Out of memory, aborting!\n");
return ENOMEM;
}
@@ -349,14 +349,14 @@ int server_setup(const char *name, int flags,
conf_db = talloc_asprintf(ctx, "%s/%s", DB_PATH, CONFDB_FILE);
if (conf_db == NULL) {
- DEBUG(0,("Out of memory, aborting!\n"));
+ SYSLOG_ERROR("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) {
- DEBUG(0,("The confdb initialization failed\n"));
+ SYSLOG_ERROR("The confdb initialization failed\n");
return ret;
}
@@ -364,8 +364,8 @@ int server_setup(const char *name, int flags,
ret = confdb_get_int(ctx->confdb_ctx, ctx, conf_entry,
"debug-level", debug_level, &debug_level);
if (ret != EOK) {
- DEBUG(0, ("Error reading from confdb (%d) [%s]\n",
- ret, strerror(ret)));
+ SYSLOG_ERROR("Error reading from confdb (%d) [%s]\n",
+ ret, strerror(ret));
return ret;
}
@@ -374,8 +374,8 @@ int server_setup(const char *name, int flags,
ret = confdb_get_bool(ctx->confdb_ctx, ctx, conf_entry,
"debug-timestamps", dt, &dt);
if (ret != EOK) {
- DEBUG(0, ("Error reading from confdb (%d) [%s]\n",
- ret, strerror(ret)));
+ SYSLOG_ERROR("Error reading from confdb (%d) [%s]\n",
+ ret, strerror(ret));
return ret;
}
if (dt) debug_timestamps = 1;
diff --git a/server/util/util.h b/server/util/util.h
index ea7f44e83..1b039637f 100644
--- a/server/util/util.h
+++ b/server/util/util.h
@@ -30,6 +30,7 @@
#include <limits.h>
#include <time.h>
#include <pcre.h>
+#include <syslog.h>
#include "config.h"
#include "talloc.h"
#include "tevent.h"
@@ -43,6 +44,7 @@ typedef int errno_t;
extern const char *debug_prg_name;
extern int debug_level;
extern int debug_timestamps;
+extern int send_syslog;
void debug_fn(const char *format, ...);
#define SSSD_DEBUG_OPTS \
@@ -81,6 +83,20 @@ void debug_fn(const char *format, ...);
#define PRINT(fmt, ...) fprintf(stdout, gettext(fmt), ##__VA_ARGS__)
#define ERROR(fmt, ...) fprintf(stderr, gettext(fmt), ##__VA_ARGS__)
+#define SYSLOG_ERROR(...) do { \
+ DEBUG(0, (__VA_ARGS__)); \
+ if (send_syslog) { \
+ syslog(LOG_ERR, __VA_ARGS__); \
+ } \
+} while(0);
+
+#define SYSLOG_NOTICE(...) do { \
+ DEBUG(0, (__VA_ARGS__)); \
+ if (send_syslog) { \
+ syslog(LOG_NOTICE, __VA_ARGS__); \
+ } \
+} while(0);
+
#ifndef discard_const
#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
#endif