mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Rich Felker <dalias@libc.org>
To: Waldek Kozaczuk <jwkozaczuk@gmail.com>
Cc: musl@lists.openwall.com
Subject: Re: [musl] netlink.c: missing handling of EAGAIN and EWOULDBLOCK
Date: Mon, 13 Jun 2022 13:08:49 -0400	[thread overview]
Message-ID: <20220613170849.GG7074@brightrain.aerifal.cx> (raw)
In-Reply-To: <CAL9cFfNfefkc+1uNtk_oTxL3uLX46e1me98UgB8XNdQaZ6PdJA@mail.gmail.com>

On Mon, Jun 13, 2022 at 11:41:57AM -0400, Waldek Kozaczuk wrote:
> Hi,
> 
> Very recently we implemented minimal rnetlink support on OSv side which
> allowed us to finally switch to the netlink-based implementation of
> getifaddrs() and if_nameindex().
> 
> However, I noticed that the function __netlink_enumerate() in
> https://github.com/ifduyue/musl/blob/master/src/network/netlink.c uses
> MSG_DONTWAIT flag when calling recv() which may fail with EAGAIN or
> EWOULDBLOCK and there is no error/retry handling for that. I actually saw
> both functions fail occasionally on OSv.
> 
> One way to fix is to add missing error handling. But another simpler
> solution is to stop using MSG_DONTWAIT altogether and force recv() to
> block. In other words, the line:
> 
> r = recv(fd, u.buf, sizeof(u.buf), MSG_DONTWAIT);
> 
> should change to:
> 
> r = recv(fd, u.buf, sizeof(u.buf), 0);
> 
> For time being we are applying a header trick on OSv side to re-define
> MSG_DONTWAIT as 0 when compiling those specific musl sources.

Thanks! I'll try to track this down. One concern is that I'm not sure
how MSG_DONTWAIT is supposed to interact with "short reads" -- is it
needed (for netlink) to prevent blocking when some data has been read
but there is still buffer space for more?

On a related issue, I'm pretty sure the netlink API doesn't allow for
partial reads with some data remaining buffered on the kernel side,
but we should probably verify that too.

Rich

  reply	other threads:[~2022-06-13 17:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-13 15:41 Waldek Kozaczuk
2022-06-13 17:08 ` Rich Felker [this message]
2022-06-13 18:38   ` Waldek Kozaczuk
2022-06-14  5:19   ` Timo Teras

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=20220613170849.GG7074@brightrain.aerifal.cx \
    --to=dalias@libc.org \
    --cc=jwkozaczuk@gmail.com \
    --cc=musl@lists.openwall.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).