[systemd-devel] [PATCH 2/3] hostnamed: expose PrettyName and CpeName as bus properties
Lennart Poettering
lennart at poettering.net
Mon Mar 10 21:00:09 PDT 2014
On Tue, 04.03.14 23:01, Djalal Harouni (tixxdz at opendz.org) wrote:
> ---
> src/hostname/hostnamed.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
> index fab0601..f8aea78 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,
Hmm, this really needs to carry "OS" or so in the name, since this is
not really a property of the host, but of the OS.
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_PRETTY_NAME],
> + "CPE_NAME", &c->data[PROP_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("PrettyName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_NAME, 0),
> + SD_BUS_PROPERTY("CpeName", "s", NULL, offsetof(Context, data)
> + sizeof(char*) * PROP_CPE_NAME, 0),
The propery should probably be OperatingSystemPrettyName and
OperatingSystemCPEName or soo..
Also, please mark these as 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),
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list