+ else if (entry[entry_len - 1] != '\n')
+ {
+ RRDD_LOG(LOG_NOTICE, "Malformed journal entry at line %"PRIu64, line);
+ ++fail_cnt;
+ continue;
+ }
+
+ entry[entry_len - 1] = '\0';
+
+ if (handle_request(NULL, now, entry, entry_len) == 0)
+ ++entry_cnt;
+ else
+ ++fail_cnt;
+ }
+
+ fclose(fh);
+
+ RRDD_LOG(LOG_INFO, "Replayed %d entries (%d failures)",
+ entry_cnt, fail_cnt);
+
+ return entry_cnt > 0 ? 1 : 0;
+} /* }}} static int journal_replay */
+
+static int journal_sort(const void *v1, const void *v2)
+{
+ char **jn1 = (char **) v1;
+ char **jn2 = (char **) v2;
+
+ return strcmp(*jn1,*jn2);
+}
+
+static void journal_init(void) /* {{{ */
+{
+ int had_journal = 0;
+ DIR *dir;
+ struct dirent *dent;
+ char path[PATH_MAX+1];
+
+ if (journal_dir == NULL) return;
+
+ pthread_mutex_lock(&journal_lock);
+
+ journal_cur = calloc(1, sizeof(journal_set));
+ if (journal_cur == NULL)
+ {
+ RRDD_LOG(LOG_CRIT, "journal_rotate: malloc(journal_set) failed\n");
+ return;
+ }
+
+ RRDD_LOG(LOG_INFO, "checking for journal files");
+
+ /* Handle old journal files during transition. This gives them the
+ * correct sort order. TODO: remove after first release
+ */
+ {
+ char old_path[PATH_MAX+1];
+ snprintf(old_path, PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE ".old" );
+ snprintf(path, PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE ".0000");
+ rename(old_path, path);
+
+ snprintf(old_path, PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE );
+ snprintf(path, PATH_MAX, "%s/%s", journal_dir, JOURNAL_BASE ".0001");
+ rename(old_path, path);
+ }
+
+ dir = opendir(journal_dir);
+ while ((dent = readdir(dir)) != NULL)
+ {
+ /* looks like a journal file? */
+ if (strncmp(dent->d_name, JOURNAL_BASE, strlen(JOURNAL_BASE)))
+ continue;
+
+ snprintf(path, PATH_MAX, "%s/%s", journal_dir, dent->d_name);
+
+ if (!rrd_add_strdup(&journal_cur->files, &journal_cur->files_num, path))