Beispiel #1
0
static int journal_next_skip (lua_State *L) {
	sd_journal *j = check_journal(L, 1);
	uint64_t skip = luaL_checkuint64(L, 2);
	int err = sd_journal_next_skip(j, skip);
	if (err < 0) return handle_error(L, -err);
	lua_pushinteger(L, err);
	return 1;
}
static void test_skip(void (*setup)(void))
{
    char t[] = "/tmp/journal-skip-XXXXXX";
    sd_journal *j;
    int r;

    assert_se(mkdtemp(t));
    assert_se(chdir(t) >= 0);

    setup();

    /* Seek to head, iterate down.
     */
    assert_ret(sd_journal_open_directory(&j, t, 0));
    assert_ret(sd_journal_seek_head(j));
    assert_ret(sd_journal_next(j));
    test_check_numbers_down(j, 4);
    sd_journal_close(j);

    /* Seek to tail, iterate up.
     */
    assert_ret(sd_journal_open_directory(&j, t, 0));
    assert_ret(sd_journal_seek_tail(j));
    assert_ret(sd_journal_previous(j));
    test_check_numbers_up(j, 4);
    sd_journal_close(j);

    /* Seek to tail, skip to head, iterate down.
     */
    assert_ret(sd_journal_open_directory(&j, t, 0));
    assert_ret(sd_journal_seek_tail(j));
    assert_ret(r = sd_journal_previous_skip(j, 4));
    assert_se(r == 4);
    test_check_numbers_down(j, 4);
    sd_journal_close(j);

    /* Seek to head, skip to tail, iterate up.
     */
    assert_ret(sd_journal_open_directory(&j, t, 0));
    assert_ret(sd_journal_seek_head(j));
    assert_ret(r = sd_journal_next_skip(j, 4));
    assert_se(r == 4);
    test_check_numbers_up(j, 4);
    sd_journal_close(j);

    log_info("Done...");

    if (arg_keep)
        log_info("Not removing %s", t);
    else {
        journal_directory_vacuum(".", 3000000, 0, 0, NULL);

        assert_se(rm_rf_dangerous(t, false, true, false) >= 0);
    }

    puts("------------------------------------------------------------");
}
static int process_journal_input(Uploader *u, int skip) {
    int r;

    r = sd_journal_next_skip(u->journal, skip);
    if (r < 0)
        return log_error_errno(r, "Failed to skip to next entry: %m");
    else if (r < skip)
        return 0;

    /* have data */
    u->entry_state = ENTRY_CURSOR;
    return start_upload(u, journal_input_callback, u);
}