]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: port various pieces of code over to UINT32_SCALE_FROM_PERMYRIAD()
authorLennart Poettering <lennart@poettering.net>
Wed, 17 Feb 2021 16:03:52 +0000 (17:03 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 18 Feb 2021 21:36:34 +0000 (22:36 +0100)
src/core/dbus-cgroup.c
src/home/homectl.c
src/login/pam_systemd.c
src/shared/bus-unit-util.c

index 6652c212f19bde5c9321770b45e2f93c28a9d891..e22233d6ff91f0b1366ee178ef1a847c47b8deb6 100644 (file)
@@ -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;                                               \
index dbe5c3af209df3be6774286c7bb267f1cb74df6c..d59dfb1f609dbe40d129d84d828b0f2bd80c4150 100644 (file)
@@ -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)
index 3fc4f43d288a9ca98db1a22a5bf87876a902fd20..a23200b3b579b17dbd3d7c8d3a1109aa546a295c 100644 (file)
@@ -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);
 
index a6e5e741326e92aa96ce8916957abe2a4a5c32b4..27c8eb915fb9f1906a42853f4c582d8d8ed11760 100644 (file)
@@ -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);