From: Lennart Poettering Date: Wed, 17 Feb 2021 16:03:52 +0000 (+0100) Subject: tree-wide: port various pieces of code over to UINT32_SCALE_FROM_PERMYRIAD() X-Git-Tag: v248-rc1~46^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=9cba32bcde31033bffbac6d53c028f8f95212293;p=thirdparty%2Fsystemd.git tree-wide: port various pieces of code over to UINT32_SCALE_FROM_PERMYRIAD() --- diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c index 6652c212f19..e22233d6ff9 100644 --- a/src/core/dbus-cgroup.c +++ b/src/core/dbus-cgroup.c @@ -16,6 +16,7 @@ #include "fileio.h" #include "limits-util.h" #include "path-util.h" +#include "percent-util.h" BUS_DEFINE_PROPERTY_GET(bus_property_get_tasks_max, "t", TasksMax, tasks_max_resolve); @@ -704,10 +705,10 @@ static int bus_cgroup_set_boolean( /* Prepare to chop off suffix */ \ assert_se(endswith(name, "Scale")); \ \ - uint32_t scaled = DIV_ROUND_UP((uint64_t) raw * 1000, (uint64_t) UINT32_MAX); \ - unit_write_settingf(u, flags, name, "%.*s=%" PRIu32 ".%" PRIu32 "%%", \ + int scaled = UINT32_SCALE_TO_PERMYRIAD(raw); \ + unit_write_settingf(u, flags, name, "%.*s=%i.%02i%%", \ (int)(strlen(name) - strlen("Scale")), name, \ - scaled / 10, scaled % 10); \ + scaled / 100, scaled % 100); \ } \ \ return 1; \ diff --git a/src/home/homectl.c b/src/home/homectl.c index dbe5c3af209..d59dfb1f609 100644 --- a/src/home/homectl.c +++ b/src/home/homectl.c @@ -2671,7 +2671,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 / 10000U; + arg_disk_size_relative = UINT32_SCALE_FROM_PERMYRIAD(r); r = drop_from_identity("diskSize"); if (r < 0) diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 3fc4f43d288..a23200b3b57 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -337,7 +337,7 @@ static int append_session_memory_max(pam_handle_t *handle, sd_bus_message *m, co r = parse_permyriad(limit); if (r >= 0) { - r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", (uint32_t) ((uint64_t) r * UINT32_MAX) / 10000U); + r = sd_bus_message_append(m, "(sv)", "MemoryMaxScale", "u", UINT32_SCALE_FROM_PERMYRIAD(r)); if (r < 0) return pam_bus_log_create_error(handle, r); diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c index a6e5e741326..27c8eb915fb 100644 --- a/src/shared/bus-unit-util.c +++ b/src/shared/bus-unit-util.c @@ -549,7 +549,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) / 10000U)); + r = sd_bus_message_append(m, "(sv)", n, "u", UINT32_SCALE_FROM_PERMYRIAD(r)); if (r < 0) return bus_log_create_error(r);