systemd/0276-sysctl-make-prefix-allow-all-kinds-of-sysctl-paths.patch
Zbigniew Jędrzejewski-Szmek 62fe9450da Update to latest git
2014-10-07 15:51:56 -04:00

63 lines
2.9 KiB
Diff

From 0e1f579227b08832437a7ac2227c7e4007a89d23 Mon Sep 17 00:00:00 2001
From: David Herrmann <dh.herrmann@gmail.com>
Date: Wed, 17 Sep 2014 09:06:49 +0200
Subject: [PATCH] sysctl: make --prefix allow all kinds of sysctl paths
Currently, we save arguments passed as --prefix directly and compare them
later to absolute sysctl file-system paths. That is, you are required to
specify arguments to --prefix with leading /proc/sys/. This is kinda
uselesss. Furthermore, we replace dots by slashes in the name, which makes
it impossible to match on specific sysfs paths that have dots in their
name (like netdev names). The intention of this argument is clear, but it
never worked as expected.
This patch modifies --prefix to accept any kind of sysctl paths. It
supports paths prefixed with /proc/sys for compatibility (but drops the
erroneous dot->slash conversion), but instead applies normalize_sysctl()
which turns any name or path into a proper path. It then appends
/proc/sys/ so we can properly use it in matches.
Thanks to Jan Synacek <jsynacek@redhat.com> for catching this!
---
src/sysctl/sysctl.c | 20 ++++++++++++++------
1 file changed, 14 insertions(+), 6 deletions(-)
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
index 4f9530baf8..809e59b71f 100644
--- a/src/sysctl/sysctl.c
+++ b/src/sysctl/sysctl.c
@@ -219,7 +219,7 @@ static void help(void) {
"Applies kernel sysctl settings.\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
- " --prefix=PATH Only apply rules that apply to paths with the specified prefix\n"
+ " --prefix=PATH Only apply rules with the specified prefix\n"
, program_invocation_short_name);
}
@@ -258,11 +258,19 @@ static int parse_argv(int argc, char *argv[]) {
case ARG_PREFIX: {
char *p;
- for (p = optarg; *p; p++)
- if (*p == '.')
- *p = '/';
-
- if (strv_extend(&arg_prefixes, optarg) < 0)
+ /* We used to require people to specify absolute paths
+ * in /proc/sys in the past. This is kinda useless, but
+ * we need to keep compatibility. We now support any
+ * sysctl name available. */
+ normalize_sysctl(optarg);
+ if (startswith(optarg, "/proc/sys"))
+ p = strdup(optarg);
+ else
+ p = strappend("/proc/sys/", optarg);
+
+ if (!p)
+ return log_oom();
+ if (strv_consume(&arg_prefixes, p) < 0)
return log_oom();
break;