diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-04-23 15:24:56 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-04-23 15:24:56 +0200 |
commit | 67962036f6c6cfd34828c1f1f1fbdc0018fb9898 (patch) | |
tree | 098f7af96e1e4ff2363ff8b5d098733c29cba5ca /src/basic/socket-util.c | |
parent | 644cb4cc7ac550242bfb65b6742d3bffb07d60e8 (diff) | |
download | systemd-67962036f6c6cfd34828c1f1f1fbdc0018fb9898.tar.gz |
basic/socket-util: put a limit on the loop to flush connections
Follow-up for #12346.
Diffstat (limited to 'src/basic/socket-util.c')
-rw-r--r-- | src/basic/socket-util.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/basic/socket-util.c b/src/basic/socket-util.c index cf2e08c2df..32a0d9c5d0 100644 --- a/src/basic/socket-util.c +++ b/src/basic/socket-util.c @@ -1219,6 +1219,10 @@ fallback: return (ssize_t) k; } +/* Put a limit on how many times will attempt to call accept4(). We loop + * only on "transient" errors, but let's make sure we don't loop forever. */ +#define MAX_FLUSH_ITERATIONS 1024 + int flush_accept(int fd) { struct pollfd pollfd = { @@ -1242,7 +1246,7 @@ int flush_accept(int fd) { * we can loop safely on transient errors below. */ return -ENOTTY; - for (;;) { + for (unsigned iteration = 0;; iteration++) { int cfd; r = poll(&pollfd, 1, 0); @@ -1255,6 +1259,10 @@ int flush_accept(int fd) { if (r == 0) return 0; + if (iteration >= MAX_FLUSH_ITERATIONS) + return log_debug_errno(SYNTHETIC_ERRNO(EBUSY), + "Failed to flush connections within " STRINGIFY(MAX_FLUSH_ITERATIONS) " iterations."); + cfd = accept4(fd, NULL, NULL, SOCK_NONBLOCK|SOCK_CLOEXEC); if (cfd < 0) { if (errno == EAGAIN) |