libsystemd-network: use recv(..., 0) instead of read(...) (#3317)

According to recv(2) these should be the same, but that is not true.
Passing a buffer of length 0 to read is defined to be a noop according
to read(2), but passing a buffer of length 0 to recv will discard the
pending pacet.

We can easily hit this as we allocate our buffer size depending on
the size of the incoming packet (using FIONREAD). As pointed out in
issue #3299 simply sending an empty UDP packet to the DHCP client
port will trigger a busy loop in networkd as we are polling on the
socket but never discarding the empty packet.

This reverts ad5ae47a0d but fixes the
same issue.
This commit is contained in:
Tom Gundersen 2016-05-21 23:00:32 +02:00 committed by Evgeny Vereshchagin
parent 3da48d7aa9
commit cf447cb62d
2 changed files with 2 additions and 5 deletions

View File

@ -1636,14 +1636,11 @@ static int client_receive_message_udp(
if (buflen < 0)
return buflen;
if (buflen == 0)
buflen = 1;
message = malloc0(buflen);
if (!message)
return -ENOMEM;
len = read(fd, message, buflen);
len = recv(fd, message, buflen, 0);
if (len < 0) {
if (errno == EAGAIN || errno == EINTR)
return 0;

View File

@ -917,7 +917,7 @@ static int client_receive_message(sd_event_source *s, int fd, uint32_t revents,
if (!message)
return -ENOMEM;
len = read(fd, message, buflen);
len = recv(fd, message, buflen, 0);
if (len < 0) {
if (errno == EAGAIN || errno == EINTR)
return 0;