tree-wide: port various pieces of code over to UINT32_SCALE_FROM_PERMYRIAD()

This commit is contained in:
Lennart Poettering
2021-02-18 22:36:34 +01:00
parent 3b6e71ad03
commit 9cba32bcde
4 changed files with 7 additions and 6 deletions
+4 -3
View 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; \
+1 -1
View 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)
+1 -1
View 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);
+1 -1
View 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);