+ 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))
+ {
+ RRDD_LOG(LOG_CRIT, "journal_init: cannot add journal file %s!",
+ dent->d_name);
+ break;
+ }
+ }
+ closedir(dir);
+
+ qsort(journal_cur->files, journal_cur->files_num,
+ sizeof(journal_cur->files[0]), journal_sort);
+
+ for (uint i=0; i < journal_cur->files_num; i++)
+ had_journal += journal_replay(journal_cur->files[i]);
+
+ journal_new_file();
+
+ /* it must have been a crash. start a flush */
+ if (had_journal && config_flush_at_shutdown)
+ flush_old_values(-1);
+
+ pthread_mutex_unlock(&journal_lock);
+
+ RRDD_LOG(LOG_INFO, "journal processing complete");
+
+} /* }}} static void journal_init */
+
+static void free_listen_socket(listen_socket_t *sock) /* {{{ */
+{
+ assert(sock != NULL);
+
+ free(sock->rbuf); sock->rbuf = NULL;
+ free(sock->wbuf); sock->wbuf = NULL;
+ free(sock);
+} /* }}} void free_listen_socket */
+
+static void close_connection(listen_socket_t *sock) /* {{{ */
+{
+ if (sock->fd >= 0)
+ {
+ close(sock->fd);
+ sock->fd = -1;
+ }
+
+ free_listen_socket(sock);
+
+} /* }}} void close_connection */