[systemd-commits] 3 commits - src/hostname
Lennart Poettering
lennart at kemper.freedesktop.org
Tue Mar 11 09:49:01 PDT 2014
src/hostname/hostnamectl.c | 22 ++++++++++------------
src/hostname/hostnamed.c | 17 ++++++++++++++---
2 files changed, 24 insertions(+), 15 deletions(-)
New commits:
commit 3448456bb20384987a5a6335518072f7c35ba32b
Author: Djalal Harouni <tixxdz at opendz.org>
Date: Tue Mar 11 14:57:16 2014 +0100
hostnamectl: read OS pretty_name and cpe_name from remote
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 94b4243..326f371 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -67,6 +67,8 @@ typedef struct StatusInfo {
char *pretty_hostname;
char *icon_name;
char *chassis;
+ char *os_pretty_name;
+ char *os_cpe_name;
char *virtualization;
char *architecture;
} StatusInfo;
@@ -74,7 +76,6 @@ typedef struct StatusInfo {
static void print_status_info(StatusInfo *i) {
sd_id128_t mid = {}, bid = {};
int r;
- _cleanup_free_ char *pretty_name = NULL, *cpe_name = NULL;
struct utsname u;
assert(i);
@@ -105,18 +106,11 @@ static void print_status_info(StatusInfo *i) {
if (!isempty(i->virtualization))
printf(" Virtualization: %s\n", i->virtualization);
- r = parse_env_file("/etc/os-release", NEWLINE,
- "PRETTY_NAME", &pretty_name,
- "CPE_NAME", &cpe_name,
- NULL);
- if (r < 0)
- log_warning("Failed to read /etc/os-release: %s", strerror(-r));
-
- if (!isempty(pretty_name))
- printf(" Operating System: %s\n", pretty_name);
+ if (!isempty(i->os_pretty_name))
+ printf(" Operating System: %s\n", i->os_pretty_name);
- if (!isempty(cpe_name))
- printf(" CPE OS Name: %s\n", cpe_name);
+ if (!isempty(i->os_cpe_name))
+ printf(" CPE OS Name: %s\n", i->os_cpe_name);
assert_se(uname(&u) >= 0);
printf(" Kernel: %s %s\n", u.sysname, u.release);
@@ -162,6 +156,8 @@ static int show_all_names(sd_bus *bus) {
{ "PrettyHostname", "s", NULL, offsetof(StatusInfo, pretty_hostname) },
{ "IconName", "s", NULL, offsetof(StatusInfo, icon_name) },
{ "Chassis", "s", NULL, offsetof(StatusInfo, chassis) },
+ { "OperatingSystemPrettyName", "s", NULL, offsetof(StatusInfo, os_pretty_name) },
+ { "OperatingSystemCPEName", "s", NULL, offsetof(StatusInfo, os_cpe_name) },
{}
};
@@ -195,6 +191,8 @@ fail:
free(info.pretty_hostname);
free(info.icon_name);
free(info.chassis);
+ free(info.os_pretty_name);
+ free(info.os_cpe_name);
free(info.virtualization);
free(info.architecture);
commit 44c3298855b60d4635b1be989d7abf0b87070935
Author: Djalal Harouni <tixxdz at opendz.org>
Date: Tue Mar 11 14:57:15 2014 +0100
hostnamed: expose OperatingSystemPrettyName and OperatingSystemCPEName on the bus
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index fab0601..3b19d43 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -40,6 +40,8 @@ enum {
PROP_PRETTY_HOSTNAME,
PROP_ICON_NAME,
PROP_CHASSIS,
+ PROP_OS_PRETTY_NAME,
+ PROP_OS_CPE_NAME,
_PROP_MAX
};
@@ -89,6 +91,13 @@ static int context_read_data(Context *c) {
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 < 0 && r != -ENOENT)
+ return r;
+
return 0;
}
@@ -546,6 +555,8 @@ static const sd_bus_vtable hostname_vtable[] = {
SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("IconName", "s", property_get_icon_name, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+ SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("OperatingSystemCPEName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_METHOD("SetHostname", "sb", NULL, method_set_hostname, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetStaticHostname", "sb", NULL, method_set_static_hostname, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_hostname, SD_BUS_VTABLE_UNPRIVILEGED),
commit f200e8bb34d08616dbcb03d6503d0610f4e7e5bc
Author: Djalal Harouni <tixxdz at opendz.org>
Date: Tue Mar 11 14:57:14 2014 +0100
hostnamed: minor improvements in context_write_data_other()
Prepare context_write_data_other() and rename it to
context_write_data_machine_info()
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 6aa08ca..fab0601 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -258,7 +258,7 @@ static int context_write_data_static_hostname(Context *c) {
return write_string_file_atomic_label("/etc/hostname", c->data[PROP_STATIC_HOSTNAME]);
}
-static int context_write_data_other(Context *c) {
+static int context_write_data_machine_info(Context *c) {
static const char * const name[_PROP_MAX] = {
[PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME",
@@ -275,7 +275,7 @@ static int context_write_data_other(Context *c) {
if (r < 0 && r != -ENOENT)
return r;
- for (p = 2; p < _PROP_MAX; p++) {
+ for (p = PROP_PRETTY_HOSTNAME; p <= PROP_CHASSIS; p++) {
char *t, **u;
assert(name[p]);
@@ -510,7 +510,7 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
c->data[prop] = h;
}
- r = context_write_data_other(c);
+ r = context_write_data_machine_info(c);
if (r < 0) {
log_error("Failed to write machine info: %s", strerror(-r));
return sd_bus_error_set_errnof(error, r, "Failed to write machine info: %s", strerror(-r));
More information about the systemd-commits
mailing list