From c08c5c089549d138931185e80b0502d24d7bdcfc Mon Sep 17 00:00:00 2001 From: Rodolphe Breard Date: Tue, 17 Sep 2019 17:43:11 +0200 Subject: [PATCH] Retry read if interrupted https://doc.rust-lang.org/std/io/trait.Read.html#tymethod.read --- opensmtpd/src/input/stdin.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/opensmtpd/src/input/stdin.rs b/opensmtpd/src/input/stdin.rs index 20860eb..0828113 100644 --- a/opensmtpd/src/input/stdin.rs +++ b/opensmtpd/src/input/stdin.rs @@ -10,7 +10,7 @@ use crate::entry::Entry; use crate::errors::Error; use crate::input::FilterInput; use std::default::Default; -use std::io::{self, Read}; +use std::io::{self, ErrorKind, Read}; use std::str; const BUFFER_SIZE: usize = 4096; @@ -40,7 +40,17 @@ impl FilterInput for StdIn { force_read = false; // Read stdin in self.buffer self.buffer.copy_from_slice(&[0; BUFFER_SIZE]); - let len = self.stdin.read(&mut self.buffer)?; + let len = match self.stdin.read(&mut self.buffer) { + Ok(n) => n, + Err(e) => match e.kind() { + ErrorKind::Interrupted => { + continue; + } + _ => { + return Err(e.into()); + } + }, + }; if len == 0 { continue; }