summaryrefslogtreecommitdiff
path: root/src/core/cgroup.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-10-07 09:15:44 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2022-10-11 16:10:21 +0200
commit385530342869ce4c6ea7388262bec4a0398b9311 (patch)
treeb9547137bb5d84351f187465b234de5f9cde4060 /src/core/cgroup.c
parent892dc967873cab3b8af158284a524d3148db674a (diff)
downloadsystemd-385530342869ce4c6ea7388262bec4a0398b9311.tar.gz
core,logind,systemctl,journald: replace calls to strerror() with setting errno + %m
strerror() is not thread safe and calling it just isn't worth the effort required to justify why it would be safe in those cases. It's easier to just use %m which is thread-safe out of the box. I don't think that any of the changes in the patch cause any functional difference. This is just about getting rid of calls to strerror() in general. When we print an error message and fail to format the string, using something like "(null)" is good enough. This is very very unlikely to happen anyway.
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r--src/core/cgroup.c16
1 files changed, 6 insertions, 10 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 6d40faa48b..bbd107849c 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -398,17 +398,13 @@ static char *format_cgroup_memory_limit_comparison(char *buf, size_t l, Unit *u,
* In the absence of reliably being able to detect whether memcg swap support is available or not,
* only complain if the error is not ENOENT. */
if (r > 0 || IN_SET(r, -ENODATA, -EOWNERDEAD) ||
- (r == -ENOENT && streq(property_name, "MemorySwapMax"))) {
+ (r == -ENOENT && streq(property_name, "MemorySwapMax")))
buf[0] = 0;
- return buf;
- }
-
- if (r < 0) {
- (void) snprintf(buf, l, " (error getting kernel value: %s)", strerror_safe(r));
- return buf;
- }
-
- (void) snprintf(buf, l, " (different value in kernel: %" PRIu64 ")", kval);
+ else if (r < 0) {
+ errno = -r;
+ (void) snprintf(buf, l, " (error getting kernel value: %m)");
+ } else
+ (void) snprintf(buf, l, " (different value in kernel: %" PRIu64 ")", kval);
return buf;
}