[systemd-commits] 2 commits - src/shared src/test
Lennart Poettering
lennart at kemper.freedesktop.org
Wed Nov 5 10:46:22 PST 2014
src/shared/condition-util.c | 51 +++++++++++++++++------------------------
src/shared/util.c | 9 ++++---
src/test/test-condition-util.c | 13 ++++++++++
3 files changed, 41 insertions(+), 32 deletions(-)
New commits:
commit 4a6ca457eb6186addcd84a6a5e5948016202235a
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Nov 5 19:44:01 2014 +0100
util: minor modernisations
diff --git a/src/shared/util.c b/src/shared/util.c
index 0f44eb5..d33f349 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -3179,7 +3179,8 @@ char *replace_env(const char *format, char **env) {
case CURLY:
if (*e == '{') {
- if (!(k = strnappend(r, word, e-word-1)))
+ k = strnappend(r, word, e-word-1);
+ if (!k)
goto fail;
free(r);
@@ -3189,7 +3190,8 @@ char *replace_env(const char *format, char **env) {
state = VARIABLE;
} else if (*e == '$') {
- if (!(k = strnappend(r, word, e-word)))
+ k = strnappend(r, word, e-word);
+ if (!k)
goto fail;
free(r);
@@ -3221,7 +3223,8 @@ char *replace_env(const char *format, char **env) {
}
}
- if (!(k = strnappend(r, word, e-word)))
+ k = strnappend(r, word, e-word);
+ if (!k)
goto fail;
free(r);
commit 07318c290884824dd19f41beefb46aeaaabab46c
Author: Lennart Poettering <lennart at poettering.net>
Date: Wed Nov 5 19:43:55 2014 +0100
condition: rewrite condition_test_kernel_command_line() based on unquote_first_word()
diff --git a/src/shared/condition-util.c b/src/shared/condition-util.c
index ff4a8ec..026b6a8 100644
--- a/src/shared/condition-util.c
+++ b/src/shared/condition-util.c
@@ -74,12 +74,10 @@ void condition_free_list(Condition *first) {
}
bool condition_test_kernel_command_line(Condition *c) {
- char *line, *word = NULL;
- const char *w, *state;
+ _cleanup_free_ char *line = NULL;
+ const char *p;
bool equal;
int r;
- size_t l, pl;
- bool found = false;
assert(c);
assert(c->parameter);
@@ -92,35 +90,30 @@ bool condition_test_kernel_command_line(Condition *c) {
return c->negate;
equal = !!strchr(c->parameter, '=');
- pl = strlen(c->parameter);
-
- FOREACH_WORD_QUOTED(w, l, line, state) {
-
- free(word);
- word = strndup(w, l);
- if (!word)
- break;
-
- if (equal) {
- if (streq(word, c->parameter)) {
- found = true;
- break;
- }
- } else {
- if (startswith(word, c->parameter) && (word[pl] == '=' || word[pl] == 0)) {
- found = true;
- break;
- }
+ p = line;
+
+ for (;;) {
+ _cleanup_free_ char *word = NULL;
+ bool found;
+
+ r = unquote_first_word(&p, &word);
+ if (r <= 0)
+ return c->negate;
+
+ if (equal)
+ found = streq(word, c->parameter);
+ else {
+ const char *f;
+
+ f = startswith(word, c->parameter);
+ found = f && (*f == '=' || *f == 0);
}
+ if (found)
+ return !c->negate;
}
- if (!isempty(state))
- log_warning("Trailing garbage and the end of kernel commandline, ignoring.");
-
- free(word);
- free(line);
- return found == !c->negate;
+ return c->negate;
}
bool condition_test_virtualization(Condition *c) {
diff --git a/src/test/test-condition-util.c b/src/test/test-condition-util.c
index 35ee916..1c79244 100644
--- a/src/test/test-condition-util.c
+++ b/src/test/test-condition-util.c
@@ -95,6 +95,18 @@ static void test_condition_test_architecture(void) {
condition_free(condition);
}
+static void test_condition_test_kernel_command_line(void) {
+ Condition *condition;
+
+ condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "thisreallyshouldntbeonthekernelcommandline", false, false);
+ assert_se(!condition_test_kernel_command_line(condition));
+ condition_free(condition);
+
+ condition = condition_new(CONDITION_KERNEL_COMMAND_LINE, "andthis=neither", false, false);
+ assert_se(!condition_test_kernel_command_line(condition));
+ condition_free(condition);
+}
+
int main(int argc, char *argv[]) {
log_parse_environment();
log_open();
@@ -102,6 +114,7 @@ int main(int argc, char *argv[]) {
test_condition_test_ac_power();
test_condition_test_host();
test_condition_test_architecture();
+ test_condition_test_kernel_command_line();
return 0;
}
More information about the systemd-commits
mailing list