From: Zbigniew Jędrzejewski-Szmek Date: Sat, 26 Aug 2023 13:13:05 +0000 (+0200) Subject: various: use id128_from_string_not_null() X-Git-Tag: v255-rc1~598^2~5 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=aea3f594db3d11966fb0ead86c07d83dfeb5fe69;p=thirdparty%2Fsystemd.git various: use id128_from_string_not_null() 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. --- diff --git a/src/core/main.c b/src/core/main.c index df9cfa21aad..7a8652df03e 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -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; diff --git a/src/network/networkd-address-generation.c b/src/network/networkd-address-generation.c index 769cccf7484..79fde024a36 100644 --- a/src/network/networkd-address-generation.c +++ b/src/network/networkd-address-generation.c @@ -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; } diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d3ae547746a..9e74ead8d58 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -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; diff --git a/src/partition/repart.c b/src/partition/repart.c index e403012e92d..b6fe9ef79ee 100644 --- a/src/partition/repart.c +++ b/src/partition/repart.c @@ -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) diff --git a/src/shared/conf-parser.c b/src/shared/conf-parser.c index ec4b53b2e8e..68c4b2ca1af 100644 --- a/src/shared/conf-parser.c +++ b/src/shared/conf-parser.c @@ -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; }