diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-01-15 11:37:49 +0100 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-01-17 08:13:09 +0100 |
commit | b0a94df9631d721699ba90fc7e692b0f51a05770 (patch) | |
tree | 66f7d30e43a47edfa0663e902d745b467d23e260 /src/login/logind-user.c | |
parent | ddee3ada467d25e77fef3434fbed7191ff0c1a34 (diff) | |
download | systemd-b0a94df9631d721699ba90fc7e692b0f51a05770.tar.gz |
logind: use loop instead of repeated code
https://github.com/systemd/systemd/pull/14096#discussion_r350953689
Diffstat (limited to 'src/login/logind-user.c')
-rw-r--r-- | src/login/logind-user.c | 44 |
1 files changed, 16 insertions, 28 deletions
diff --git a/src/login/logind-user.c b/src/login/logind-user.c index fdc6448a65..9ceb33cde9 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -405,35 +405,23 @@ static int user_update_slice(User *u) { if (r < 0) return bus_log_create_error(r); - if (u->user_record->tasks_max != UINT64_MAX) { - r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", u->user_record->tasks_max); - if (r < 0) - return bus_log_create_error(r); - } - - if (u->user_record->memory_max != UINT64_MAX) { - r = sd_bus_message_append(m, "(sv)", "MemoryMax", "t", u->user_record->memory_max); - if (r < 0) - return bus_log_create_error(r); - } - - if (u->user_record->memory_high != UINT64_MAX) { - r = sd_bus_message_append(m, "(sv)", "MemoryHigh", "t", u->user_record->memory_high); - if (r < 0) - return bus_log_create_error(r); - } - - if (u->user_record->cpu_weight != UINT64_MAX) { - r = sd_bus_message_append(m, "(sv)", "CPUWeight", "t", u->user_record->cpu_weight); - if (r < 0) - return bus_log_create_error(r); - } + const struct { + const char *name; + uint64_t value; + } settings[] = { + { "TasksMax", u->user_record->tasks_max }, + { "MemoryMax", u->user_record->memory_max }, + { "MemoryHigh", u->user_record->memory_high }, + { "CPUWeight", u->user_record->cpu_weight }, + { "IOWeight", u->user_record->io_weight }, + }; - if (u->user_record->io_weight != UINT64_MAX) { - r = sd_bus_message_append(m, "(sv)", "IOWeight", "t", u->user_record->io_weight); - if (r < 0) - return bus_log_create_error(r); - } + for (size_t i = 0; i < ELEMENTSOF(settings); i++) + if (settings[i].value != UINT64_MAX) { + r = sd_bus_message_append(m, "(sv)", settings[i].name, "t", settings[i].value); + if (r < 0) + return bus_log_create_error(r); + } r = sd_bus_message_close_container(m); if (r < 0) |