[systemd-devel] [PATCH 1/2] hostnamed: expose OperatingSystemName and OperatingSystemRelease on the bus
Lennart Poettering
lennart at poettering.net
Wed Apr 23 14:05:53 PDT 2014
On Thu, 27.03.14 19:48, Djalal Harouni (tixxdz at opendz.org) wrote:
Hmm, thinking about this again, given that this is actually the kernel
identity we return here we should really name those props KernelName and
KernelRelease...
Sorry for the constant forth and back!
Otherwise looks great, can you ren ame the props? will then merge!
> ---
> src/hostname/hostnamed.c | 12 ++++++++++++
> 1 file changed, 12 insertions(+)
>
> diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
> index 3b19d43..abafa62 100644
> --- a/src/hostname/hostnamed.c
> +++ b/src/hostname/hostnamed.c
> @@ -23,6 +23,7 @@
> #include <string.h>
> #include <unistd.h>
> #include <dlfcn.h>
> +#include <sys/utsname.h>
>
> #include "util.h"
> #include "strv.h"
> @@ -40,6 +41,8 @@ enum {
> PROP_PRETTY_HOSTNAME,
> PROP_ICON_NAME,
> PROP_CHASSIS,
> + PROP_OS_NAME,
> + PROP_OS_RELEASE,
> PROP_OS_PRETTY_NAME,
> PROP_OS_CPE_NAME,
> _PROP_MAX
> @@ -70,11 +73,18 @@ static void context_free(Context *c, sd_bus *bus) {
>
> 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_OS_NAME] = strdup(u.sysname);
> + c->data[PROP_OS_RELEASE] = strdup(u.release);
> + if (!c->data[PROP_OS_NAME] || !c->data[PROP_OS_RELEASE])
> + return -ENOMEM;
> +
> c->data[PROP_HOSTNAME] = gethostname_malloc();
> if (!c->data[PROP_HOSTNAME])
> return -ENOMEM;
> @@ -555,6 +565,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("OperatingSystemName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
> + SD_BUS_PROPERTY("OperatingSystemRelease", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_OS_RELEASE, SD_BUS_VTABLE_PROPERTY_CONST),
> 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),
Lennart
--
Lennart Poettering, Red Hat
More information about the systemd-devel
mailing list