]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
various: use id128_from_string_not_null()
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 26 Aug 2023 13:13:05 +0000 (15:13 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 2 Sep 2023 11:16:25 +0000 (14:16 +0300)
No functional change. In config_parse_address_generation_type() we would set
the output parameter and then say it's ignored, so it _looked_ like an error in
the code, but the variable was always initialized to SD_ID128_NULL anyway, so
the code was actually fine.

src/core/main.c
src/network/networkd-address-generation.c
src/nspawn/nspawn.c
src/partition/repart.c
src/shared/conf-parser.c

index df9cfa21aad95fb4e3c61d7cea5351abf81990c9..7a8652df03e7623b446c985ace8688fc17502531 100644 (file)
@@ -242,20 +242,6 @@ static int console_setup(void) {
         return 0;
 }
 
-static int set_machine_id(const char *m) {
-        sd_id128_t t;
-        assert(m);
-
-        if (sd_id128_from_string(m, &t) < 0)
-                return -EINVAL;
-
-        if (sd_id128_is_null(t))
-                return -EINVAL;
-
-        arg_machine_id = t;
-        return 0;
-}
-
 static int parse_proc_cmdline_item(const char *key, const char *value, void *data) {
         int r;
 
@@ -392,7 +378,7 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
                 if (proc_cmdline_value_missing(key, value))
                         return 0;
 
-                r = set_machine_id(value);
+                r = id128_from_string_nonzero(value, &arg_machine_id);
                 if (r < 0)
                         log_warning_errno(r, "MachineID '%s' is not valid, ignoring: %m", value);
 
@@ -1045,7 +1031,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_MACHINE_ID:
-                        r = set_machine_id(optarg);
+                        r = id128_from_string_nonzero(optarg, &arg_machine_id);
                         if (r < 0)
                                 return log_error_errno(r, "MachineID '%s' is not valid: %m", optarg);
                         break;
index 769cccf7484de9020c20717fe308410897a0a853..79fde024a365ef456e53b4ed24ed1c3527cd056e 100644 (file)
@@ -370,16 +370,11 @@ int config_parse_address_generation_type(
                 }
 
                 if (comma) {
-                        r = sd_id128_from_string(comma + 1, &secret_key);
+                        r = id128_from_string_nonzero(comma + 1, &secret_key);
                         if (r < 0) {
                                 log_syntax(unit, LOG_WARNING, filename, line, r,
-                                           "Failed to parse secret key in %s=, ignoring assignment: %s",
-                                           lvalue, rvalue);
-                                return 0;
-                        }
-                        if (sd_id128_is_null(secret_key)) {
-                                log_syntax(unit, LOG_WARNING, filename, line, 0,
-                                           "Secret key in %s= cannot be null, ignoring assignment: %s",
+                                           r == -ENXIO ? "Secret key in %s= cannot be null, ignoring assignment: %s"
+                                                       : "Failed to parse secret key in %s=, ignoring assignment: %s",
                                            lvalue, rvalue);
                                 return 0;
                         }
index d3ae547746a060be6a1300083e4574d8eda9673f..9e74ead8d58191db0614ce405d2874ad9a0b8855 100644 (file)
@@ -976,13 +976,12 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_UUID:
-                        r = sd_id128_from_string(optarg, &arg_uuid);
-                        if (r < 0)
-                                return log_error_errno(r, "Invalid UUID: %s", optarg);
-
-                        if (sd_id128_is_null(arg_uuid))
+                        r = id128_from_string_nonzero(optarg, &arg_uuid);
+                        if (r == -ENXIO)
                                 return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
                                                        "Machine UUID may not be all zeroes.");
+                        if (r < 0)
+                                return log_error_errno(r, "Invalid UUID: %s", optarg);
 
                         arg_settings_mask |= SETTING_MACHINE_ID;
                         break;
index e403012e92dd79fb2cb882cdab94ab00c796ba91..b6fe9ef79eeeba8a04c7bea6b261be028a428a21 100644 (file)
@@ -2438,11 +2438,8 @@ static int context_load_partition_table(Context *context) {
         if (r < 0)
                 return log_error_errno(r, "Failed to get current GPT disk label UUID: %m");
 
-        r = sd_id128_from_string(disk_uuid_string, &disk_uuid);
-        if (r < 0)
-                return log_error_errno(r, "Failed to parse current GPT disk label UUID: %m");
-
-        if (sd_id128_is_null(disk_uuid)) {
+        r = id128_from_string_nonzero(disk_uuid_string, &disk_uuid);
+        if (r == -ENXIO) {
                 r = derive_uuid(context->seed, "disk-uuid", &disk_uuid);
                 if (r < 0)
                         return log_error_errno(r, "Failed to acquire disk GPT uuid: %m");
@@ -2450,7 +2447,8 @@ static int context_load_partition_table(Context *context) {
                 r = fdisk_set_disklabel_id(c);
                 if (r < 0)
                         return log_error_errno(r, "Failed to set GPT disk label: %m");
-        }
+        } else if (r < 0)
+                return log_error_errno(r, "Failed to parse current GPT disk label UUID: %m");
 
         r = fdisk_get_partitions(c, &t);
         if (r < 0)
index ec4b53b2e8ee75532eb1a745eab81b64b1b3c332..68c4b2ca1af0bb2f1a9fc7ed511d246081f58a96 100644 (file)
@@ -19,6 +19,7 @@
 #include "fileio.h"
 #include "fs-util.h"
 #include "hostname-util.h"
+#include "id128-util.h"
 #include "in-addr-util.h"
 #include "log.h"
 #include "macro.h"
@@ -944,25 +945,19 @@ int config_parse_id128(
                 void *data,
                 void *userdata) {
 
-        sd_id128_t t, *result = data;
+        sd_id128_t *result = data;
         int r;
 
         assert(filename);
         assert(lvalue);
         assert(rvalue);
 
-        r = sd_id128_from_string(rvalue, &t);
-        if (r < 0) {
+        r = id128_from_string_nonzero(rvalue, result);
+        if (r == -ENXIO)
+                log_syntax(unit, LOG_WARNING, filename, line, r, "128-bit ID/UUID is all 0, ignoring: %s", rvalue);
+        else if (r < 0)
                 log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 128-bit ID/UUID, ignoring: %s", rvalue);
-                return 0;
-        }
-
-        if (sd_id128_is_null(t)) {
-                log_syntax(unit, LOG_WARNING, filename, line, 0, "128-bit ID/UUID is all 0, ignoring: %s", rvalue);
-                return 0;
-        }
 
-        *result = t;
         return 0;
 }