]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hostname: use FOREACH_ARGUMENT() at one more place 37583/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 23 May 2025 14:24:27 +0000 (23:24 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 23 May 2025 14:24:38 +0000 (23:24 +0900)
Follow-up for 29a352e8c14c51983ba661cb5f4ce51e2bc8664b.

src/hostname/hostnamed.c

index ec09acb539dd6a095215ad889587a8f72b73175f..e194381ce1bfdc814dea810b0905e7d5d67fbd5f 100644 (file)
@@ -393,17 +393,16 @@ static int get_hardware_version(Context *c, char **ret) {
 
         /* Suppress reporting the version field, if it's the same string as the
          * model or sku field, which it appears to be on various systems */
-        for (int i = 0; i < 2; i++) {
+        int (*getter)(Context *c, char **ret);
+        FOREACH_ARGUMENT(getter, get_hardware_model, get_hardware_sku) {
                 _cleanup_free_ char *value = NULL;
 
-                if (i == 0)
-                        r = get_hardware_model(c, &value);
-                else
-                        r = get_hardware_sku(c, &value);
-                if (r < 0) {
-                        if (r != -ENOENT)
-                                return r;
-                } else if (streq_ptr(version, value))
+                r = getter(c, &value);
+                if (r == -ENOENT)
+                        continue;
+                if (r < 0)
+                        return r;
+                if (streq_ptr(version, value))
                         return -ENOENT;
         }