diff options
author | Vincent Ambo <mail@tazj.in> | 2018-10-09T09·01+0200 |
---|---|---|
committer | Vincent Ambo <github@tazj.in> | 2018-10-09T09·38+0200 |
commit | 61b2577a19715901048dd519d732caf3da90ea07 (patch) | |
tree | c20903a79b6c0350152d904928823f4d87d1c096 | |
parent | c1ab78c05a8d0274f80f17d1207fed26fdd88f12 (diff) |
fix: Refuse to write empty journald cursors and inform users
Exits from `persist_cursor` early if the cursor received from journald is an empty string. We don't currently know if this actually happens (please see #2 for more details), so an error message has been added that asks users to report this if it ever occurs.
-rw-r--r-- | src/main.rs | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index b8eeb6b9fb5c..ef28ee880465 100644 --- a/src/main.rs +++ b/src/main.rs @@ -494,6 +494,18 @@ fn receiver_loop(mut journal: Journal) -> Result<()> { /// is still being written, this will first write the cursor into a /// temporary file and then move it. fn persist_cursor(cursor: String) -> Result<()> { + // This code exists to aid in tracking down if there are other + // causes of issue #2 than what has already been taken care of. + // + // One theory is that journald (or the Rust library to interface + // with it) may occasionally return empty cursor strings. If this + // is ever the case, we would like to know about it. + if cursor.is_empty() { + error!("Received empty journald cursor position, refusing to persist!"); + error!("Please report this message at https://github.com/tazjin/journaldriver/issues/2"); + return Ok(()) + } + let mut file = File::create(&*CURSOR_TMP_FILE)?; write!(file, "{}", cursor).context("Failed to write cursor file")?; rename(&*CURSOR_TMP_FILE, &*CURSOR_FILE) |