util-lib: add parse_percent_unbounded() for percentages over 100% (#3886)

This permits CPUQuota to accept greater values as documented.
This commit is contained in:
David Michael 2016-08-04 04:09:54 -07:00 committed by Lennart Poettering
parent 19c8201744
commit 5124866d73
4 changed files with 13 additions and 5 deletions

View file

@ -533,7 +533,7 @@ int parse_fractional_part_u(const char **p, size_t digits, unsigned *res) {
return 0;
}
int parse_percent(const char *p) {
int parse_percent_unbounded(const char *p) {
const char *pc, *n;
unsigned v;
int r;
@ -546,8 +546,15 @@ int parse_percent(const char *p) {
r = safe_atou(n, &v);
if (r < 0)
return r;
if (v > 100)
return -ERANGE;
return (int) v;
}
int parse_percent(const char *p) {
int v = parse_percent_unbounded(p);
if (v > 100)
return -ERANGE;
return v;
}

View file

@ -106,4 +106,5 @@ int safe_atod(const char *s, double *ret_d);
int parse_fractional_part_u(const char **s, size_t digits, unsigned *res);
int parse_percent_unbounded(const char *p);
int parse_percent(const char *p);

View file

@ -2903,7 +2903,7 @@ int config_parse_cpu_quota(
return 0;
}
r = parse_percent(rvalue);
r = parse_percent_unbounded(rvalue);
if (r <= 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "CPU quota '%s' invalid. Ignoring.", rvalue);
return 0;

View file

@ -84,7 +84,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
if (isempty(eq))
r = sd_bus_message_append(m, "sv", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
else {
r = parse_percent(eq);
r = parse_percent_unbounded(eq);
if (r <= 0) {
log_error_errno(r, "CPU quota '%s' invalid.", eq);
return -EINVAL;