static gboolean _load_queue(QDisk *self, GQueue *q, gint64 q_ofs, gint32 q_len, gint32 q_count) { GString *serialized; SerializeArchive *sa; gint i; if (q_ofs) { gssize read_len; serialized = g_string_sized_new(q_len); g_string_set_size(serialized, q_len); read_len = pread(self->fd, serialized->str, q_len, q_ofs); if (read_len < 0 || read_len != q_len) { msg_error("Error reading in-memory buffer from disk-queue file", evt_tag_str("filename", self->filename), read_len < 0 ? evt_tag_errno("error", errno) : evt_tag_str("error", "short read")); g_string_free(serialized, TRUE); return FALSE; } sa = serialize_string_archive_new(serialized); for (i = 0; i < q_count; i++) { LogMessage *msg; msg = log_msg_new_empty(); if (log_msg_deserialize(msg, sa)) { g_queue_push_tail(q, msg); /* we restore the queue without ACKs */ g_queue_push_tail(q, GINT_TO_POINTER(0x80000000)); } else { msg_error("Error reading message from disk-queue file (maybe currupted file) some messages will be lost", evt_tag_str("filename", self->filename), evt_tag_int("lost messages", q_count - i)); log_msg_unref(msg); break; } } g_string_free(serialized, TRUE); serialize_archive_free(sa); } return TRUE; }
static gboolean _pop_disk(LogQueueDisk *self, LogMessage **msg) { GString *serialized; SerializeArchive *sa; *msg = NULL; if (!qdisk_initialized(self->qdisk)) return FALSE; serialized = g_string_sized_new(64); if (!qdisk_pop_head(self->qdisk, serialized)) { g_string_free(serialized, TRUE); return FALSE; } sa = serialize_string_archive_new(serialized); *msg = log_msg_new_empty(); if (!log_msg_deserialize(*msg, sa)) { g_string_free(serialized, TRUE); serialize_archive_free(sa); log_msg_unref(*msg); *msg = NULL; msg_error("Can't read correct message from disk-queue file",evt_tag_str("filename",qdisk_get_filename(self->qdisk)),NULL); return TRUE; } serialize_archive_free(sa); g_string_free(serialized, TRUE); return TRUE; }