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