hostname: two trivial cleanups (#37583)

This commit is contained in:
Yu Watanabe
2025-05-24 01:56:25 +09:00
committed by GitHub

View File

@@ -101,7 +101,7 @@ typedef struct Context {
static void context_reset(Context *c, uint64_t mask) {
assert(c);
for (int p = 0; p < _PROP_MAX; p++) {
for (HostProperty p = 0; p < _PROP_MAX; p++) {
if (!BIT_SET(mask, p))
continue;
@@ -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;
}
@@ -845,7 +844,7 @@ static int context_write_data_machine_info(Context *c) {
if (r < 0 && r != -ENOENT)
return r;
for (int p = PROP_PRETTY_HOSTNAME; p <= PROP_LOCATION; p++) {
for (HostProperty p = PROP_PRETTY_HOSTNAME; p <= PROP_LOCATION; p++) {
assert(name[p]);
r = strv_env_assign(&l, name[p], empty_to_null(c->data[p]));