diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-03-22 16:53:26 +0100 |
---|---|---|
committer | Sven Eden <yamakuzure@gmx.net> | 2018-08-24 16:47:08 +0200 |
commit | 0c2b96fea853ce7f16a9326c3c98117d75defdf6 (patch) | |
tree | ff3d108a1d7f295af840137e3c7f77e9d25692aa /src/core/cgroup.c | |
parent | 6895c0be1845203e14b776dd8a15a97780ac6942 (diff) |
macro: introduce TAKE_PTR() macro
This macro will read a pointer of any type, return it, and set the
pointer to NULL. This is useful as an explicit concept of passing
ownership of a memory area between pointers.
This takes inspiration from Rust:
https://doc.rust-lang.org/std/option/enum.Option.html#method.take
and was suggested by Alan Jenkins (@sourcejedi).
It drops ~160 lines of code from our codebase, which makes me like it.
Also, I think it clarifies passing of ownership, and thus helps
readability a bit (at least for the initiated who know the new macro)
Diffstat (limited to 'src/core/cgroup.c')
-rw-r--r-- | src/core/cgroup.c | 5 |
1 files changed, 2 insertions, 3 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c index 7c590a661..7b9e29b6f 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -1382,8 +1382,7 @@ int unit_set_cgroup_path(Unit *u, const char *path) { unit_release_cgroup(u); - u->cgroup_path = p; - p = NULL; + u->cgroup_path = TAKE_PTR(p); return 1; } @@ -2341,7 +2340,7 @@ void manager_shutdown_cgroup(Manager *m, bool delete) { #if 0 /// elogind is not init /* We can't really delete the group, since we are in it. But * let's trim it. */ - if (delete && m->cgroup_root && m->test_run_flags != MANAGER_TEST_RUN_MINIMAL) + if (delete && m->cgroup_root) (void) cg_trim(SYSTEMD_CGROUP_CONTROLLER, m->cgroup_root, false); m->cgroup_empty_event_source = sd_event_source_unref(m->cgroup_empty_event_source); |