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