diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-06-08 19:25:38 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-06-14 19:50:38 +0200 |
commit | 9184ca48ea43e009cd6f379f319926109a30926c (patch) | |
tree | 0db1fa083fb240966e47d621d861cd7cb45501e6 /src/core | |
parent | d9ab2bcf0591b496f1a4750c7ff790b33f9c7e59 (diff) |
util-lib: introduce parse_percent() for parsing percent specifications
And port a couple of users over to it.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/load-fragment.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 17c72aed88..fe60bee789 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -2774,7 +2774,7 @@ int config_parse_cpu_quota( void *userdata) { CGroupContext *c = data; - double percent; + int r; assert(filename); assert(lvalue); @@ -2785,18 +2785,13 @@ int config_parse_cpu_quota( return 0; } - if (!endswith(rvalue, "%")) { - log_syntax(unit, LOG_ERR, filename, line, 0, "CPU quota '%s' not ending in '%%'. Ignoring.", rvalue); + r = parse_percent(rvalue); + if (r <= 0) { + log_syntax(unit, LOG_ERR, filename, line, r, "CPU quota '%s' invalid. Ignoring.", rvalue); return 0; } - if (sscanf(rvalue, "%lf%%", &percent) != 1 || percent <= 0) { - log_syntax(unit, LOG_ERR, filename, line, 0, "CPU quota '%s' invalid. Ignoring.", rvalue); - return 0; - } - - c->cpu_quota_per_sec_usec = (usec_t) (percent * USEC_PER_SEC / 100); - + c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 100U; return 0; } |