From: Yann Droneaud <ydroneaud@opteya.com>
To: Viacheslav Biriukov <v.v.biriukov@gmail.com>,
kernelnewbies@kernelnewbies.org
Subject: Re: pipe writes, ERESTARTSYS and SA_RESTART
Date: Thu, 4 Aug 2022 20:38:06 +0200 [thread overview]
Message-ID: <45f14059-2f16-de4b-75f4-3fcdc141b29a@opteya.com> (raw)
In-Reply-To: <CAPKsgQw00KBTo_q7CVD59Gw4rHZ-tTFBpPiOR6M1t1_Xp4AY_g@mail.gmail.com>
Hi,
Le 04/08/2022 à 20:01, Viacheslav Biriukov a écrit :
>
> 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.
>
> With strace I can see all that retries, for example:
>
> write(1, ""..., 33554431) = 65536
> write(1, ""..., 33488895) = ? ERESTARTSYS (To be
> restarted if SA_RESTART is set)
> write(1, ""..., 33488895) = ? ERESTARTSYS (To be
> restarted if SA_RESTART is set)
> write(1, ""..., 33488895) = ? ERESTARTSYS (To be
> restarted if SA_RESTART is set)
> write(1, ""..., 33488895) = 33488895
>
> 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.
>
> 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.
>
> 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.
>
It doesn't. SA_RESTART is only meant to retry syscall that would have
returned EINTR.
In such case, there's no tracking to do, because nothing was actually
written, so the syscall can be restarted with the same parameters.
Regards.
--
Yann Droneaud
OPTEYA
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
next prev parent reply other threads:[~2022-08-04 18:38 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAPKsgQzW2uuQrL0amv+hBhVi612mJdQGgpWP33biyf7T3YMKQA@mail.gmail.com>
2022-08-04 18:01 ` pipe writes, ERESTARTSYS and SA_RESTART Viacheslav Biriukov
2022-08-04 18:38 ` Yann Droneaud [this message]
2022-08-04 20:30 ` Viacheslav Biriukov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=45f14059-2f16-de4b-75f4-3fcdc141b29a@opteya.com \
--to=ydroneaud@opteya.com \
--cc=kernelnewbies@kernelnewbies.org \
--cc=v.v.biriukov@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox