static gboolean _add_poll_events(JournalReader *self) { gint fd = journald_get_fd(self->journal); if (fd < 0) { msg_error("Error setting up journal polling, journald_get_fd() returned failure", evt_tag_errno("error", errno)); journald_close(self->journal); return FALSE; } self->poll_events = poll_fd_events_new(fd); poll_events_set_callback(self->poll_events, _io_process_async_input, self); return TRUE; }
void __test_fd_handling(Journald *journald) { gint fd = journald_get_fd(journald); journald_process(journald); task_called = FALSE; poll_triggered = FALSE; struct iv_task add_entry_task; struct iv_fd fd_to_poll; struct iv_timer stop_timer; IV_TASK_INIT(&add_entry_task); add_entry_task.cookie = journald; add_entry_task.handler = add_mock_entries; IV_FD_INIT(&fd_to_poll); fd_to_poll.fd = fd; fd_to_poll.cookie = journald; fd_to_poll.handler_in = handle_new_entry; iv_validate_now(); IV_TIMER_INIT(&stop_timer); stop_timer.cookie = NULL; stop_timer.expires = iv_now; stop_timer.expires.tv_sec++; stop_timer.handler = stop_timer_expired; iv_task_register(&add_entry_task); iv_fd_register(&fd_to_poll); iv_timer_register(&stop_timer); iv_main(); assert_true(poll_triggered, ASSERTION_ERROR("Poll event isn't triggered")); }