diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-04-29 08:47:51 +0200 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2020-05-06 16:54:06 +0200 |
commit | be32732168e07b7d52ec77fa67cf93a80a9a8293 (patch) | |
tree | 0feb0a006050702078fd41b5fea2eee9c4d00b08 /src/nspawn/nspawn-cgroup.c | |
parent | 0894f08bf14b09ef0436ed11268d43dbcdd88ee7 (diff) | |
download | systemd-be32732168e07b7d52ec77fa67cf93a80a9a8293.tar.gz |
basic/set: let set_put_strdup() create the set with string hash ops
If we're using a set with _put_strdup(), most of the time we want to use
string hash ops on the set, and free the strings when done. This defines
the appropriate a new string_hash_ops_free structure to automatically free
the keys when removing the set, and makes set_put_strdup() and set_put_strdupv()
instantiate the set with those hash ops.
hashmap_put_strdup() was already doing something similar.
(It is OK to instantiate the set earlier, possibly with a different hash ops
structure. set_put_strdup() will then use the existing set. It is also OK
to call set_free_free() instead of set_free() on a set with
string_hash_ops_free, the effect is the same, we're just overriding the
override of the cleanup function.)
No functional change intended.
Diffstat (limited to 'src/nspawn/nspawn-cgroup.c')
-rw-r--r-- | src/nspawn/nspawn-cgroup.c | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/nspawn/nspawn-cgroup.c b/src/nspawn/nspawn-cgroup.c index f5048d9473..dcee851e93 100644 --- a/src/nspawn/nspawn-cgroup.c +++ b/src/nspawn/nspawn-cgroup.c @@ -199,16 +199,12 @@ int create_subcgroup(pid_t pid, bool keep_unit, CGroupUnified unified_requested) * namespace. */ static int get_process_controllers(Set **ret) { - _cleanup_set_free_free_ Set *controllers = NULL; + _cleanup_set_free_ Set *controllers = NULL; _cleanup_fclose_ FILE *f = NULL; int r; assert(ret); - controllers = set_new(&string_hash_ops); - if (!controllers) - return -ENOMEM; - f = fopen("/proc/self/cgroup", "re"); if (!f) return errno == ENOENT ? -ESRCH : -errno; @@ -237,7 +233,7 @@ static int get_process_controllers(Set **ret) { if (STR_IN_SET(l, "", "name=systemd", "name=unified")) continue; - r = set_put_strdup(controllers, l); + r = set_put_strdup(&controllers, l); if (r < 0) return r; } @@ -303,7 +299,7 @@ static int mount_legacy_cgns_supported( uid_t uid_range, const char *selinux_apifs_context) { - _cleanup_set_free_free_ Set *controllers = NULL; + _cleanup_set_free_ Set *controllers = NULL; const char *cgroup_root = "/sys/fs/cgroup", *c; int r; |