chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
55af389
)
sysctl: support multiple prefixes in a single invocation
author
Lennart Poettering
<lennart@poettering.net>
Fri, 15 Jul 2011 00:01:31 +0000
(
02:01
+0200)
committer
Lennart Poettering
<lennart@poettering.net>
Fri, 15 Jul 2011 00:01:31 +0000
(
02:01
+0200)
src/sysctl.c
patch
|
blob
|
history
diff --git
a/src/sysctl.c
b/src/sysctl.c
index 5ffb9695c6439349d6c26fa6c4a00828d41f26e8..9f7acfce8b09f76d67247c0d82caa2c35baed5aa 100644
(file)
--- a/
src/sysctl.c
+++ b/
src/sysctl.c
@@
-30,10
+30,11
@@
#include "log.h"
#include "strv.h"
#include "util.h"
#include "log.h"
#include "strv.h"
#include "util.h"
+#include "strv.h"
#define PROC_SYS_PREFIX "/proc/sys/"
#define PROC_SYS_PREFIX "/proc/sys/"
-static c
onst char *arg_prefix
= NULL;
+static c
har **arg_prefixes
= NULL;
static int apply_sysctl(const char *property, const char *value) {
char *p, *n;
static int apply_sysctl(const char *property, const char *value) {
char *p, *n;
@@
-54,10
+55,21
@@
static int apply_sysctl(const char *property, const char *value) {
if (*n == '.')
*n = '/';
if (*n == '.')
*n = '/';
- if (arg_prefix && !path_startswith(p, arg_prefix)) {
- log_debug("Skipping %s", p);
- free(p);
- return 0;
+ if (!strv_isempty(arg_prefixes)) {
+ char **i;
+ bool good = false;
+
+ STRV_FOREACH(i, arg_prefixes)
+ if (path_startswith(p, *i)) {
+ good = true;
+ break;
+ }
+
+ if (!good) {
+ log_debug("Skipping %s", p);
+ free(p);
+ return 0;
+ }
}
k = write_one_line_file(p, value);
}
k = write_one_line_file(p, value);
@@
-170,12
+182,20
@@
static int parse_argv(int argc, char *argv[]) {
case ARG_PREFIX: {
char *p;
case ARG_PREFIX: {
char *p;
+ char **l;
for (p = optarg; *p; p++)
if (*p == '.')
*p = '/';
for (p = optarg; *p; p++)
if (*p == '.')
*p = '/';
- arg_prefix = optarg;
+ l = strv_append(arg_prefixes, optarg);
+ if (!l) {
+ log_error("Out of memory");
+ return -ENOMEM;
+ }
+
+ strv_free(arg_prefixes);
+ arg_prefixes = l;
break;
}
break;
}
@@
-238,5
+258,7
@@
int main(int argc, char *argv[]) {
strv_free(files);
}
finish:
strv_free(files);
}
finish:
+ strv_free(arg_prefixes);
+
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}