test-journal-flush.c revision dfd9cf7f0b257d38f5527989dd9315e767fbe41b
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering/***
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering This file is part of systemd.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering Copyright 2013 Lennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering systemd is free software; you can redistribute it and/or modify it
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering under the terms of the GNU Lesser General Public License as published by
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering the Free Software Foundation; either version 2.1 of the License, or
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering (at your option) any later version.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering systemd is distributed in the hope that it will be useful, but
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering Lesser General Public License for more details.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering You should have received a copy of the GNU Lesser General Public License
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering***/
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering
718db96199eb307751264e4163555662c9a389faLennart Poettering#include <fcntl.h>
718db96199eb307751264e4163555662c9a389faLennart Poettering
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering#include "sd-journal.h"
4ad490007b70e6ac18d3cb04fa2ed92eba1451faLennart Poettering#include "journal-file.h"
4ad490007b70e6ac18d3cb04fa2ed92eba1451faLennart Poettering#include "journal-internal.h"
a016b9228f338cb9b380ce7e00826ef462767d98Lennart Poettering
718db96199eb307751264e4163555662c9a389faLennart Poetteringint main(int argc, char *argv[]) {
718db96199eb307751264e4163555662c9a389faLennart Poettering
718db96199eb307751264e4163555662c9a389faLennart Poettering char dn[] = "/var/tmp/test-journal-flush.XXXXXX", *fn;
718db96199eb307751264e4163555662c9a389faLennart Poettering JournalFile *new_journal = NULL;
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering sd_journal *j = NULL;
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering unsigned n = 0;
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering int r;
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering
718db96199eb307751264e4163555662c9a389faLennart Poettering assert_se(mkdtemp(dn));
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering fn = strappend(dn, "/test.journal");
718db96199eb307751264e4163555662c9a389faLennart Poettering
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering r = journal_file_open(fn, O_CREAT|O_RDWR, 0644, false, false, NULL, NULL, NULL, &new_journal);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering assert_se(r >= 0);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering unlink(fn);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering r = sd_journal_open(&j, 0);
718db96199eb307751264e4163555662c9a389faLennart Poettering assert_se(r >= 0);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering sd_journal_set_data_threshold(j, 0);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering SD_JOURNAL_FOREACH(j) {
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering Object *o;
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering JournalFile *f;
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering
bc432dc7eb62c5671f2b741a86a66393adb350dcLennart Poettering f = j->current_file;
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering assert(f && f->current_offset > 0);
8e2af478402414f060bbc16e1b4bbe7de1779c13Lennart Poettering
r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
assert(r >= 0);
r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL, NULL);
assert(r >= 0);
n++;
if (n > 10000)
break;
}
sd_journal_close(j);
journal_file_close(new_journal);
assert_se(rmdir(dn) == 0);
return 0;
}