hostnamed: don't cache system UUID
There's no point in caching this. Let's always get this directly from sysfs, so that we can never get out-of-date data here (after all this is going to be cheap, and people might overmount it or so)
This commit is contained in:
parent
72f48cd3e3
commit
5704cd733c
|
@ -52,8 +52,6 @@ enum {
|
|||
typedef struct Context {
|
||||
char *data[_PROP_MAX];
|
||||
Hashmap *polkit_registry;
|
||||
sd_id128_t uuid;
|
||||
bool has_uuid;
|
||||
} Context;
|
||||
|
||||
static void context_reset(Context *c) {
|
||||
|
@ -104,17 +102,6 @@ static int context_read_data(Context *c) {
|
|||
if (r < 0 && r != -ENOENT)
|
||||
return r;
|
||||
|
||||
r = id128_read("/sys/class/dmi/id/product_uuid", ID128_UUID, &c->uuid);
|
||||
if (r == -ENOENT)
|
||||
r = id128_read("/sys/firmware/devicetree/base/vm,uuid", ID128_UUID, &c->uuid);
|
||||
if (r < 0)
|
||||
log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to read product UUID, ignoring: %m");
|
||||
else if (sd_id128_is_null(c->uuid) || sd_id128_is_allf(c->uuid))
|
||||
log_debug("DMI product UUID " SD_ID128_FORMAT_STR " is all 0x00 or all 0xFF, ignoring.", SD_ID128_FORMAT_VAL(c->uuid));
|
||||
else
|
||||
c->has_uuid = true;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -631,13 +618,27 @@ static int method_set_location(sd_bus_message *m, void *userdata, sd_bus_error *
|
|||
static int method_get_product_uuid(sd_bus_message *m, void *userdata, sd_bus_error *error) {
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
|
||||
Context *c = userdata;
|
||||
bool has_uuid = false;
|
||||
int interactive, r;
|
||||
sd_id128_t uuid;
|
||||
|
||||
assert(m);
|
||||
assert(c);
|
||||
|
||||
if (!c->has_uuid)
|
||||
return sd_bus_error_set(error, BUS_ERROR_NO_PRODUCT_UUID, "Failed to read product UUID from /sys/class/dmi/id/product_uuid");
|
||||
r = id128_read("/sys/class/dmi/id/product_uuid", ID128_UUID, &uuid);
|
||||
if (r == -ENOENT)
|
||||
r = id128_read("/sys/firmware/devicetree/base/vm,uuid", ID128_UUID, &uuid);
|
||||
if (r < 0)
|
||||
log_full_errno(r == -ENOENT ? LOG_DEBUG : LOG_WARNING, r,
|
||||
"Failed to read product UUID, ignoring: %m");
|
||||
else if (sd_id128_is_null(uuid) || sd_id128_is_allf(uuid))
|
||||
log_debug("DMI product UUID " SD_ID128_FORMAT_STR " is all 0x00 or all 0xFF, ignoring.", SD_ID128_FORMAT_VAL(uuid));
|
||||
else
|
||||
has_uuid = true;
|
||||
|
||||
if (!has_uuid)
|
||||
return sd_bus_error_set(error, BUS_ERROR_NO_PRODUCT_UUID,
|
||||
"Failed to read product UUID from firmware.");
|
||||
|
||||
r = sd_bus_message_read(m, "b", &interactive);
|
||||
if (r < 0)
|
||||
|
@ -661,7 +662,7 @@ static int method_get_product_uuid(sd_bus_message *m, void *userdata, sd_bus_err
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_append_array(reply, 'y', &c->uuid, sizeof(c->uuid));
|
||||
r = sd_bus_message_append_array(reply, 'y', &uuid, sizeof(uuid));
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
Loading…
Reference in New Issue