58 lines
1.8 KiB
Diff
58 lines
1.8 KiB
Diff
|
|
From c01404fdf100b03dafa8a366d07f74f3c30d5330 Mon Sep 17 00:00:00 2001
|
||
|
|
From: Yu Watanabe <watanabe.yu+github@gmail.com>
|
||
|
|
Date: Wed, 17 Aug 2022 03:11:00 +0900
|
||
|
|
Subject: [PATCH] sysctl: drop /proc/sys/ in prefix
|
||
|
|
|
||
|
|
---
|
||
|
|
src/sysctl/sysctl.c | 20 ++++----------------
|
||
|
|
1 file changed, 4 insertions(+), 16 deletions(-)
|
||
|
|
|
||
|
|
diff --git a/src/sysctl/sysctl.c b/src/sysctl/sysctl.c
|
||
|
|
index dda112f45..ae079b7a7 100644
|
||
|
|
--- a/src/sysctl/sysctl.c
|
||
|
|
+++ b/src/sysctl/sysctl.c
|
||
|
|
@@ -56,18 +56,7 @@ static bool test_prefix(const char *p) {
|
||
|
|
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;
|
||
|
|
+ return path_startswith_strv(p, arg_prefixes);
|
||
|
|
}
|
||
|
|
|
||
|
|
static Option *option_new(
|
||
|
|
@@ -360,6 +349,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||
|
|
break;
|
||
|
|
|
||
|
|
case ARG_PREFIX: {
|
||
|
|
+ const char *s;
|
||
|
|
char *p;
|
||
|
|
|
||
|
|
/* We used to require people to specify absolute paths
|
||
|
|
@@ -368,10 +358,8 @@ static int parse_argv(int argc, char *argv[]) {
|
||
|
|
* sysctl name available. */
|
||
|
|
sysctl_normalize(optarg);
|
||
|
|
|
||
|
|
- if (path_startswith(optarg, "/proc/sys"))
|
||
|
|
- p = strdup(optarg);
|
||
|
|
- else
|
||
|
|
- p = path_join("/proc/sys", optarg);
|
||
|
|
+ s = path_startswith(optarg, "/proc/sys");
|
||
|
|
+ p = strdup(s ?: optarg);
|
||
|
|
if (!p)
|
||
|
|
return log_oom();
|
||
|
|
|
||
|
|
--
|
||
|
|
2.33.0
|
||
|
|
|