<div>Hello team,<br></div><div><div class="gmail_quote"><div dir="ltr"><div><br></div><div>It would be great if someone can help me with a question about blocking write calls to a pipe and syscall restart logic. <br></div><div><br></div><div>From my experiments I can see that if the SA_RESTART flag is set, the kernel (?) restarts the write call if the process gets a signal. <br></div><div>The logic lives in the pipe.c file under the pipe_write function: <a href="https://elixir.bootlin.com/linux/v5.19/source/fs/pipe.c#L555" target="_blank">https://elixir.bootlin.com/linux/v5.19/source/fs/pipe.c#L555</a></div><div><br></div><div>But what I can't understand is how and where the kernel modifies the arguments of the write system call and where it collects the return values of all these restarts, thus the userspace caller ultimately sees the correct number of written bytes. <br></div><div><br></div><div>With strace I can see all that retries, for example:</div><div><br></div><div>write(1, ""..., 33554431) = 65536<br>write(1, ""..., 33488895) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)<br>write(1, ""..., 33488895) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)<br>write(1, ""..., 33488895) = ? ERESTARTSYS (To be restarted if SA_RESTART is set)<br>write(1, ""..., 33488895) = 33488895<br></div><div><br></div><div>Here there were 4 restarts (I sent 4 signals), 3 of them returned ERESTARTSYS and 2 were able to write to the pipe. Also for restarts strace shows the correct 3rd argument, which is decrementing. <br></div><div><br></div><div>The caller in the userspace in the end sees that it was able to write 65536+33488895 bytes. Which is correct and what the man 7 pipe describes.<br></div><div><br></div><div>My question is how and where it does that. I tried to dig in the kernel source code but can't find the place where this tracking occurs. <br></div><div><br></div><div><div><span lang="en"><span><span>Thank you for reading this far and for your willingness to help.</span></span></span><span><br></span></div><div><br><span></span></div></div><div>Have a great day,</div><div>BR, <br></div><div>Viacheslav<br></div><div><br></div></div>
</div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">Sent from Gmail Mobile</div>