]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/resolve/resolved-conf.c
util-lib: split string parsing related calls from util.[ch] into parse-util.[ch]
[thirdparty/systemd.git] / src / resolve / resolved-conf.c
index cc8d5fa76a2cd0cd261cae75b8028a6adeb031c5..17eafec2fa65d7d7895e2af09e3bdacfdb903559 100644 (file)
  ***/
 
 #include "conf-parser.h"
-
+#include "parse-util.h"
 #include "resolved-conf.h"
+#include "extract-word.h"
+#include "string-util.h"
 
 int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string) {
-        const char *word, *state;
-        size_t length;
         DnsServer *first;
         int r;
 
@@ -34,19 +34,23 @@ int manager_parse_dns_server(Manager *m, DnsServerType type, const char *string)
 
         first = type == DNS_SERVER_FALLBACK ? m->fallback_dns_servers : m->dns_servers;
 
-        FOREACH_WORD_QUOTED(word, length, string, state) {
-                char buffer[length+1];
-                int family;
+        for(;;) {
+                _cleanup_free_ char *word;
                 union in_addr_union addr;
                 bool found = false;
                 DnsServer *s;
+                int family;
+
+                r = extract_first_word(&string, &word, NULL, 0);
+                if (r < 0)
+                        return log_error_errno(r, "Failed to parse resolved dns server syntax \"%s\": %m", string);
 
-                memcpy(buffer, word, length);
-                buffer[length] = 0;
+                if (r == 0)
+                        break;
 
-                r = in_addr_from_string_auto(buffer, &family, &addr);
+                r = in_addr_from_string_auto(word, &family, &addr);
                 if (r < 0) {
-                        log_warning("Ignoring invalid DNS address '%s'", buffer);
+                        log_warning("Ignoring invalid DNS address '%s'", word);
                         continue;
                 }