Merge pull request #1693 from ssahani/word

timesysnd: port to extract_first_word
This commit is contained in:
Tom Gundersen
2015-10-27 11:41:06 +01:00
2 changed files with 22 additions and 17 deletions

View File

@@ -22,10 +22,9 @@
#include "conf-parser.h"
#include "string-util.h"
#include "resolved-conf.h"
#include "extract-word.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 +33,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;
memcpy(buffer, word, length);
buffer[length] = 0;
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);
r = in_addr_from_string_auto(buffer, &family, &addr);
if (r == 0)
break;
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;
}

View File

@@ -23,10 +23,9 @@
#include "timesyncd-manager.h"
#include "timesyncd-server.h"
#include "timesyncd-conf.h"
#include "extract-word.h"
int manager_parse_server_string(Manager *m, ServerType type, const char *string) {
const char *word, *state;
size_t length;
ServerName *first;
int r;
@@ -35,17 +34,20 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string)
first = type == SERVER_FALLBACK ? m->fallback_servers : m->system_servers;
FOREACH_WORD_QUOTED(word, length, string, state) {
char buffer[length+1];
for (;;) {
_cleanup_free_ char *word;
bool found = false;
ServerName *n;
memcpy(buffer, word, length);
buffer[length] = 0;
r = extract_first_word(&string, &word, NULL, 0);
if (r < 0)
return log_error_errno(r, "Failed to parse timesyncd server syntax \"%s\": %m", string);
if (r == 0)
break;
/* Filter out duplicates */
LIST_FOREACH(names, n, first)
if (streq_ptr(n->string, buffer)) {
if (streq_ptr(n->string, word)) {
found = true;
break;
}
@@ -53,7 +55,7 @@ int manager_parse_server_string(Manager *m, ServerType type, const char *string)
if (found)
continue;
r = server_name_new(m, NULL, type, buffer);
r = server_name_new(m, NULL, type, word);
if (r < 0)
return r;
}