diff options
author | Lennart Poettering <lennart@poettering.net> | 2016-10-25 09:25:21 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2016-11-02 11:29:59 -0600 |
commit | 9c37b41c6166ca511b317255cfad271c906e597a (patch) | |
tree | 4cb291e385076c9689b2cb1c2cbd7cbf760a029c /src | |
parent | 39540de8abe24886693ca29a9caeea85c88089aa (diff) |
sysctl: split out condition check into its own function
This way, we can get rid of a label/goto.
Diffstat (limited to 'src')
-rw-r--r-- | src/sysctl/sysctl.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c index 1363a93830..a2a7a10f69 100644 --- a/src/sysctl/sysctl.c +++ b/src/sysctl/sysctl.c @@ -69,6 +69,25 @@ static int apply_all(OrderedHashmap *sysctl_options) { return r; } +static bool test_prefix(const char *p) { + char **i; + + if (strv_isempty(arg_prefixes)) + return true; + + STRV_FOREACH(i, arg_prefixes) { + const char *t; + + t = path_startswith(*i, "/proc/sys/"); + if (!t) + t = *i; + if (path_startswith(p, t)) + return true; + } + + return false; +} + static int parse_file(OrderedHashmap *sysctl_options, const char *path, bool ignore_enoent) { _cleanup_fclose_ FILE *f = NULL; int r; @@ -118,20 +137,9 @@ static int parse_file(OrderedHashmap *sysctl_options, const char *path, bool ign p = sysctl_normalize(strstrip(p)); value = strstrip(value); - if (!strv_isempty(arg_prefixes)) { - char **i, *t; - STRV_FOREACH(i, arg_prefixes) { - t = path_startswith(*i, "/proc/sys/"); - if (t == NULL) - t = *i; - if (path_startswith(p, t)) - goto found; - } - /* not found */ + if (!test_prefix(p)) continue; - } -found: existing = ordered_hashmap_get2(sysctl_options, p, &v); if (existing) { if (streq(value, existing)) |