Re: [PATCH 10/10] daemon: fix type of `max_connections`
- From
Jeff King <peff@peff.net>
- Date
- Dec 1, 2024, 22:09 UTC
- Message-ID
- <20241201220952.GG145938@coredump.intra.peff.net>
- In-Reply-To
- <20241129-pks-sign-compare-v1-10-fc406b984bc9@pks.im>
On Fri, Nov 29, 2024 at 02:13:31PM +0100, Patrick Steinhardt wrote:
Show 14 quoted lines
> The `max_connections` type tracks how many children git-daemon(1) would > spawn at the same time. This value can be controlled via a command line > switch: if given a positive value we'll set that up as the limit. But > when given either zero or a negative value we don't enforce any limit at > all. > > But even when being passed a negative value we won't actually store it, > but normalize it to 0. Still, the variable used to store the config is > using a signed integer, which causes warnings when comparing the number > of accepted connections (`max_connections`) with the number of current > connections being handled (`live_children`). > > Adapt the type of `max_connections` such that the types of both > variables match.
Makes sense.
Show 14 quoted lines
> @@ -1315,10 +1313,11 @@ int cmd_main(int argc, const char **argv)
> continue;
> }
> if (skip_prefix(arg, "--max-connections=", &v)) {
> - if (strtol_i(v, 10, &max_connections))
> + int parsed_value;
> + if (strtol_i(v, 10, &parsed_value))
> die(_("invalid max-connections '%s', expecting an integer"), v);
> - if (max_connections < 0)
> - max_connections = 0; /* unlimited */
> + /* A negative value indicates unlimited children. */
> + max_connections = parsed_value < 0 ? 0 : parsed_value;
> continue;
> }If this were a common pattern, we might want some kind of helper that parses and clamps the negative values. But I suspect it's not common enough to merit that, and it's not too many extra lines of code to parse and assign separately. So this looks good.
-Peff