From 035fe294b3fdc054151eacc5a75909f2c479300c Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Thu, 27 Oct 2016 20:15:22 -0400 Subject: core/load-fragment: port to extract_first_word --- src/core/load-fragment.c | 254 +++++++++++++++++++++++++---------------------- 1 file changed, 136 insertions(+), 118 deletions(-) (limited to 'src/core/load-fragment.c') diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 3651eb9634..455c11a501 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -269,26 +269,33 @@ int config_parse_unit_path_strv_printf( void *userdata) { char ***x = data; - const char *word, *state; Unit *u = userdata; - size_t l; int r; + const char *p; assert(filename); assert(lvalue); assert(rvalue); assert(u); - FOREACH_WORD_QUOTED(word, l, rvalue, state) { - _cleanup_free_ char *k = NULL; - char t[l+1]; + for (p = rvalue;;) { + _cleanup_free_ char *word = NULL, *k = NULL; - memcpy(t, word, l); - t[l] = 0; + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); + if (r == 0) + return 0; + if (r == -ENOMEM) + return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid syntax, ignoring: %s", rvalue); + return 0; + } - r = unit_full_printf(u, t, &k); + r = unit_full_printf(u, word, &k); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve unit specifiers on %s, ignoring: %m", t); + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to resolve unit specifiers on \"%s\", ignoring: %m", word); return 0; } @@ -298,7 +305,8 @@ int config_parse_unit_path_strv_printf( } if (!path_is_absolute(k)) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Symlink path %s is not absolute, ignoring: %m", k); + log_syntax(unit, LOG_ERR, filename, line, 0, + "Symlink path is not absolute: %s", k); return 0; } @@ -307,13 +315,8 @@ int config_parse_unit_path_strv_printf( r = strv_push(x, k); if (r < 0) return log_oom(); - k = NULL; } - if (!isempty(state)) - log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid syntax, ignoring."); - - return 0; } int config_parse_socket_listen(const char *unit, @@ -1062,8 +1065,8 @@ int config_parse_exec_secure_bits(const char *unit, void *userdata) { ExecContext *c = data; - size_t l; - const char *word, *state; + const char *p; + int r; assert(filename); assert(lvalue); @@ -1076,28 +1079,38 @@ int config_parse_exec_secure_bits(const char *unit, return 0; } - FOREACH_WORD_QUOTED(word, l, rvalue, state) { - if (first_word(word, "keep-caps")) + for (p = rvalue;;) { + _cleanup_free_ char *word = NULL; + + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); + if (r == 0) + return 0; + if (r == -ENOMEM) + return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid syntax, ignoring: %s", rvalue); + return 0; + } + + if (streq(word, "keep-caps")) c->secure_bits |= 1<secure_bits |= 1<secure_bits |= 1<secure_bits |= 1<secure_bits |= 1<secure_bits |= 1<address_families_whitelist = !invert; } - FOREACH_WORD_QUOTED(word, l, rvalue, state) { - _cleanup_free_ char *t = NULL; + for (p = rvalue;;) { + _cleanup_free_ char *word = NULL; int af; - t = strndup(word, l); - if (!t) + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); + if (r == 0) + return 0; + if (r == -ENOMEM) return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid syntax, ignoring: %s", rvalue); + return 0; + } - af = af_from_name(t); + af = af_from_name(word); if (af <= 0) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Failed to parse address family, ignoring: %s", t); + log_syntax(unit, LOG_ERR, filename, line, 0, + "Failed to parse address family \"%s\", ignoring: %m", word); continue; } /* If we previously wanted to forbid an address family and now - * we want to allow it, then remove it from the list + * we want to allow it, then just remove it from the list. */ if (!invert == c->address_families_whitelist) { r = set_put(c->address_families, INT_TO_PTR(af)); - if (r == 0) - continue; if (r < 0) return log_oom(); } else set_remove(c->address_families, INT_TO_PTR(af)); } - if (!isempty(state)) - log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring."); - - return 0; } #endif @@ -3622,8 +3637,7 @@ int config_parse_runtime_directory( char***rt = data; Unit *u = userdata; - const char *word, *state; - size_t l; + const char *p; int r; assert(filename); @@ -3637,34 +3651,38 @@ int config_parse_runtime_directory( return 0; } - FOREACH_WORD_QUOTED(word, l, rvalue, state) { - _cleanup_free_ char *t = NULL, *n = NULL; + for (p = rvalue;;) { + _cleanup_free_ char *word = NULL, *k = NULL; - t = strndup(word, l); - if (!t) + r = extract_first_word(&p, &word, NULL, EXTRACT_QUOTES); + if (r == 0) + return 0; + if (r == -ENOMEM) return log_oom(); + if (r < 0) { + log_syntax(unit, LOG_WARNING, filename, line, r, + "Invalid syntax, ignoring: %s", rvalue); + return 0; + } - r = unit_name_printf(u, t, &n); + r = unit_name_printf(u, word, &k); if (r < 0) { - log_syntax(unit, LOG_ERR, filename, line, r, "Failed to resolve specifiers, ignoring: %m"); + log_syntax(unit, LOG_ERR, filename, line, r, + "Failed to resolve specifiers in \"%s\", ignoring: %m", word); continue; } - if (!filename_is_valid(n)) { - log_syntax(unit, LOG_ERR, filename, line, 0, "Runtime directory is not valid, ignoring assignment: %s", rvalue); + if (!filename_is_valid(k)) { + log_syntax(unit, LOG_ERR, filename, line, 0, + "Runtime directory is not valid, ignoring assignment: %s", rvalue); continue; } - r = strv_push(rt, n); + r = strv_push(rt, k); if (r < 0) return log_oom(); - - n = NULL; + k = NULL; } - if (!isempty(state)) - log_syntax(unit, LOG_ERR, filename, line, 0, "Trailing garbage, ignoring."); - - return 0; } int config_parse_set_status( -- cgit v1.2.3-54-g00ecf