d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering/***
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering This file is part of systemd.
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering Copyright 2013 Lennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering systemd is free software; you can redistribute it and/or modify it
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering under the terms of the GNU Lesser General Public License as published by
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering the Free Software Foundation; either version 2.1 of the License, or
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering (at your option) any later version.
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering systemd is distributed in the hope that it will be useful, but
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering WITHOUT ANY WARRANTY; without even the implied warranty of
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering Lesser General Public License for more details.
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering You should have received a copy of the GNU Lesser General Public License
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering along with systemd; If not, see <http://www.gnu.org/licenses/>.
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering***/
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering#include <fcntl.h>
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering#include "sd-journal.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering
b5efdb8af40ea759a1ea584c1bc44ecc81dd00ceLennart Poettering#include "alloc-util.h"
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering#include "journal-file.h"
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering#include "journal-internal.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "macro.h"
07630cea1f3a845c09309f197ac7c4f11edd3b62Lennart Poettering#include "string-util.h"
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poetteringint main(int argc, char *argv[]) {
3e348b8a6af4bc46562efa44500fe2fa44320aa1Ronny Chevalier _cleanup_free_ char *fn = NULL;
3e348b8a6af4bc46562efa44500fe2fa44320aa1Ronny Chevalier char dn[] = "/var/tmp/test-journal-flush.XXXXXX";
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering JournalFile *new_journal = NULL;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering sd_journal *j = NULL;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering unsigned n = 0;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering int r;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
dfd9cf7f0b257d38f5527989dd9315e767fbe41bZbigniew Jędrzejewski-Szmek assert_se(mkdtemp(dn));
dfd9cf7f0b257d38f5527989dd9315e767fbe41bZbigniew Jędrzejewski-Szmek fn = strappend(dn, "/test.journal");
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering r = journal_file_open(fn, O_CREAT|O_RDWR, 0644, false, false, NULL, NULL, NULL, &new_journal);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering assert_se(r >= 0);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering r = sd_journal_open(&j, 0);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering assert_se(r >= 0);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering sd_journal_set_data_threshold(j, 0);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering SD_JOURNAL_FOREACH(j) {
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering Object *o;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering JournalFile *f;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering f = j->current_file;
0c0cdb06c139b52ff103287f6909b3daa5b2dc54Ronny Chevalier assert_se(f && f->current_offset > 0);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering r = journal_file_move_to_object(f, OBJECT_ENTRY, f->current_offset, &o);
0c0cdb06c139b52ff103287f6909b3daa5b2dc54Ronny Chevalier assert_se(r >= 0);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering r = journal_file_copy_entry(f, new_journal, o, f->current_offset, NULL, NULL, NULL);
0c0cdb06c139b52ff103287f6909b3daa5b2dc54Ronny Chevalier assert_se(r >= 0);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering n++;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering if (n > 10000)
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering break;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering }
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering sd_journal_close(j);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering journal_file_close(new_journal);
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering
2678031a179a9b91fc799f8ef951a548c66c4b49Lennart Poettering unlink(fn);
dfd9cf7f0b257d38f5527989dd9315e767fbe41bZbigniew Jędrzejewski-Szmek assert_se(rmdir(dn) == 0);
dfd9cf7f0b257d38f5527989dd9315e767fbe41bZbigniew Jędrzejewski-Szmek
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering return 0;
d0767ffd08bbb5c069e266710eb0462315e47e6dLennart Poettering}