test-journal-stream.c revision c6511e859c35b12de4e6fb5f58d7258d9de3b8f2
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <unistd.h>
#include <fcntl.h>
#include <systemd/sd-journal.h>
#include "journal-file.h"
#include "journal-internal.h"
#include "util.h"
#include "log.h"
#define N_ENTRIES 200
unsigned i;
assert(j);
i = 0;
SD_JOURNAL_FOREACH(j) {
const void *d;
char *k, *c;
size_t l;
unsigned u;
assert_se(sd_journal_get_cursor(j, &k) >= 0);
printf("cursor: %s\n", k);
free(k);
printf("\t%.*s\n", (int) l, (const char*) d);
printf("\t%s\n", k);
if (skip > 0) {
assert_se(i == u);
i += skip;
}
free(k);
assert_se(sd_journal_get_cursor(j, &c) >= 0);
assert_se(sd_journal_test_cursor(j, c) > 0);
free(c);
}
if (skip > 0)
}
char t[] = "/tmp/journal-stream-XXXXXX";
unsigned i;
sd_journal *j;
char *z;
assert_se(journal_file_open("one.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &one) == 0);
assert_se(journal_file_open("two.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &two) == 0);
assert_se(journal_file_open("three.journal", O_RDWR|O_CREAT, 0666, true, false, NULL, NULL, NULL, &three) == 0);
for (i = 0; i < N_ENTRIES; i++) {
char *p, *q;
if (i % 10 == 0)
else {
if (i % 3 == 0)
}
free(p);
free(q);
}
assert_se(sd_journal_open_directory(&j, t, 0) >= 0);
const void *d;
size_t l;
char *c;
printf("\t%.*s\n", (int) l, (const char*) d);
assert_se(sd_journal_get_cursor(j, &c) >= 0);
assert_se(sd_journal_test_cursor(j, c) > 0);
free(c);
}
SD_JOURNAL_FOREACH(j) {
const void *d;
size_t l;
char *c;
printf("\t%.*s\n", (int) l, (const char*) d);
assert_se(sd_journal_get_cursor(j, &c) >= 0);
assert_se(sd_journal_test_cursor(j, c) > 0);
free(c);
}
verify_contents(j, 1);
printf("NEXT TEST\n");
assert_se(z = journal_make_match_string(j));
printf("resulting match expression is: %s\n", z);
free(z);
verify_contents(j, 5);
printf("NEXT TEST\n");
assert_se(z = journal_make_match_string(j));
printf("resulting match expression is: %s\n", z);
free(z);
verify_contents(j, 0);
sd_journal_close(j);
assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
return 0;
}