[systemd-commits] 2 commits - src/journal
Zbigniew JÄdrzejewski-Szmek
zbyszek at kemper.freedesktop.org
Wed Oct 9 19:38:30 PDT 2013
src/journal/journal-file.c | 23 ++++++++---------------
src/journal/journald-server.c | 4 +++-
2 files changed, 11 insertions(+), 16 deletions(-)
New commits:
commit 2b98f75a63e6022bf74a7d678c47faa5208c794f
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Oct 9 22:13:13 2013 -0400
journald: remove rotated file from hashmap when rotation fails
Before, when the user journal file was rotated, journal_file_rotate
could close the old file and fail to open the new file. In that
case, we would leave the old (deallocated) file in the hashmap.
On subsequent accesses, we could retrieve this stale entry, leading
to a segfault.
When journal_file_rotate fails with the file pointer set to 0,
old file is certainly gone, and cannot be used anymore.
https://bugzilla.redhat.com/show_bug.cgi?id=890463
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index 4f47eb1..e03e413 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -321,8 +321,10 @@ void server_rotate(Server *s) {
if (r < 0)
if (f)
log_error("Failed to rotate %s: %s", f->path, strerror(-r));
- else
+ else {
log_error("Failed to create user journal: %s", strerror(-r));
+ hashmap_remove(s->user_journals, k);
+ }
else {
hashmap_replace(s->user_journals, k, f);
server_fix_perms(s, f, PTR_TO_UINT32(k));
commit 57535f4703b5de5d03ad6e35bd06247d378f46fe
Author: Zbigniew JÄdrzejewski-Szmek <zbyszek at in.waw.pl>
Date: Wed Oct 9 22:13:04 2013 -0400
journald: replace new+snprintf with asprintf
diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c
index 81c344f..78b937b 100644
--- a/src/journal/journal-file.c
+++ b/src/journal/journal-file.c
@@ -2551,7 +2551,7 @@ fail:
}
int journal_file_rotate(JournalFile **f, bool compress, bool seal) {
- char *p;
+ _cleanup_free_ char *p = NULL;
size_t l;
JournalFile *old_file, *new_file = NULL;
int r;
@@ -2568,22 +2568,15 @@ int journal_file_rotate(JournalFile **f, bool compress, bool seal) {
return -EINVAL;
l = strlen(old_file->path);
-
- p = new(char, l + 1 + 32 + 1 + 16 + 1 + 16 + 1);
- if (!p)
+ r = asprintf(&p, "%.*s@" SD_ID128_FORMAT_STR "-%016"PRIx64"-%016"PRIx64".journal",
+ (int) l - 8, old_file->path,
+ SD_ID128_FORMAT_VAL(old_file->header->seqnum_id),
+ le64toh((*f)->header->head_entry_seqnum),
+ le64toh((*f)->header->head_entry_realtime));
+ if (r < 0)
return -ENOMEM;
- memcpy(p, old_file->path, l - 8);
- p[l-8] = '@';
- sd_id128_to_string(old_file->header->seqnum_id, p + l - 8 + 1);
- snprintf(p + l - 8 + 1 + 32, 1 + 16 + 1 + 16 + 8 + 1,
- "-%016"PRIx64"-%016"PRIx64".journal",
- le64toh((*f)->header->head_entry_seqnum),
- le64toh((*f)->header->head_entry_realtime));
-
r = rename(old_file->path, p);
- free(p);
-
if (r < 0)
return -errno;
@@ -2634,7 +2627,7 @@ int journal_file_open_reliably(
l = strlen(fname);
if (asprintf(&p, "%.*s@%016llx-%016llx.journal~",
- (int) (l-8), fname,
+ (int) l - 8, fname,
(unsigned long long) now(CLOCK_REALTIME),
random_ull()) < 0)
return -ENOMEM;
More information about the systemd-commits
mailing list