]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
timesyncd: clean up server_name_new()
authorDaniel Mack <daniel@zonque.org>
Tue, 22 Mar 2022 17:26:55 +0000 (18:26 +0100)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 9 Apr 2022 01:23:14 +0000 (10:23 +0900)
Use `LIST_APPEND()` in favour of `LIST_FIND_TAIL()` + `LIST_INSERT_AFTER()`.
Also use a switch/case statement instead of if/else if.

src/timesync/timesyncd-server.c

index c8ff46f3992e3399f6d63f817d3863ca8677550f..3b7d79323fee443e8892f43aea087d815009c2bc 100644 (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 &&