@@ -14,6 +14,7 @@ use std::ffi::CString;
14
14
use std:: io:: ErrorKind :: InvalidData ;
15
15
use std:: mem:: MaybeUninit ;
16
16
use std:: os:: raw:: c_void;
17
+ use std:: os:: unix:: io:: AsRawFd ;
17
18
use std:: u64;
18
19
use std:: { fmt, io, ptr, result, slice, time} ;
19
20
@@ -384,6 +385,20 @@ impl Journal {
384
385
}
385
386
386
387
impl JournalRef {
388
+ /// Returns a file descriptor a file descriptor that may be
389
+ /// asynchronously polled in an external event loop and is signaled as
390
+ /// soon as the journal changes, because new entries or files were added,
391
+ /// rotation took place, or files have been deleted, and similar. The
392
+ /// file descriptor is suitable for usage in poll(2).
393
+ ///
394
+ /// This corresponds to [`sd_journal_get_fd`]
395
+ ///
396
+ /// [`sd_journal_get_fd`]: https://www.freedesktop.org/software/systemd/man/sd_journal_get_fd.html
397
+ #[ inline]
398
+ pub fn fd ( & self ) -> Result < c_int > {
399
+ Ok ( sd_try ! ( ffi:: sd_journal_get_fd( self . as_ptr( ) ) ) )
400
+ }
401
+
387
402
/// Fields that are longer that this number of bytes _may_ be truncated when retrieved by this [`Journal`]
388
403
/// instance.
389
404
///
@@ -760,3 +775,10 @@ impl JournalRef {
760
775
Ok ( self )
761
776
}
762
777
}
778
+
779
+ impl AsRawFd for JournalRef {
780
+ #[ inline]
781
+ fn as_raw_fd ( & self ) -> c_int {
782
+ self . fd ( ) . unwrap ( )
783
+ }
784
+ }
0 commit comments