static int context_read_data(Context *c) { int r; struct utsname u; assert(c); context_reset(c); assert_se(uname(&u) >= 0); c->data[PROP_KERNEL_NAME] = strdup(u.sysname); c->data[PROP_KERNEL_RELEASE] = strdup(u.release); c->data[PROP_KERNEL_VERSION] = strdup(u.version); if (!c->data[PROP_KERNEL_NAME] || !c->data[PROP_KERNEL_RELEASE] || !c->data[PROP_KERNEL_VERSION]) return -ENOMEM; c->data[PROP_HOSTNAME] = gethostname_malloc(); if (!c->data[PROP_HOSTNAME]) return -ENOMEM; r = read_etc_hostname(NULL, &c->data[PROP_STATIC_HOSTNAME]); if (r < 0 && r != -ENOENT) return r; r = parse_env_file(NULL, "/etc/machine-info", "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME], "ICON_NAME", &c->data[PROP_ICON_NAME], "CHASSIS", &c->data[PROP_CHASSIS], "DEPLOYMENT", &c->data[PROP_DEPLOYMENT], "LOCATION", &c->data[PROP_LOCATION]); if (r < 0 && r != -ENOENT) return r; r = parse_os_release(NULL, "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME], "CPE_NAME", &c->data[PROP_OS_CPE_NAME], "HOME_URL", &c->data[PROP_HOME_URL], NULL); if (r < 0 && r != -ENOENT) return r; r = id128_read("/sys/class/dmi/id/product_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; }
static int context_read_data(Context *c) { int r; struct utsname u; assert(c); context_reset(c); assert_se(uname(&u) >= 0); c->data[PROP_KERNEL_NAME] = strdup(u.sysname); c->data[PROP_KERNEL_RELEASE] = strdup(u.release); c->data[PROP_KERNEL_VERSION] = strdup(u.version); if (!c->data[PROP_KERNEL_NAME] || !c->data[PROP_KERNEL_RELEASE] || !c->data[PROP_KERNEL_VERSION]) return -ENOMEM; c->data[PROP_HOSTNAME] = gethostname_malloc(); if (!c->data[PROP_HOSTNAME]) return -ENOMEM; r = read_etc_hostname(NULL, &c->data[PROP_STATIC_HOSTNAME]); if (r < 0 && r != -ENOENT) return r; r = parse_env_file("/etc/machine-info", NEWLINE, "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME], "ICON_NAME", &c->data[PROP_ICON_NAME], "CHASSIS", &c->data[PROP_CHASSIS], "DEPLOYMENT", &c->data[PROP_DEPLOYMENT], "LOCATION", &c->data[PROP_LOCATION], NULL); if (r < 0 && r != -ENOENT) return r; r = parse_env_file("/etc/os-release", NEWLINE, "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME], "CPE_NAME", &c->data[PROP_OS_CPE_NAME], NULL); if (r == -ENOENT) r = parse_env_file("/usr/lib/os-release", NEWLINE, "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME], "CPE_NAME", &c->data[PROP_OS_CPE_NAME], NULL); if (r < 0 && r != -ENOENT) return r; return 0; }