From 911efc97f9bfe2ad4f4d021f5e76d05c8d5d81ac Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 12 Apr 2012 12:57:41 +0200 Subject: [PATCH 1/4] journald: add missing flag to open() --- src/journal/journald.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/journal/journald.c b/src/journal/journald.c index baad3ab..c8b400a 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -2461,7 +2461,7 @@ static int open_proc_kmsg(Server *s) { return 0; - s->proc_kmsg_fd = open("/proc/kmsg", O_CLOEXEC|O_NONBLOCK|O_NOCTTY); + s->proc_kmsg_fd = open("/proc/kmsg", O_RDONLY|O_CLOEXEC|O_NONBLOCK|O_NOCTTY); if (s->proc_kmsg_fd < 0) { log_warning("Failed to open /proc/kmsg, ignoring: %m"); return 0; -- 1.7.7 From 94b8299358fd743137857bc0f28ab62bcf6eec92 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 13 Apr 2012 13:58:50 +0200 Subject: [PATCH 2/4] fix a couple of things found with the llvm static analyzer --- src/journal/journal-file.c | 2 +- src/journal/journald.c | 2 +- src/logs-show.c | 2 +- src/manager.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 474dd5c..5255c3b 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -1974,7 +1974,7 @@ int journal_directory_vacuum(const char *directory, uint64_t max_use, uint64_t m size_t q; struct stat st; char *p; - unsigned long long seqnum, realtime; + unsigned long long seqnum = 0, realtime; sd_id128_t seqnum_id; bool have_seqnum; diff --git a/src/journal/journald.c b/src/journal/journald.c index c8b400a..1118b7e 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -1140,7 +1140,7 @@ static void process_native_message( char *identifier = NULL, *message = NULL; assert(s); - assert(buffer || n == 0); + assert(buffer || buffer_size == 0); p = buffer; remaining = buffer_size; diff --git a/src/logs-show.c b/src/logs-show.c index f71c6b0..eb9a902 100644 --- a/src/logs-show.c +++ b/src/logs-show.c @@ -541,7 +541,7 @@ int show_journal_by_unit( bool follow) { char *m = NULL; - sd_journal *j; + sd_journal *j = NULL; int r; int fd; unsigned line = 0; diff --git a/src/manager.c b/src/manager.c index 74bd740..3e592b6 100644 --- a/src/manager.c +++ b/src/manager.c @@ -2979,7 +2979,7 @@ bool manager_unit_pending_inactive(Manager *m, const char *name) { void manager_check_finished(Manager *m) { char userspace[FORMAT_TIMESPAN_MAX], initrd[FORMAT_TIMESPAN_MAX], kernel[FORMAT_TIMESPAN_MAX], sum[FORMAT_TIMESPAN_MAX]; - usec_t kernel_usec = 0, initrd_usec = 0, userspace_usec = 0, total_usec = 0; + usec_t kernel_usec, initrd_usec, userspace_usec, total_usec; assert(m); -- 1.7.7 From f83fa045b967478a80ca55477dfe6a5be5f0b4a8 Mon Sep 17 00:00:00 2001 From: Sjoerd Simons Date: Sat, 14 Apr 2012 14:11:08 +0200 Subject: [PATCH 3/4] journal: crash when filesystem is low on space When space is getting too low on a file system rotating the journal file will fail after the rotation, as opening the new logfile will fail. Recognize this when logging the error and don't try to dereference a NULL JournalFile pointer. --- src/journal/journald.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/journal/journald.c b/src/journal/journald.c index 1118b7e..9180656 100644 --- a/src/journal/journald.c +++ b/src/journal/journald.c @@ -330,7 +330,10 @@ static void server_rotate(Server *s) { if (s->runtime_journal) { r = journal_file_rotate(&s->runtime_journal); if (r < 0) - log_error("Failed to rotate %s: %s", s->runtime_journal->path, strerror(-r)); + if (s->runtime_journal) + log_error("Failed to rotate %s: %s", s->runtime_journal->path, strerror(-r)); + else + log_error("Failed to create new runtime journal: %s", strerror(-r)); else server_fix_perms(s, s->runtime_journal, 0); } @@ -338,7 +341,11 @@ static void server_rotate(Server *s) { if (s->system_journal) { r = journal_file_rotate(&s->system_journal); if (r < 0) - log_error("Failed to rotate %s: %s", s->system_journal->path, strerror(-r)); + if (s->system_journal) + log_error("Failed to rotate %s: %s", s->system_journal->path, strerror(-r)); + else + log_error("Failed to create new system journal: %s", strerror(-r)); + else server_fix_perms(s, s->system_journal, 0); } @@ -346,7 +353,10 @@ static void server_rotate(Server *s) { HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) { r = journal_file_rotate(&f); if (r < 0) - log_error("Failed to rotate %s: %s", f->path, strerror(-r)); + if (f->path) + log_error("Failed to rotate %s: %s", f->path, strerror(-r)); + else + log_error("Failed to create user journal: %s", strerror(-r)); else { hashmap_replace(s->user_journals, k, f); server_fix_perms(s, s->system_journal, PTR_TO_UINT32(k)); -- 1.7.7 From d80e2f5c26aae25c0773042bcd1599d3c583bf6a Mon Sep 17 00:00:00 2001 From: Michal Schmidt Date: Tue, 12 Jun 2012 16:45:09 +0200 Subject: [PATCH 4/4] journal-file: fix mmap leak https://bugzilla.redhat.com/show_bug.cgi?id=831132 --- src/journal/journal-file.c | 7 +++++-- 1 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 5255c3b..e242fa2 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -67,9 +67,12 @@ void journal_file_close(JournalFile *f) { assert(f); - if (f->header && f->writable) - f->header->state = STATE_OFFLINE; + if (f->header) { + if (f->writable) + f->header->state = STATE_OFFLINE; + munmap(f->header, PAGE_ALIGN(sizeof(Header))); + } for (t = 0; t < _WINDOW_MAX; t++) if (f->windows[t].ptr) -- 1.7.7