summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-05-21 03:31:49 +0200
committerLennart Poettering <lennart@poettering.net>2010-05-21 03:31:49 +0200
commit9726b29e9811d12c0800a53f0a34dc26fe9b915c (patch)
tree9e29a63eb04c349c4869f5389d5e15059a773759 /src
parentb6dbbe1c9860d1e1a7ca7e4be170959277f9e04d (diff)
log: handle multi-line log messages properly
Diffstat (limited to 'src')
-rw-r--r--src/log.c56
1 files changed, 37 insertions, 19 deletions
diff --git a/src/log.c b/src/log.c
index 7b4db4c77a..1343b9d986 100644
--- a/src/log.c
+++ b/src/log.c
@@ -312,31 +312,49 @@ static int log_dispatch(
const char*file,
int line,
const char *func,
- const char *buffer) {
+ char *buffer) {
- int r;
+ int r = 0;
- if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
- log_target == LOG_TARGET_SYSLOG) {
+ do {
+ char *e;
+ int k;
- if ((r = write_to_syslog(level, file, line, func, buffer)) < 0) {
- log_close_syslog();
- log_open_kmsg();
- } else if (r > 0)
- return r;
- }
+ buffer += strspn(buffer, NEWLINE);
- if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
- log_target == LOG_TARGET_KMSG) {
+ if (buffer[0] == 0)
+ break;
- if ((r = write_to_kmsg(level, file, line, func, buffer)) < 0) {
- log_close_kmsg();
- log_open_console();
- } else if (r > 0)
- return r;
- }
+ if ((e = strpbrk(buffer, NEWLINE)))
+ *(e++) = 0;
- return write_to_console(level, file, line, func, buffer);
+ if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+ log_target == LOG_TARGET_SYSLOG) {
+
+ if ((r = write_to_syslog(level, file, line, func, buffer)) < 0) {
+ log_close_syslog();
+ log_open_kmsg();
+ } else if (r > 0)
+ r++;
+ }
+
+ if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+ log_target == LOG_TARGET_KMSG) {
+
+ if ((r = write_to_kmsg(level, file, line, func, buffer)) < 0) {
+ log_close_kmsg();
+ log_open_console();
+ } else if (r > 0)
+ r++;
+ }
+
+ if ((k = write_to_console(level, file, line, func, buffer)) < 0)
+ return k;
+
+ buffer = e;
+ } while (buffer);
+
+ return r;
}
int log_meta(