Skip to content

Implement AsRawFd for JournalRef #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 5, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/journal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use std::ffi::CString;
use std::io::ErrorKind::InvalidData;
use std::mem::MaybeUninit;
use std::os::raw::c_void;
use std::os::unix::io::AsRawFd;
use std::u64;
use std::{fmt, io, ptr, result, slice, time};

Expand Down Expand Up @@ -384,6 +385,20 @@ impl Journal {
}

impl JournalRef {
/// Returns a file descriptor a file descriptor that may be
/// asynchronously polled in an external event loop and is signaled as
/// soon as the journal changes, because new entries or files were added,
/// rotation took place, or files have been deleted, and similar. The
/// file descriptor is suitable for usage in poll(2).
///
/// This corresponds to [`sd_journal_get_fd`]
///
/// [`sd_journal_get_fd`]: https://www.freedesktop.org/software/systemd/man/sd_journal_get_fd.html
#[inline]
pub fn fd(&self) -> Result<c_int> {
Ok(sd_try!(ffi::sd_journal_get_fd(self.as_ptr())))
}

/// Fields that are longer that this number of bytes _may_ be truncated when retrieved by this [`Journal`]
/// instance.
///
Expand Down Expand Up @@ -760,3 +775,10 @@ impl JournalRef {
Ok(self)
}
}

impl AsRawFd for JournalRef {
#[inline]
fn as_raw_fd(&self) -> c_int {
self.fd().unwrap()
}
}