Skip to content

Commit

Permalink
Fix kmsgfile implementation to work on older kernels
Browse files Browse the repository at this point in the history
  • Loading branch information
archis-polyverse committed Jan 21, 2021
1 parent d8f2887 commit 6781e67
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "rmesg"
version = "1.0.10"
version = "1.0.11"
authors = ["Archis Gore <[email protected]>"]
edition = "2018"
license-file = "LICENSE"
Expand Down
31 changes: 22 additions & 9 deletions src/kmsgfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,20 @@ impl KMsgEntriesStream {
}
};

let lines_stream = Box::pin(tokioio::BufReader::new(file).lines());
// try to read from file
let mut lines_stream = Box::pin(tokioio::BufReader::new(file).lines());

//read a line
if let Err(e) = lines_stream.next_line().await {
return Err(RMesgError::DevKMsgFileOpenError(format!(
"Unable to read from file {}: {}",
path, e
)));
}

// create a new lines_stream with a new file
let lines_stream =
Box::pin(tokioio::BufReader::new(tokiofs::File::open(path.clone()).await?).lines());

Ok(Self { raw, lines_stream })
}
Expand Down Expand Up @@ -240,13 +253,13 @@ pub fn entry_from_line(line: &str) -> Result<Entry, EntryParsingError> {
lazy_static! {
static ref RE_ENTRY_WITH_TIMESTAMP: Regex = Regex::new(
r"(?x)^
[[:space:]]*(?P<faclevstr>[[:digit:]]*)[[:space:]]*,
# Sequence is a 64-bit integer: https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg
[[:space:]]*(?P<sequencenum>[[:digit:]]*)[[:space:]]*,
[[:space:]]*(?P<timestampstr>[[:digit:]]*)[[:space:]]*,
# Ignore everything until the semi-colon and then the semicolon
[[^;]]*;
(?P<message>.*)$"
[[:space:]]*(?P<faclevstr>[[:digit:]]*)[[:space:]]*,
# Sequence is a 64-bit integer: https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg
[[:space:]]*(?P<sequencenum>[[:digit:]]*)[[:space:]]*,
[[:space:]]*(?P<timestampstr>[[:digit:]]*)[[:space:]]*,
# Ignore everything until the semi-colon and then the semicolon
[[^;]]*;
(?P<message>.*)$"
)
.unwrap();
}
Expand Down Expand Up @@ -345,7 +358,7 @@ mod test {

// Don't clear the buffer. Poll every second.
let stream_result = KMsgEntriesStream::with_options(None, false).await;
assert!(stream_result.is_ok());
//assert!(stream_result.is_ok());

let mut stream = stream_result.unwrap();

Expand Down

0 comments on commit 6781e67

Please sign in to comment.