static gboolean _load_queue(ThreadedDiskqSourceDriver *self) { self->diskq_options.read_only = TRUE; self->diskq_options.reliable = FALSE; FILE *file = fopen(self->filename, "rb"); if (!file) { msg_error("Error opening diskq file", evt_tag_str("file", self->filename)); return FALSE; } gchar file_signature[5] = {0}; if (fread(file_signature, 4, 1, file) == 0) { msg_error("Error reading diskq file signature", evt_tag_str("file", self->filename)); fclose(file); return FALSE; } fclose(file); if (strcmp(file_signature, "SLRQ") == 0) self->diskq_options.reliable = TRUE; if (self->diskq_options.reliable) { self->diskq_options.disk_buf_size = 128; self->diskq_options.mem_buf_size = 1024 * 1024; self->queue = log_queue_disk_reliable_new(&self->diskq_options, NULL); } else { self->diskq_options.disk_buf_size = 1; self->diskq_options.mem_buf_size = 128; self->diskq_options.qout_size = 128; self->queue = log_queue_disk_non_reliable_new(&self->diskq_options, NULL); } if (!log_queue_disk_load_queue(self->queue, self->filename)) { msg_error("Error loading diskq", evt_tag_str("file", self->filename)); return FALSE; } return TRUE; }
static gboolean open_queue(char *filename, LogQueue **lq, DiskQueueOptions *options) { options->read_only = TRUE; options->reliable = FALSE; FILE *f = fopen(filename, "rb"); if (f) { gchar idbuf[5]; if (fread(idbuf, 4, 1, f) == 0) fprintf(stderr, "File reading error: %s\n", filename); fclose(f); idbuf[4] = '\0'; if (!strcmp(idbuf, "SLRQ")) options->reliable = TRUE; } else { fprintf(stderr, "File not found: %s\n", filename); return FALSE; } if (options->reliable) { options->disk_buf_size = 128; options->mem_buf_size = 1024 * 1024; *lq = log_queue_disk_reliable_new(options); } else { options->disk_buf_size = 1; options->mem_buf_size = 128; options->qout_size = 128; *lq = log_queue_disk_non_reliable_new(options); } if (!log_queue_disk_load_queue(*lq, filename)) { fprintf(stderr, "Error restoring disk buffer file.\n"); return FALSE; } return TRUE; }