diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-05-29 10:17:43 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2019-05-29 17:02:24 +0200 |
commit | 1f57a176af5152d05719bf43740e87a47e37af50 (patch) | |
tree | 1955788da6982fbdf205654c138d63b669127730 /src/shared | |
parent | systemctl: present CPUAffinity mask as a list of CPU index ranges (diff) | |
download | systemd-1f57a176af5152d05719bf43740e87a47e37af50.tar.xz systemd-1f57a176af5152d05719bf43740e87a47e37af50.zip |
shared/cpu-set-util: only force range printing one time
The idea is to have at least one range to make the new format clearly
distinguishable from the old. But it is enough to just do it once.
In particular, in case the affinity would be specified like 0, 2, 4, 6…,
this gives much shorter output.
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/cpu-set-util.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/shared/cpu-set-util.c b/src/shared/cpu-set-util.c index 13a43dc6cc..7c8f4d42d2 100644 --- a/src/shared/cpu-set-util.c +++ b/src/shared/cpu-set-util.c @@ -55,7 +55,10 @@ char *cpu_set_to_range_string(const CPUSet *set) { if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(unsigned))) return NULL; - r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end); + if (range_end > range_start || len == 0) + r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end); + else + r = sprintf(str + len, len > 0 ? " %d" : "%d", range_start); assert_se(r > 0); len += r; } @@ -64,7 +67,10 @@ char *cpu_set_to_range_string(const CPUSet *set) { if (!GREEDY_REALLOC(str, allocated, len + 2 + 2 * DECIMAL_STR_MAX(int))) return NULL; - r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end); + if (range_end > range_start || len == 0) + r = sprintf(str + len, len > 0 ? " %d-%d" : "%d-%d", range_start, range_end); + else + r = sprintf(str + len, len > 0 ? " %d" : "%d", range_start); assert_se(r > 0); } |