summaryrefslogtreecommitdiff
path: root/src/sysctl
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-01-16 13:05:32 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-01-16 14:45:37 +0100
commitb2ae4d9eb85f80d639733e0ff140c5fa8cae71ab (patch)
tree7de3a2ef7bb90eeb5f9fe83ba78ebd4fe164853e /src/sysctl
parente76c60bf2a2bfd4193accadb7d29e2ac8f659623 (diff)
downloadsystemd-b2ae4d9eb85f80d639733e0ff140c5fa8cae71ab.tar.gz
sysctl: move hashmap allocation out of main function
This allocation is a low level detail, and it seems nicer to keep it out of run().
Diffstat (limited to 'src/sysctl')
-rw-r--r--src/sysctl/sysctl.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 56d86d8eba..1ced48b4db 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -122,7 +122,7 @@ static bool test_prefix(const char *p) {
return false;
}
-static int parse_file(OrderedHashmap *sysctl_options, const char *path, bool ignore_enoent) {
+static int parse_file(OrderedHashmap **sysctl_options, const char *path, bool ignore_enoent) {
_cleanup_fclose_ FILE *f = NULL;
unsigned c = 0;
int r;
@@ -183,7 +183,10 @@ static int parse_file(OrderedHashmap *sysctl_options, const char *path, bool ign
if (!test_prefix(p))
continue;
- existing = ordered_hashmap_get(sysctl_options, p);
+ if (ordered_hashmap_ensure_allocated(sysctl_options, &option_hash_ops) < 0)
+ return log_oom();
+
+ existing = ordered_hashmap_get(*sysctl_options, p);
if (existing) {
if (streq(value, existing->value)) {
existing->ignore_failure = existing->ignore_failure || ignore_failure;
@@ -191,14 +194,14 @@ static int parse_file(OrderedHashmap *sysctl_options, const char *path, bool ign
}
log_debug("Overwriting earlier assignment of %s at '%s:%u'.", p, path, c);
- option_free(ordered_hashmap_remove(sysctl_options, p));
+ option_free(ordered_hashmap_remove(*sysctl_options, p));
}
new_option = option_new(p, value, ignore_failure);
if (!new_option)
return log_oom();
- k = ordered_hashmap_put(sysctl_options, new_option->key, new_option);
+ k = ordered_hashmap_put(*sysctl_options, new_option->key, new_option);
if (k < 0)
return log_error_errno(k, "Failed to add sysctl variable %s to hashmap: %m", p);
@@ -320,17 +323,13 @@ static int run(int argc, char *argv[]) {
umask(0022);
- sysctl_options = ordered_hashmap_new(&option_hash_ops);
- if (!sysctl_options)
- return log_oom();
-
if (argc > optind) {
int i;
r = 0;
for (i = optind; i < argc; i++) {
- k = parse_file(sysctl_options, argv[i], false);
+ k = parse_file(&sysctl_options, argv[i], false);
if (k < 0 && r == 0)
r = k;
}
@@ -349,7 +348,7 @@ static int run(int argc, char *argv[]) {
}
STRV_FOREACH(f, files) {
- k = parse_file(sysctl_options, *f, true);
+ k = parse_file(&sysctl_options, *f, true);
if (k < 0 && r == 0)
r = k;
}