コード例 #1
0
ファイル: journal.c プロジェクト: daurnimator/lua-systemd
static int journal_get_events (lua_State *L) {
	sd_journal *j = check_journal(L, 1);
	int err = sd_journal_get_events(j);
	if (err < 0) return handle_error(L, -err);
	lua_pushinteger(L, err);
	return 1;
}
コード例 #2
0
int open_journal_for_upload(Uploader *u,
                            sd_journal *j,
                            const char *cursor,
                            bool after_cursor,
                            bool follow) {
    int fd, r, events;

    u->journal = j;

    sd_journal_set_data_threshold(j, 0);

    if (follow) {
        fd = sd_journal_get_fd(j);
        if (fd < 0)
            return log_error_errno(fd, "sd_journal_get_fd failed: %m");

        events = sd_journal_get_events(j);

        r = sd_journal_reliable_fd(j);
        assert(r >= 0);
        if (r > 0)
            u->timeout = -1;
        else
            u->timeout = JOURNAL_UPLOAD_POLL_TIMEOUT;

        r = sd_event_add_io(u->events, &u->input_event,
                            fd, events, dispatch_journal_input, u);
        if (r < 0)
            return log_error_errno(r, "Failed to register input event: %m");

        log_debug("Listening for journal events on fd:%d, timeout %d",
                  fd, u->timeout == (uint64_t) -1 ? -1 : (int) u->timeout);
    } else
        log_debug("Not listening for journal events.");

    if (cursor) {
        r = sd_journal_seek_cursor(j, cursor);
        if (r < 0) {
            return log_error_errno(r, "Failed to seek to cursor %s: %m",
                                   cursor);
        }
    }

    return process_journal_input(u, 1 + !!after_cursor);
}