Skip to content

Commit 6781e67

Browse files
Fix kmsgfile implementation to work on older kernels
1 parent d8f2887 commit 6781e67

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "rmesg"
3-
version = "1.0.10"
3+
version = "1.0.11"
44
authors = ["Archis Gore <archis@polyverse.com>"]
55
edition = "2018"
66
license-file = "LICENSE"

src/kmsgfile.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,20 @@ impl KMsgEntriesStream {
144144
}
145145
};
146146

147-
let lines_stream = Box::pin(tokioio::BufReader::new(file).lines());
147+
// try to read from file
148+
let mut lines_stream = Box::pin(tokioio::BufReader::new(file).lines());
149+
150+
//read a line
151+
if let Err(e) = lines_stream.next_line().await {
152+
return Err(RMesgError::DevKMsgFileOpenError(format!(
153+
"Unable to read from file {}: {}",
154+
path, e
155+
)));
156+
}
157+
158+
// create a new lines_stream with a new file
159+
let lines_stream =
160+
Box::pin(tokioio::BufReader::new(tokiofs::File::open(path.clone()).await?).lines());
148161

149162
Ok(Self { raw, lines_stream })
150163
}
@@ -240,13 +253,13 @@ pub fn entry_from_line(line: &str) -> Result<Entry, EntryParsingError> {
240253
lazy_static! {
241254
static ref RE_ENTRY_WITH_TIMESTAMP: Regex = Regex::new(
242255
r"(?x)^
243-
[[:space:]]*(?P<faclevstr>[[:digit:]]*)[[:space:]]*,
244-
# Sequence is a 64-bit integer: https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg
245-
[[:space:]]*(?P<sequencenum>[[:digit:]]*)[[:space:]]*,
246-
[[:space:]]*(?P<timestampstr>[[:digit:]]*)[[:space:]]*,
247-
# Ignore everything until the semi-colon and then the semicolon
248-
[[^;]]*;
249-
(?P<message>.*)$"
256+
[[:space:]]*(?P<faclevstr>[[:digit:]]*)[[:space:]]*,
257+
# Sequence is a 64-bit integer: https://www.kernel.org/doc/Documentation/ABI/testing/dev-kmsg
258+
[[:space:]]*(?P<sequencenum>[[:digit:]]*)[[:space:]]*,
259+
[[:space:]]*(?P<timestampstr>[[:digit:]]*)[[:space:]]*,
260+
# Ignore everything until the semi-colon and then the semicolon
261+
[[^;]]*;
262+
(?P<message>.*)$"
250263
)
251264
.unwrap();
252265
}
@@ -345,7 +358,7 @@ mod test {
345358

346359
// Don't clear the buffer. Poll every second.
347360
let stream_result = KMsgEntriesStream::with_options(None, false).await;
348-
assert!(stream_result.is_ok());
361+
//assert!(stream_result.is_ok());
349362

350363
let mut stream = stream_result.unwrap();
351364

0 commit comments

Comments
 (0)