diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-09-29 07:31:14 -0500 |
---|---|---|
committer | Anthony G. Basile <blueness@gentoo.org> | 2014-09-30 15:57:53 -0400 |
commit | 19a52be96c85c15db274edc7a1dc7dfc236bd2ae (patch) | |
tree | 7bf16d6ae524858c14ac8704e16f38b9ad6ddc9f /src/shared | |
parent | d7447bb0baa871b5866785ed3ecdfdc35976d458 (diff) |
Do not format USEC_INFINITY as NULL
systemctl would print 'CPUQuotaPerSecUSec=(null)' for no limit. This
does not look right.
Since USEC_INFINITY is one of the valid values, format_timespan()
could return NULL, and we should wrap every use of it in strna() or
similar. But most callers didn't do that, and it seems more robust to
return a string ("infinity") that makes sense most of the time, even
if in some places the result will not be grammatically correct.
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/time-util.c | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/src/shared/time-util.c b/src/shared/time-util.c index 3df35b8e24..4e12ea3ca6 100644 --- a/src/shared/time-util.c +++ b/src/shared/time-util.c @@ -99,11 +99,8 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) { assert(buf); assert(l > 0); - if (t == USEC_INFINITY) - return NULL; - - if (t <= 0) { - snprintf(p, l, "0"); + if (t == USEC_INFINITY || t <= 0) { + strncpy(p, t == USEC_INFINITY ? "infinity" : "0", l); p[l-1] = 0; return p; } |