chiark / gitweb /
journald: remove rotated file from hashmap when rotation fails
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Oct 2013 02:13:13 +0000 (22:13 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Thu, 10 Oct 2013 02:32:08 +0000 (22:32 -0400)
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

src/journal/journald-server.c

index 4f47eb1..e03e413 100644 (file)
@@ -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));