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.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2023-08-26 15:13:05 +02:00
parent 7c9de5d85d
commit aea3f594db
5 changed files with 19 additions and 46 deletions

View 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;

View 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;
}

View 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;

View 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)

View 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;
}