Fix signal-resilient read loop

Better termination condition for signal-resilient read loop.