/[pkg-src]/trunk/systemd/patches/systemd-242-socket-util-put-a-limit-on-the-loop-to-flush-connections.patch |
Contents of /trunk/systemd/patches/systemd-242-socket-util-put-a-limit-on-the-loop-to-flush-connections.patch
Parent Directory | Revision Log
Revision 3368 -
(show annotations)
(download)
Tue Jul 9 11:20:22 2019 UTC (5 years, 2 months ago) by niro
File size: 1724 byte(s)
Tue Jul 9 11:20:22 2019 UTC (5 years, 2 months ago) by niro
File size: 1724 byte(s)
-added systemd-242 upstream patches
1 | From 67962036f6c6cfd34828c1f1f1fbdc0018fb9898 Mon Sep 17 00:00:00 2001 |
2 | From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= <zbyszek@in.waw.pl> |
3 | Date: Tue, 23 Apr 2019 15:24:56 +0200 |
4 | Subject: [PATCH] basic/socket-util: put a limit on the loop to flush |
5 | connections |
6 | |
7 | Follow-up for #12346. |
8 | --- |
9 | src/basic/socket-util.c | 10 +++++++++- |
10 | 1 file changed, 9 insertions(+), 1 deletion(-) |
11 | |
12 | diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c |
13 | index cf2e08c2df8..32a0d9c5d06 100644 |
14 | --- a/src/basic/socket-util.c |
15 | +++ b/src/basic/socket-util.c |
16 | @@ -1219,6 +1219,10 @@ ssize_t next_datagram_size_fd(int fd) { |
17 | return (ssize_t) k; |
18 | } |
19 | |
20 | +/* Put a limit on how many times will attempt to call accept4(). We loop |
21 | + * only on "transient" errors, but let's make sure we don't loop forever. */ |
22 | +#define MAX_FLUSH_ITERATIONS 1024 |
23 | + |
24 | int flush_accept(int fd) { |
25 | |
26 | struct pollfd pollfd = { |
27 | @@ -1242,7 +1246,7 @@ int flush_accept(int fd) { |
28 | * we can loop safely on transient errors below. */ |
29 | return -ENOTTY; |
30 | |
31 | - for (;;) { |
32 | + for (unsigned iteration = 0;; iteration++) { |
33 | int cfd; |
34 | |
35 | r = poll(&pollfd, 1, 0); |
36 | @@ -1255,6 +1259,10 @@ int flush_accept(int fd) { |
37 | if (r == 0) |
38 | return 0; |
39 | |
40 | + if (iteration >= MAX_FLUSH_ITERATIONS) |
41 | + return log_debug_errno(SYNTHETIC_ERRNO(EBUSY), |
42 | + "Failed to flush connections within " STRINGIFY(MAX_FLUSH_ITERATIONS) " iterations."); |
43 | + |
44 | cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC); |
45 | if (cfd < 0) { |
46 | if (errno == EAGAIN) |