hostnamed.c revision f3f4f0086ea45ce82658d5fd8a9a36f25685043f
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier This file is part of systemd.
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier Copyright 2011 Lennart Poettering
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier systemd is free software; you can redistribute it and/or modify it
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier under the terms of the GNU Lesser General Public License as published by
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier the Free Software Foundation; either version 2.1 of the License, or
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier (at your option) any later version.
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier systemd is distributed in the hope that it will be useful, but
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier WITHOUT ANY WARRANTY; without even the implied warranty of
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier Lesser General Public License for more details.
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier You should have received a copy of the GNU Lesser General Public License
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier along with systemd; If not, see <http://www.gnu.org/licenses/>.
e6b5c5d03cb28d2149dc1c124c2a315911b91f4fRonny Chevalier#define VALID_DEPLOYMENT_CHARS (DIGITS LETTERS "-.:")
typedef struct Context {
} Context;
assert(c);
for (p = 0; p < _PROP_MAX; p++)
assert(c);
context_reset(c);
struct utsname u;
assert(c);
context_reset(c);
return -ENOMEM;
return -ENOMEM;
if (r < 0 && r != -ENOENT)
NULL);
if (r < 0 && r != -ENOENT)
NULL);
if (r == -ENOENT)
NULL);
if (r < 0 && r != -ENOENT)
return nulstr_contains(
chassis);
static const char* fallback_chassis(void) {
char *type;
v = detect_virtualization();
if (VIRTUALIZATION_IS_VM(v))
if (VIRTUALIZATION_IS_CONTAINER(v))
goto try_dmi;
goto try_dmi;
return NULL;
return NULL;
return NULL;
const char *chassis;
assert(c);
if (chassis)
const char *static_hn;
const char *hn;
assert(c);
return -errno;
assert(c);
assert(c);
if (r < 0 && r != -ENOENT)
return -ENOMEM;
u = strv_env_set(l, t);
return -ENOMEM;
strv_free(l);
if (strv_isempty(l)) {
static int property_get_icon_name(
const char *path,
const char *interface,
const char *property,
void *userdata,
const char *name;
if (!name)
return -ENOMEM;
static int property_get_chassis(
const char *path,
const char *interface,
const char *property,
void *userdata,
const char *name;
const char *name;
int interactive;
assert(m);
assert(c);
"org.freedesktop.hostname1.set-hostname",
NULL,
&c->polkit_registry,
error);
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
return -ENOMEM;
r = context_update_kernel_hostname(c);
(void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "Hostname", NULL);
const char *name;
int interactive;
assert(m);
assert(c);
"org.freedesktop.hostname1.set-static-hostname",
NULL,
&c->polkit_registry,
error);
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
return -ENOMEM;
r = context_update_kernel_hostname(c);
(void) sd_bus_emit_properties_changed(sd_bus_message_get_bus(m), "/org/freedesktop/hostname1", "org.freedesktop.hostname1", "StaticHostname", NULL);
static int set_machine_info(Context *c, sd_bus_message *m, int prop, sd_bus_message_handler_t cb, sd_bus_error *error) {
int interactive;
const char *name;
assert(c);
assert(m);
prop == PROP_PRETTY_HOSTNAME ? "org.freedesktop.hostname1.set-static-hostname" : "org.freedesktop.hostname1.set-machine-info",
NULL,
&c->polkit_registry,
error);
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */
return -ENOMEM;
r = context_write_data_machine_info(c);
(void) sd_bus_emit_properties_changed(
"/org/freedesktop/hostname1",
"org.freedesktop.hostname1",
SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("StaticHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_STATIC_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_PRETTY_HOSTNAME, 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),
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("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),
assert(c);
r = sd_bus_add_object_vtable(bus, NULL, "/org/freedesktop/hostname1", "org.freedesktop.hostname1", hostname_vtable, c);
log_open();
r = -EINVAL;
goto finish;
goto finish;
goto finish;
goto finish;
r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1", DEFAULT_EXIT_USEC, NULL, NULL);
goto finish;