Merge pull request #14589 from keszybz/sysctl-downgrade-messages

sysctl: add glob patterns to set network settings more flexibly
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2020-02-04 00:04:28 +01:00
committed by GitHub
7 changed files with 265 additions and 111 deletions
+4
View File
@@ -325,6 +325,10 @@ tests += [
[],
[]],
[['src/test/test-sysctl-util.c'],
[],
[]],
[['src/test/test-user-util.c'],
[],
[]],
+44
View File
@@ -0,0 +1,44 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include "strv.h"
#include "sysctl-util.h"
#include "tests.h"
static const char* cases[] = {
"a.b.c", "a/b/c",
"a/b/c", "a/b/c",
"a/b.c/d", "a/b.c/d",
"a.b/c.d", "a/b.c/d",
"net.ipv4.conf.enp3s0/200.forwarding", "net/ipv4/conf/enp3s0.200/forwarding",
"net/ipv4/conf/enp3s0.200/forwarding", "net/ipv4/conf/enp3s0.200/forwarding",
"a...b...c", "a/b/c",
"a///b///c", "a/b/c",
".a...b...c", "a/b/c",
"/a///b///c", "a/b/c",
NULL,
};
static void test_sysctl_normalize(void) {
log_info("/* %s */", __func__);
const char **s, **expected;
STRV_FOREACH_PAIR(s, expected, cases) {
_cleanup_free_ char *t;
assert_se(t = strdup(*s));
assert_se(sysctl_normalize(t) == t);
log_info("\"%s\" → \"%s\", expected \"%s\"", *s, t, *expected);
assert_se(streq(t, *expected));
}
}
int main(int argc, char *argv[]) {
test_setup_logging(LOG_INFO);
test_sysctl_normalize();
return 0;
}