mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user