[systemd-commits] man/hostnamectl.xml man/machine-info.xml src/hostname

Lennart Poettering lennart at kemper.freedesktop.org
Fri Jul 11 06:50:55 PDT 2014


 man/hostnamectl.xml      |   21 +++++++++++++++++++--
 man/machine-info.xml     |   12 +++++++++++-
 src/hostname/hostnamed.c |   34 +++++++++++++++-------------------
 3 files changed, 45 insertions(+), 22 deletions(-)

New commits:
commit ce0f1493c399178a3c7796415bfe5abd105ad610
Author: Lennart Poettering <lennart at poettering.net>
Date:   Fri Jul 11 15:50:32 2014 +0200

    hostnamed: introduce new location machin-info field, too

diff --git a/man/hostnamectl.xml b/man/hostnamectl.xml
index 99f984f..128d92f 100644
--- a/man/hostnamectl.xml
+++ b/man/hostnamectl.xml
@@ -235,8 +235,8 @@
                                 <term><command>set-deployment <replaceable>ENVIRONMENT</replaceable></command></term>
 
                                 <listitem><para>Set the deployment
-                                environment description.
-                                <replaceable>ENVIRONMENT</replaceable>
+                                environment
+                                description. <replaceable>ENVIRONMENT</replaceable>
                                 must be a single word without any
                                 control characters. One of the
                                 following is suggested:
@@ -251,7 +251,24 @@
                                 </listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><command>set-location <replaceable>LOCATION</replaceable></command></term>
+
+                                <listitem><para>Set the location
+                                string for the system, if it is
+                                known. <replaceable>LOCATION</replaceable>
+                                should be a human-friendly, free-form
+                                string describing the physical
+                                location of the system, if it is known
+                                and applicable. This may be as generic
+                                as <literal>Berlin, Germany</literal>
+                                or as specific as <literal>Left Rack,
+                                2nd Shelf</literal>.</para>
 
+                                <para>Pass an empty string to reset to
+                                the default empty value.</para>
+                                </listitem>
+                        </varlistentry>
                 </variablelist>
         </refsect1>
 
diff --git a/man/machine-info.xml b/man/machine-info.xml
index a2ad4e6..c654daa 100644
--- a/man/machine-info.xml
+++ b/man/machine-info.xml
@@ -170,9 +170,19 @@
                                 </para></listitem>
                         </varlistentry>
 
+                        <varlistentry>
+                                <term><varname>LOCATION=</varname></term>
 
+                                <listitem><para>Describes the system
+                                location if applicable and
+                                known. Takes a human-friendly,
+                                free-form string. This may be as
+                                generic as <literal>Berlin,
+                                Germany</literal> or as specific as
+                                <literal>Left Rack, 2nd
+                                Shelf</literal>.</para></listitem>
+                        </varlistentry>
                 </variablelist>
-
         </refsect1>
 
         <refsect1>
diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c
index 8b6aebf..74d9dab 100644
--- a/src/hostname/hostnamed.c
+++ b/src/hostname/hostnamed.c
@@ -43,6 +43,7 @@ enum {
         PROP_ICON_NAME,
         PROP_CHASSIS,
         PROP_DEPLOYMENT,
+        PROP_LOCATION,
         PROP_KERNEL_NAME,
         PROP_KERNEL_RELEASE,
         PROP_KERNEL_VERSION,
@@ -103,6 +104,7 @@ static int context_read_data(Context *c) {
                            "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;
@@ -311,6 +313,7 @@ static int context_write_data_machine_info(Context *c) {
                 [PROP_ICON_NAME] = "ICON_NAME",
                 [PROP_CHASSIS] = "CHASSIS",
                 [PROP_DEPLOYMENT] = "DEPLOYMENT",
+                [PROP_LOCATION] = "LOCATION",
         };
 
         _cleanup_strv_free_ char **l = NULL;
@@ -322,7 +325,7 @@ static int context_write_data_machine_info(Context *c) {
         if (r < 0 && r != -ENOENT)
                 return r;
 
-        for (p = PROP_PRETTY_HOSTNAME; p <= PROP_DEPLOYMENT; p++) {
+        for (p = PROP_PRETTY_HOSTNAME; p <= PROP_LOCATION; p++) {
                 _cleanup_free_ char *t = NULL;
                 char **u;
 
@@ -399,23 +402,6 @@ static int property_get_chassis(
         return sd_bus_message_append(reply, "s", name);
 }
 
-static int property_get_deployment(
-                sd_bus *bus,
-                const char *path,
-                const char *interface,
-                const char *property,
-                sd_bus_message *reply,
-                void *userdata,
-                sd_bus_error *error) {
-
-        Context *c = userdata;
-        const char *name;
-
-        name = c->data[PROP_DEPLOYMENT];
-
-        return sd_bus_message_append(reply, "s", name);
-}
-
 static int method_set_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
         Context *c = userdata;
         const char *name;
@@ -571,6 +557,8 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid chassis '%s'", name);
                 if (prop == PROP_DEPLOYMENT && !valid_deployment(name))
                         return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid deployment '%s'", name);
+                if (prop == PROP_LOCATION && string_has_cc(name, NULL))
+                        return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid location '%s'", name);
 
                 h = strdup(name);
                 if (!h)
@@ -589,11 +577,13 @@ static int set_machine_info(Context *c, sd_bus *bus, sd_bus_message *m, int prop
         log_info("Changed %s to '%s'",
                  prop == PROP_PRETTY_HOSTNAME ? "pretty host name" :
                  prop == PROP_DEPLOYMENT ? "deployment" :
+                 prop == PROP_LOCATION ? "location" :
                  prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->data[prop]));
 
         sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", "org.freedesktop.hostname1",
                                        prop == PROP_PRETTY_HOSTNAME ? "PrettyHostname" :
                                        prop == PROP_DEPLOYMENT ? "Deployment" :
+                                       prop == PROP_LOCATION ? "Location" :
                                        prop == PROP_CHASSIS ? "Chassis" : "IconName" , NULL);
 
         return sd_bus_reply_method_return(m, NULL);
@@ -615,6 +605,10 @@ static int method_set_deployment(sd_bus *bus, sd_bus_message *m, void *userdata,
         return set_machine_info(userdata, bus, m, PROP_DEPLOYMENT, method_set_deployment, error);
 }
 
+static int method_set_location(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) {
+        return set_machine_info(userdata, bus, m, PROP_LOCATION, method_set_location, error);
+}
+
 static const sd_bus_vtable hostname_vtable[] = {
         SD_BUS_VTABLE_START(0),
         SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_HOSTNAME, 0),
@@ -622,7 +616,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("Deployment", "s", property_get_deployment, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+        SD_BUS_PROPERTY("Deployment", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_DEPLOYMENT, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
+        SD_BUS_PROPERTY("Location", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_LOCATION, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
         SD_BUS_PROPERTY("KernelName", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_NAME, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("KernelRelease", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_RELEASE, SD_BUS_VTABLE_PROPERTY_CONST),
         SD_BUS_PROPERTY("KernelVersion", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_VERSION, SD_BUS_VTABLE_PROPERTY_CONST),
@@ -634,6 +629,7 @@ static const sd_bus_vtable hostname_vtable[] = {
         SD_BUS_METHOD("SetIconName", "sb", NULL, method_set_icon_name, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("SetChassis", "sb", NULL, method_set_chassis, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_METHOD("SetDeployment", "sb", NULL, method_set_deployment, SD_BUS_VTABLE_UNPRIVILEGED),
+        SD_BUS_METHOD("SetLocation", "sb", NULL, method_set_location, SD_BUS_VTABLE_UNPRIVILEGED),
         SD_BUS_VTABLE_END,
 };
 



More information about the systemd-commits mailing list