From 61b2577a19715901048dd519d732caf3da90ea07 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 9 Oct 2018 11:01:33 +0200 Subject: 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. --- src/main.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index b8eeb6b9fb..ef28ee8804 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) -- cgit 1.4.1