From fe845b5e7653677f922070ab3c92abfd49bbb4e5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 17 Feb 2021 14:37:08 +0100 Subject: [PATCH] tree-wide: parse permyriads wherever we can MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Given that we now have a parser for permyriads, let's use it everywhere for greater accuracy. This means wherever we previously supported % and ‰, we now also support ‱. --- src/core/load-fragment.c | 12 ++++++------ src/home/homectl.c | 6 +++--- src/login/logind-user.c | 6 +++--- src/login/pam_systemd.c | 4 ++-- src/network/tc/tc-util.c | 8 ++++---- src/shared/bus-unit-util.c | 8 ++++---- 6 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 11836c0938..a1ab5f70eb 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -3593,13 +3593,13 @@ int config_parse_cpu_quota( return 0; } - r = parse_permille_unbounded(rvalue); + r = parse_permyriad_unbounded(rvalue); if (r <= 0) { log_syntax(unit, LOG_WARNING, filename, line, r, "Invalid CPU quota '%s', ignoring.", rvalue); return 0; } - c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 1000U; + c->cpu_quota_per_sec_usec = ((usec_t) r * USEC_PER_SEC) / 10000U; return 0; } @@ -3664,7 +3664,7 @@ int config_parse_memory_limit( bytes = CGROUP_LIMIT_MIN; else if (!isempty(rvalue) && !streq(rvalue, "infinity")) { - r = parse_permille(rvalue); + r = parse_permyriad(rvalue); if (r < 0) { r = parse_size(rvalue, 1024, &bytes); if (r < 0) { @@ -3672,7 +3672,7 @@ int config_parse_memory_limit( return 0; } } else - bytes = physical_memory_scale(r, 1000U); + bytes = physical_memory_scale(r, 10000U); if (bytes >= UINT64_MAX || (bytes <= 0 && !STR_IN_SET(lvalue, "MemorySwapMax", "MemoryLow", "MemoryMin", "DefaultMemoryLow", "DefaultMemoryMin"))) { @@ -3734,9 +3734,9 @@ int config_parse_tasks_max( return 0; } - r = parse_permille(rvalue); + r = parse_permyriad(rvalue); if (r >= 0) - *tasks_max = (TasksMax) { r, 1000U }; /* r‰ */ + *tasks_max = (TasksMax) { r, 10000U }; /* r‱ */ else { r = safe_atou64(rvalue, &v); if (r < 0) { diff --git a/src/home/homectl.c b/src/home/homectl.c index fa9d11e69d..98835327cd 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -1567,7 +1567,7 @@ static int resize_home(int argc, char *argv[], void *userdata) { (void) polkit_agent_open_if_enabled(arg_transport, arg_ask_password); if (arg_disk_size_relative != UINT64_MAX || - (argc > 2 && parse_percent(argv[2]) >= 0)) + (argc > 2 && parse_permyriad(argv[2]) >= 0)) return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Relative disk size specification currently not supported when resizing."); @@ -2653,7 +2653,7 @@ static int parse_argv(int argc, char *argv[]) { break; } - r = parse_permille(optarg); + r = parse_permyriad(optarg); if (r < 0) { r = parse_size(optarg, 1024, &arg_disk_size); if (r < 0) @@ -2670,7 +2670,7 @@ static int parse_argv(int argc, char *argv[]) { arg_disk_size_relative = UINT64_MAX; } else { /* Normalize to UINT32_MAX == 100% */ - arg_disk_size_relative = (uint64_t) r * UINT32_MAX / 1000U; + arg_disk_size_relative = (uint64_t) r * UINT32_MAX / 10000U; r = drop_from_identity("diskSize"); if (r < 0) diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 9b3ec07906..4406f36614 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -907,9 +907,9 @@ int config_parse_tmpfs_size( assert(data); /* First, try to parse as percentage */ - r = parse_permille(rvalue); - if (r > 0 && r < 1000) - *sz = physical_memory_scale(r, 1000U); + r = parse_permyriad(rvalue); + if (r > 0) + *sz = physical_memory_scale(r, 10000U); else { uint64_t k; diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 8e7a94db55..fce27262f1 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -334,9 +334,9 @@ static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, co return PAM_SUCCESS; } - r = parse_permille(limit); + r = parse_permyriad(limit); if (r >= 0) { - r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 1000U)); + r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", (uint32_t) ((uint64_t) r * UINT32_MAX) / 10000U); if (r < 0) return pam_bus_log_create_error(handle, r); diff --git a/src/network/tc/tc-util.c b/src/network/tc/tc-util.c index 3e10b50c96..1890e96164 100644 --- a/src/network/tc/tc-util.c +++ b/src/network/tc/tc-util.c @@ -57,17 +57,17 @@ int tc_time_to_tick(usec_t t, uint32_t *ret) { return 0; } -int parse_tc_percent(const char *s, uint32_t *percent) { +int parse_tc_percent(const char *s, uint32_t *ret_fraction) { int r; assert(s); - assert(percent); + assert(ret_fraction); - r = parse_permille(s); + r = parse_permyriad(s); if (r < 0) return r; - *percent = (double) r / 1000 * UINT32_MAX; + *ret_fraction = (double) r / 10000 * UINT32_MAX; return 0; } diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index 548dc57e3c..a1a253e801 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -539,7 +539,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons return 1; } - r = parse_permille(eq); + r = parse_permyriad(eq); if (r >= 0) { char *n; @@ -548,7 +548,7 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons * size can be determined server-side. */ n = strjoina(field, "Scale"); - r = sd_bus_message_append(m, "(sv)", n, "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 1000U)); + r = sd_bus_message_append(m, "(sv)", n, "u", (uint32_t) (((uint64_t) r * UINT32_MAX) / 10000U)); if (r < 0) return bus_log_create_error(r); @@ -565,14 +565,14 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons if (isempty(eq)) r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY); else { - r = parse_permille_unbounded(eq); + r = parse_permyriad_unbounded(eq); if (r == 0) return log_error_errno(SYNTHETIC_ERRNO(ERANGE), "CPU quota too small."); if (r < 0) return log_error_errno(r, "CPU quota '%s' invalid.", eq); - r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", (((uint64_t) r * USEC_PER_SEC) / 1000U)); + r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", (((uint64_t) r * USEC_PER_SEC) / 10000U)); } if (r < 0) -- 2.25.1