timesyncd: clean up server_name_new()

Use `LIST_APPEND()` in favour of `LIST_FIND_TAIL()` + `LIST_INSERT_AFTER()`.
Also use a switch/case statement instead of if/else if.
This commit is contained in:
Daniel Mack
2022-03-22 18:26:55 +01:00
committed by Yu Watanabe
parent 5dfb11097d
commit feb219c997

View File

@@ -66,7 +66,7 @@ int server_name_new(
ServerType type,
const char *string) {
ServerName *n, *tail;
ServerName *n;
assert(m);
assert(string);
@@ -86,20 +86,22 @@ int server_name_new(
return -ENOMEM;
}
if (type == SERVER_SYSTEM) {
LIST_FIND_TAIL(names, m->system_servers, tail);
LIST_INSERT_AFTER(names, m->system_servers, tail, n);
} else if (type == SERVER_LINK) {
LIST_FIND_TAIL(names, m->link_servers, tail);
LIST_INSERT_AFTER(names, m->link_servers, tail, n);
} else if (type == SERVER_FALLBACK) {
LIST_FIND_TAIL(names, m->fallback_servers, tail);
LIST_INSERT_AFTER(names, m->fallback_servers, tail, n);
} else if (type == SERVER_RUNTIME) {
LIST_FIND_TAIL(names, m->runtime_servers, tail);
LIST_INSERT_AFTER(names, m->runtime_servers, tail, n);
} else
switch (type) {
case SERVER_SYSTEM:
LIST_APPEND(names, m->system_servers, n);
break;
case SERVER_LINK:
LIST_APPEND(names, m->link_servers, n);
break;
case SERVER_FALLBACK:
LIST_APPEND(names, m->fallback_servers, n);
break;
case SERVER_RUNTIME:
LIST_APPEND(names, m->runtime_servers, n);
break;
default:
assert_not_reached();
}
if (type != SERVER_FALLBACK &&
m->current_server_name &&