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