diff options
-rw-r--r-- | man/hostnamectl.xml | 21 | ||||
-rw-r--r-- | man/machine-info.xml | 17 | ||||
-rw-r--r-- | src/hostname/hostnamectl.c | 20 | ||||
-rw-r--r-- | src/hostname/hostnamed.c | 46 |
4 files changed, 96 insertions, 8 deletions
diff --git a/man/hostnamectl.xml b/man/hostnamectl.xml index a158e67519..99f984f2ce 100644 --- a/man/hostnamectl.xml +++ b/man/hostnamectl.xml @@ -231,6 +231,27 @@ </listitem> </varlistentry> + <varlistentry> + <term><command>set-deployment <replaceable>ENVIRONMENT</replaceable></command></term> + + <listitem><para>Set the deployment + environment description. + <replaceable>ENVIRONMENT</replaceable> + must be a single word without any + control characters. One of the + following is suggested: + <literal>development</literal>, + <literal>integration</literal>, + <literal>staging</literal>, + <literal>production</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 244e9b69cf..a2ad4e6d11 100644 --- a/man/machine-info.xml +++ b/man/machine-info.xml @@ -157,6 +157,20 @@ available.</para></listitem> </varlistentry> + <varlistentry> + <term><varname>DEPLOYMENT=</varname></term> + + <listitem><para>Describes the system + deployment environment. One of the + following is suggested: + <literal>development</literal>, + <literal>integration</literal>, + <literal>staging</literal>, + <literal>production</literal>. + </para></listitem> + </varlistentry> + + </variablelist> </refsect1> @@ -166,7 +180,8 @@ <programlisting>PRETTY_HOSTNAME="Lennart's Tablet" ICON_NAME=computer-tablet -CHASSIS=tablet</programlisting> +CHASSIS=tablet +DEPLOYMENT=production</programlisting> </refsect1> <refsect1> diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c index 267cd74011..7e6922b0a0 100644 --- a/src/hostname/hostnamectl.c +++ b/src/hostname/hostnamectl.c @@ -67,6 +67,7 @@ typedef struct StatusInfo { char *pretty_hostname; char *icon_name; char *chassis; + char *deployment; char *kernel_name; char *kernel_release; char *os_pretty_name; @@ -92,9 +93,11 @@ static void print_status_info(StatusInfo *i) { printf("Transient hostname: %s\n", i->hostname); printf(" Icon name: %s\n" - " Chassis: %s\n", + " Chassis: %s\n" + " Deployment: %s\n", strna(i->icon_name), - strna(i->chassis)); + strna(i->chassis), + strna(i->deployment)); r = sd_id128_get_machine(&mid); if (r >= 0) @@ -157,6 +160,7 @@ 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) }, + { "Deployment", "s", NULL, offsetof(StatusInfo, deployment) }, { "KernelName", "s", NULL, offsetof(StatusInfo, kernel_name) }, { "KernelRelease", "s", NULL, offsetof(StatusInfo, kernel_release) }, { "OperatingSystemPrettyName", "s", NULL, offsetof(StatusInfo, os_pretty_name) }, @@ -194,6 +198,7 @@ fail: free(info.pretty_hostname); free(info.icon_name); free(info.chassis); + free(info.deployment); free(info.kernel_name); free(info.kernel_release); free(info.os_pretty_name); @@ -309,6 +314,13 @@ static int set_chassis(sd_bus *bus, char **args, unsigned n) { return set_simple_string(bus, "SetChassis", args[1]); } +static int set_deployment(sd_bus *bus, char **args, unsigned n) { + assert(args); + assert(n == 2); + + return set_simple_string(bus, "SetDeployment", args[1]); +} + static int help(void) { printf("%s [OPTIONS...] COMMAND ...\n\n" @@ -325,7 +337,8 @@ static int help(void) { " status Show current hostname settings\n" " set-hostname NAME Set system hostname\n" " set-icon-name NAME Set icon name for host\n" - " set-chassis NAME Set chassis type for host\n", + " set-chassis NAME Set chassis type for host\n" + " set-deployment NAME Set deployment environment for host\n", program_invocation_short_name); return 0; @@ -423,6 +436,7 @@ static int hostnamectl_main(sd_bus *bus, int argc, char *argv[]) { { "set-hostname", EQUAL, 2, set_hostname }, { "set-icon-name", EQUAL, 2, set_icon_name }, { "set-chassis", EQUAL, 2, set_chassis }, + { "set-deployment", EQUAL, 2, set_deployment }, }; int left; diff --git a/src/hostname/hostnamed.c b/src/hostname/hostnamed.c index eaae1139fa..a4849b3673 100644 --- a/src/hostname/hostnamed.c +++ b/src/hostname/hostnamed.c @@ -35,12 +35,15 @@ #include "bus-util.h" #include "event-util.h" +#define VALID_DEPLOYMENT_CHARS (DIGITS LETTERS "-.:") + enum { PROP_HOSTNAME, PROP_STATIC_HOSTNAME, PROP_PRETTY_HOSTNAME, PROP_ICON_NAME, PROP_CHASSIS, + PROP_DEPLOYMENT, PROP_KERNEL_NAME, PROP_KERNEL_RELEASE, PROP_KERNEL_VERSION, @@ -100,6 +103,7 @@ static int context_read_data(Context *c) { "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME], "ICON_NAME", &c->data[PROP_ICON_NAME], "CHASSIS", &c->data[PROP_CHASSIS], + "DEPLOYMENT", &c->data[PROP_DEPLOYMENT], NULL); if (r < 0 && r != -ENOENT) return r; @@ -134,7 +138,6 @@ static bool check_nss(void) { } static bool valid_chassis(const char *chassis) { - assert(chassis); return nulstr_contains( @@ -149,6 +152,12 @@ static bool valid_chassis(const char *chassis) { chassis); } +static bool valid_deployment(const char *deployment) { + assert(deployment); + + return strspn(deployment, VALID_DEPLOYMENT_CHARS) == strlen(deployment); +} + static const char* fallback_chassis(void) { int r; char *type; @@ -258,6 +267,7 @@ static char* context_fallback_icon_name(Context *c) { return strdup("computer"); } + static bool hostname_is_useful(const char *hn) { return !isempty(hn) && !is_localhost(hn); } @@ -312,7 +322,8 @@ static int context_write_data_machine_info(Context *c) { static const char * const name[_PROP_MAX] = { [PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME", [PROP_ICON_NAME] = "ICON_NAME", - [PROP_CHASSIS] = "CHASSIS" + [PROP_CHASSIS] = "CHASSIS", + [PROP_DEPLOYMENT] = "DEPLOYMENT", }; _cleanup_strv_free_ char **l = NULL; @@ -324,7 +335,7 @@ static int context_write_data_machine_info(Context *c) { if (r < 0 && r != -ENOENT) return r; - for (p = PROP_PRETTY_HOSTNAME; p <= PROP_CHASSIS; p++) { + for (p = PROP_PRETTY_HOSTNAME; p <= PROP_DEPLOYMENT; p++) { char *t, **u; assert(name[p]); @@ -402,6 +413,23 @@ 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; @@ -555,6 +583,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 pretty host name '%s'", name); if (prop == PROP_CHASSIS && !valid_chassis(name)) 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); h = strdup(name); if (!h) @@ -572,11 +602,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_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_CHASSIS ? "Chassis" : "IconName", NULL); + prop == PROP_DEPLOYMENT ? "Deployment" : + prop == PROP_CHASSIS ? "Chassis" : "IconName" , NULL); return sd_bus_reply_method_return(m, NULL); } @@ -593,6 +625,10 @@ static int method_set_chassis(sd_bus *bus, sd_bus_message *m, void *userdata, sd return set_machine_info(userdata, bus, m, PROP_CHASSIS, method_set_chassis, error); } +static int method_set_deployment(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) { + return set_machine_info(userdata, bus, m, PROP_DEPLOYMENT, method_set_deployment, 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), @@ -600,6 +636,7 @@ 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("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), @@ -610,6 +647,7 @@ static const sd_bus_vtable hostname_vtable[] = { SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_hostname, SD_BUS_VTABLE_UNPRIVILEGED), 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_VTABLE_END, }; |