Skip to content

Commit

Permalink
Add function to jump to beginning of current boot
Browse files Browse the repository at this point in the history
  • Loading branch information
kloenk committed Jul 20, 2022
1 parent 237fbe0 commit 7113dae
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub use std::io::{Error, Result};
use std::mem::MaybeUninit;

use libsystemd_sys as ffi;

Expand Down Expand Up @@ -34,3 +35,14 @@ pub mod reader;

#[path = "journal_writer.rs"]
pub mod writer;

pub struct Id(pub(crate) libsystemd_sys::id128::sd_id128_t);

impl Id {
pub fn get_boot_id() -> Result<Self> {
let mut id = MaybeUninit::uninit();

unsafe { ffi_result(ffi::id128::sd_id128_get_boot(id.as_mut_ptr())) }?;
Ok(Self(unsafe { id.assume_init() }))
}
}
7 changes: 7 additions & 0 deletions src/reader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ pub enum JournalSeek {
Head,
Tail,
Cursor(String),
/// Seek to beginning of the current boot process
ThisBoot,
}

/// Wakeup event types
Expand Down Expand Up @@ -270,6 +272,11 @@ impl JournalReader {
::std::ffi::CString::new(cur)?.as_ptr(),
))?
},
JournalSeek::ThisBoot => {
let boot_id = crate::Id::get_boot_id()?;

unsafe { ffi_result(ffi::sd_journal_seek_monotonic_usec(self.j, boot_id.0, 0)) }?
}
};

Ok(())
Expand Down

0 comments on commit 7113dae

Please sign in to comment.