core: set_put never returns -EEXIST
When the value is already there it returns 0. Also add a test to ensure this
This commit is contained in:
@@ -2369,7 +2369,7 @@ int config_parse_syscall_filter(
|
||||
continue;
|
||||
|
||||
r = set_put(c->syscall_filter, INT_TO_PTR(id + 1));
|
||||
if (r == -EEXIST)
|
||||
if (r == 0)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
@@ -2397,7 +2397,7 @@ int config_parse_syscall_filter(
|
||||
*/
|
||||
if (!invert == c->syscall_whitelist) {
|
||||
r = set_put(c->syscall_filter, INT_TO_PTR(id + 1));
|
||||
if (r == -EEXIST)
|
||||
if (r == 0)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
@@ -2459,7 +2459,7 @@ int config_parse_syscall_archs(
|
||||
}
|
||||
|
||||
r = set_put(*archs, UINT32_TO_PTR(a + 1));
|
||||
if (r == -EEXIST)
|
||||
if (r == 0)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
@@ -2570,7 +2570,7 @@ int config_parse_address_families(
|
||||
*/
|
||||
if (!invert == c->address_families_whitelist) {
|
||||
r = set_put(c->address_families, INT_TO_PTR(af));
|
||||
if (r == -EEXIST)
|
||||
if (r == 0)
|
||||
continue;
|
||||
if (r < 0)
|
||||
return log_oom();
|
||||
|
||||
+2
-11
@@ -181,12 +181,8 @@ int unit_add_name(Unit *u, const char *text) {
|
||||
return -E2BIG;
|
||||
|
||||
r = set_put(u->names, s);
|
||||
if (r < 0) {
|
||||
if (r == -EEXIST)
|
||||
return 0;
|
||||
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = hashmap_put(u->manager->units, s, u);
|
||||
if (r < 0) {
|
||||
@@ -1161,7 +1157,6 @@ static int unit_add_mount_dependencies(Unit *u) {
|
||||
|
||||
static int unit_add_startup_units(Unit *u) {
|
||||
CGroupContext *c;
|
||||
int r = 0;
|
||||
|
||||
c = unit_get_cgroup_context(u);
|
||||
if (!c)
|
||||
@@ -1171,11 +1166,7 @@ static int unit_add_startup_units(Unit *u) {
|
||||
c->startup_blockio_weight == (unsigned long) -1)
|
||||
return 0;
|
||||
|
||||
r = set_put(u->manager->startup_units, u);
|
||||
if (r == -EEXIST)
|
||||
return 0;
|
||||
|
||||
return r;
|
||||
return set_put(u->manager->startup_units, u);
|
||||
}
|
||||
|
||||
int unit_load(Unit *u) {
|
||||
|
||||
@@ -39,8 +39,25 @@ static void test_set_steal_first(void) {
|
||||
assert_se(set_isempty(m));
|
||||
}
|
||||
|
||||
static void test_set_put(void) {
|
||||
_cleanup_set_free_ Set *m = NULL;
|
||||
|
||||
m = set_new(&string_hash_ops);
|
||||
assert_se(m);
|
||||
|
||||
assert_se(set_put(m, (void*) "1") == 1);
|
||||
assert_se(set_put(m, (void*) "22") == 1);
|
||||
assert_se(set_put(m, (void*) "333") == 1);
|
||||
assert_se(set_put(m, (void*) "333") == 0);
|
||||
assert_se(set_remove(m, (void*) "333"));
|
||||
assert_se(set_put(m, (void*) "333") == 1);
|
||||
assert_se(set_put(m, (void*) "333") == 0);
|
||||
assert_se(set_put(m, (void*) "22") == 0);
|
||||
}
|
||||
|
||||
int main(int argc, const char *argv[]) {
|
||||
test_set_steal_first();
|
||||
test_set_put();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user