From 8d83e0c20ec50ea6b9da197a977f02ad140fc5e8 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 8 Apr 2024 01:35:24 +0800 Subject: [PATCH 1/2] core/service: use GREEDY_REALLOC_APPEND --- src/core/service.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/core/service.c b/src/core/service.c index 61b2b9a955..21f8b47a0c 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1405,8 +1405,8 @@ static int service_collect_fds( UNIT_FOREACH_DEPENDENCY(u, UNIT(s), UNIT_ATOM_TRIGGERED_BY) { _cleanup_free_ int *cfds = NULL; - Socket *sock; int cn_fds; + Socket *sock; sock = SOCKET(u); if (!sock) @@ -1422,18 +1422,8 @@ static int service_collect_fds( if (!rfds) { rfds = TAKE_PTR(cfds); rn_socket_fds = cn_fds; - } else { - int *t; - - t = reallocarray(rfds, rn_socket_fds + cn_fds, sizeof(int)); - if (!t) - return -ENOMEM; - - memcpy(t + rn_socket_fds, cfds, cn_fds * sizeof(int)); - - rfds = t; - rn_socket_fds += cn_fds; - } + } else if (!GREEDY_REALLOC_APPEND(rfds, rn_socket_fds, cfds, cn_fds)) + return -ENOMEM; r = strv_extend_n(&rfd_names, socket_fdname(sock), cn_fds); if (r < 0) From 6b014a2ac4b3cd27b71bcbee18395a07c6ef4dad Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 8 Apr 2024 01:49:33 +0800 Subject: [PATCH 2/2] man/systemd.socket: be explicit that MaxConnectionsPerSource=0 means disabled --- man/systemd.socket.xml | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/man/systemd.socket.xml b/man/systemd.socket.xml index 3531ffaa17..8dc7641dde 100644 --- a/man/systemd.socket.xml +++ b/man/systemd.socket.xml @@ -460,14 +460,10 @@ MaxConnections= - The maximum number of connections to - simultaneously run services instances for, when - is set. If more concurrent - connections are coming in, they will be refused until at least - one existing connection is terminated. This setting has no - effect on sockets configured with - or datagram sockets. Defaults to - 64. + The maximum number of connections to simultaneously run services instances for, when + is set. If more concurrent connections are coming in, they will be refused + until at least one existing connection is terminated. This setting has no effect on sockets configured + with or datagram sockets. Defaults to 64. @@ -475,7 +471,7 @@ The maximum number of connections for a service per source IP address (in case of IPv4/IPv6), per source CID (in case of AF_VSOCK), or source UID (in case of AF_UNIX). This is very similar to the MaxConnections= - directive above. Disabled by default. + directive above. Defaults to 0, i.e. disabled.