]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-file-util: do not fail when journal_file_set_offline() called more than once
authorYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 5 Oct 2023 09:20:40 +0000 (18:20 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 5 Oct 2023 10:15:55 +0000 (19:15 +0900)
Previously, if journal_file_set_offline() is called twice with 'wait = false',
the second call triggered segfaults, as the offline_state is OFFLINE_DONE,
and journal_file_set_offline_thread_join() tries to call pthread_join()
with NULL.

src/shared/journal-file-util.c

index 90737fb8a859c672795ad64d8820481b774c3644..ff32a1aac83d630ab55c09890a457ef2eca4eb13 100644 (file)
@@ -346,9 +346,14 @@ int journal_file_set_offline(JournalFile *f, bool wait) {
         /* Initiate a new offline. */
         f->offline_state = OFFLINE_SYNCING;
 
-        if (wait) /* Without using a thread if waiting. */
+        if (wait) {
+                /* Without using a thread if waiting. */
                 journal_file_set_offline_internal(f);
-        else {
+
+                assert(f->offline_state == OFFLINE_DONE);
+                f->offline_state = OFFLINE_JOINED;
+
+        } else {
                 sigset_t ss, saved_ss;
                 int k;