hostnamed.c | hostnamed.c | |||
---|---|---|---|---|
skipping to change at line 25 | skipping to change at line 25 | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
Lesser General Public License for more details. | Lesser General Public License for more details. | |||
You should have received a copy of the GNU Lesser General Public License | You should have received a copy of the GNU Lesser General Public License | |||
along with systemd; If not, see <http://www.gnu.org/licenses/>. | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |||
***/ | ***/ | |||
#include <errno.h> | #include <errno.h> | |||
#include <string.h> | #include <string.h> | |||
#include <unistd.h> | #include <unistd.h> | |||
#include <dlfcn.h> | ||||
#include <sys/utsname.h> | #include <sys/utsname.h> | |||
#include <sys/capability.h> | ||||
#include "util.h" | #include "util.h" | |||
#include "strv.h" | #include "strv.h" | |||
#include "def.h" | #include "def.h" | |||
#include "virt.h" | #include "virt.h" | |||
#include "env-util.h" | #include "env-util.h" | |||
#include "fileio-label.h" | #include "fileio-label.h" | |||
#include "label.h" | #include "label.h" | |||
#include "bus-util.h" | #include "bus-util.h" | |||
#include "event-util.h" | #include "event-util.h" | |||
#define VALID_DEPLOYMENT_CHARS (DIGITS LETTERS "-.:") | ||||
enum { | enum { | |||
PROP_HOSTNAME, | PROP_HOSTNAME, | |||
PROP_STATIC_HOSTNAME, | PROP_STATIC_HOSTNAME, | |||
PROP_PRETTY_HOSTNAME, | PROP_PRETTY_HOSTNAME, | |||
PROP_ICON_NAME, | PROP_ICON_NAME, | |||
PROP_CHASSIS, | PROP_CHASSIS, | |||
PROP_DEPLOYMENT, | ||||
PROP_LOCATION, | ||||
PROP_KERNEL_NAME, | PROP_KERNEL_NAME, | |||
PROP_KERNEL_RELEASE, | PROP_KERNEL_RELEASE, | |||
PROP_KERNEL_VERSION, | PROP_KERNEL_VERSION, | |||
PROP_OS_PRETTY_NAME, | PROP_OS_PRETTY_NAME, | |||
PROP_OS_CPE_NAME, | PROP_OS_CPE_NAME, | |||
_PROP_MAX | _PROP_MAX | |||
}; | }; | |||
typedef struct Context { | typedef struct Context { | |||
char *data[_PROP_MAX]; | char *data[_PROP_MAX]; | |||
skipping to change at line 68 | skipping to change at line 72 | |||
int p; | int p; | |||
assert(c); | assert(c); | |||
for (p = 0; p < _PROP_MAX; p++) { | for (p = 0; p < _PROP_MAX; p++) { | |||
free(c->data[p]); | free(c->data[p]); | |||
c->data[p] = NULL; | c->data[p] = NULL; | |||
} | } | |||
} | } | |||
static void context_free(Context *c, sd_bus *bus) { | static void context_free(Context *c) { | |||
assert(c); | assert(c); | |||
context_reset(c); | context_reset(c); | |||
bus_verify_polkit_async_registry_free(bus, c->polkit_registry); | bus_verify_polkit_async_registry_free(c->polkit_registry); | |||
} | } | |||
static int context_read_data(Context *c) { | static int context_read_data(Context *c) { | |||
int r; | int r; | |||
struct utsname u; | struct utsname u; | |||
assert(c); | assert(c); | |||
context_reset(c); | context_reset(c); | |||
skipping to change at line 103 | skipping to change at line 107 | |||
return -ENOMEM; | return -ENOMEM; | |||
r = read_one_line_file("/etc/hostname", &c->data[PROP_STATIC_HOSTNA ME]); | r = read_one_line_file("/etc/hostname", &c->data[PROP_STATIC_HOSTNA ME]); | |||
if (r < 0 && r != -ENOENT) | if (r < 0 && r != -ENOENT) | |||
return r; | return r; | |||
r = parse_env_file("/etc/machine-info", NEWLINE, | r = parse_env_file("/etc/machine-info", NEWLINE, | |||
"PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME ], | "PRETTY_HOSTNAME", &c->data[PROP_PRETTY_HOSTNAME ], | |||
"ICON_NAME", &c->data[PROP_ICON_NAME], | "ICON_NAME", &c->data[PROP_ICON_NAME], | |||
"CHASSIS", &c->data[PROP_CHASSIS], | "CHASSIS", &c->data[PROP_CHASSIS], | |||
"DEPLOYMENT", &c->data[PROP_DEPLOYMENT], | ||||
"LOCATION", &c->data[PROP_LOCATION], | ||||
NULL); | NULL); | |||
if (r < 0 && r != -ENOENT) | if (r < 0 && r != -ENOENT) | |||
return r; | return r; | |||
r = parse_env_file("/etc/os-release", NEWLINE, | r = parse_env_file("/etc/os-release", NEWLINE, | |||
"PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME], | "PRETTY_NAME", &c->data[PROP_OS_PRETTY_NAME], | |||
"CPE_NAME", &c->data[PROP_OS_CPE_NAME], | "CPE_NAME", &c->data[PROP_OS_CPE_NAME], | |||
NULL); | NULL); | |||
if (r == -ENOENT) { | if (r == -ENOENT) { | |||
r = parse_env_file("/usr/lib/os-release", NEWLINE, | r = parse_env_file("/usr/lib/os-release", NEWLINE, | |||
skipping to change at line 124 | skipping to change at line 130 | |||
"CPE_NAME", &c->data[PROP_OS_CPE_NAME], | "CPE_NAME", &c->data[PROP_OS_CPE_NAME], | |||
NULL); | NULL); | |||
} | } | |||
if (r < 0 && r != -ENOENT) | if (r < 0 && r != -ENOENT) | |||
return r; | return r; | |||
return 0; | return 0; | |||
} | } | |||
static bool check_nss(void) { | ||||
void *dl; | ||||
dl = dlopen("libnss_myhostname.so.2", RTLD_LAZY); | ||||
if (dl) { | ||||
dlclose(dl); | ||||
return true; | ||||
} | ||||
return false; | ||||
} | ||||
static bool valid_chassis(const char *chassis) { | static bool valid_chassis(const char *chassis) { | |||
assert(chassis); | assert(chassis); | |||
return nulstr_contains( | return nulstr_contains( | |||
"vm\0" | "vm\0" | |||
"container\0" | "container\0" | |||
"desktop\0" | "desktop\0" | |||
"laptop\0" | "laptop\0" | |||
"server\0" | "server\0" | |||
"tablet\0" | "tablet\0" | |||
"handset\0", | "handset\0" | |||
"watch\0", | ||||
chassis); | chassis); | |||
} | } | |||
static bool valid_deployment(const char *deployment) { | ||||
assert(deployment); | ||||
return in_charset(deployment, VALID_DEPLOYMENT_CHARS); | ||||
} | ||||
static const char* fallback_chassis(void) { | static const char* fallback_chassis(void) { | |||
int r; | int r; | |||
char *type; | char *type; | |||
unsigned t; | unsigned t; | |||
int v; | int v; | |||
v = detect_virtualization(NULL); | v = detect_virtualization(NULL); | |||
if (v == VIRTUALIZATION_VM) | if (v == VIRTUALIZATION_VM) | |||
return "vm"; | return "vm"; | |||
skipping to change at line 314 | skipping to change at line 314 | |||
return 0; | return 0; | |||
} | } | |||
return write_string_file_atomic_label("/etc/hostname", c->data[PROP _STATIC_HOSTNAME]); | return write_string_file_atomic_label("/etc/hostname", c->data[PROP _STATIC_HOSTNAME]); | |||
} | } | |||
static int context_write_data_machine_info(Context *c) { | static int context_write_data_machine_info(Context *c) { | |||
static const char * const name[_PROP_MAX] = { | static const char * const name[_PROP_MAX] = { | |||
[PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME", | [PROP_PRETTY_HOSTNAME] = "PRETTY_HOSTNAME", | |||
[PROP_ICON_NAME] = "ICON_NAME", | [PROP_ICON_NAME] = "ICON_NAME", | |||
[PROP_CHASSIS] = "CHASSIS" | [PROP_CHASSIS] = "CHASSIS", | |||
[PROP_DEPLOYMENT] = "DEPLOYMENT", | ||||
[PROP_LOCATION] = "LOCATION", | ||||
}; | }; | |||
_cleanup_strv_free_ char **l = NULL; | _cleanup_strv_free_ char **l = NULL; | |||
int r, p; | int r, p; | |||
assert(c); | assert(c); | |||
r = load_env_file(NULL, "/etc/machine-info", NULL, &l); | r = load_env_file(NULL, "/etc/machine-info", NULL, &l); | |||
if (r < 0 && r != -ENOENT) | if (r < 0 && r != -ENOENT) | |||
return r; | return r; | |||
for (p = PROP_PRETTY_HOSTNAME; p <= PROP_CHASSIS; p++) { | for (p = PROP_PRETTY_HOSTNAME; p <= PROP_LOCATION; p++) { | |||
char *t, **u; | _cleanup_free_ char *t = NULL; | |||
char **u; | ||||
assert(name[p]); | assert(name[p]); | |||
if (isempty(c->data[p])) { | if (isempty(c->data[p])) { | |||
strv_env_unset(l, name[p]); | strv_env_unset(l, name[p]); | |||
continue; | continue; | |||
} | } | |||
if (asprintf(&t, "%s=%s", name[p], strempty(c->data[p])) < | t = strjoin(name[p], "=", c->data[p], NULL); | |||
0) | if (!t) | |||
return -ENOMEM; | return -ENOMEM; | |||
u = strv_env_set(l, t); | u = strv_env_set(l, t); | |||
free(t); | ||||
if (!u) | if (!u) | |||
return -ENOMEM; | return -ENOMEM; | |||
strv_free(l); | strv_free(l); | |||
l = u; | l = u; | |||
} | } | |||
if (strv_isempty(l)) { | if (strv_isempty(l)) { | |||
if (unlink("/etc/machine-info") < 0) | if (unlink("/etc/machine-info") < 0) | |||
return errno == ENOENT ? 0 : -errno; | return errno == ENOENT ? 0 : -errno; | |||
return 0; | return 0; | |||
} | } | |||
return write_env_file_label("/etc/machine-info", l); | return write_env_file_label("/etc/machine-info", l); | |||
} | } | |||
static int property_get_icon_name( | static int property_get_icon_name( | |||
skipping to change at line 427 | skipping to change at line 428 | |||
if (isempty(name)) | if (isempty(name)) | |||
name = "localhost"; | name = "localhost"; | |||
if (!hostname_is_valid(name)) | if (!hostname_is_valid(name)) | |||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", name); | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALID_ARGS, "Invalid hostname '%s'", name); | |||
if (streq_ptr(name, c->data[PROP_HOSTNAME])) | if (streq_ptr(name, c->data[PROP_HOSTNAME])) | |||
return sd_bus_reply_method_return(m, NULL); | return sd_bus_reply_method_return(m, NULL); | |||
r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freed esktop.hostname1.set-hostname", interactive, error, method_set_hostname, c) ; | r = bus_verify_polkit_async(m, CAP_SYS_ADMIN, "org.freedesktop.host name1.set-hostname", interactive, &c->polkit_registry, error); | |||
if (r < 0) | if (r < 0) | |||
return r; | return r; | |||
if (r == 0) | if (r == 0) | |||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
h = strdup(name); | h = strdup(name); | |||
if (!h) | if (!h) | |||
return -ENOMEM; | return -ENOMEM; | |||
free(c->data[PROP_HOSTNAME]); | free(c->data[PROP_HOSTNAME]); | |||
skipping to change at line 469 | skipping to change at line 470 | |||
r = sd_bus_message_read(m, "sb", &name, &interactive); | r = sd_bus_message_read(m, "sb", &name, &interactive); | |||
if (r < 0) | if (r < 0) | |||
return r; | return r; | |||
if (isempty(name)) | if (isempty(name)) | |||
name = NULL; | name = NULL; | |||
if (streq_ptr(name, c->data[PROP_STATIC_HOSTNAME])) | if (streq_ptr(name, c->data[PROP_STATIC_HOSTNAME])) | |||
return sd_bus_reply_method_return(m, NULL); | return sd_bus_reply_method_return(m, NULL); | |||
r = bus_verify_polkit_async(bus, &c->polkit_registry, m, "org.freed esktop.hostname1.set-static-hostname", interactive, error, method_set_stati c_hostname, c); | r = bus_verify_polkit_async(m, CAP_SYS_ADMIN, "org.freedesktop.host name1.set-static-hostname", interactive, &c->polkit_registry, error); | |||
if (r < 0) | if (r < 0) | |||
return r; | return r; | |||
if (r == 0) | if (r == 0) | |||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
if (isempty(name)) { | if (isempty(name)) { | |||
free(c->data[PROP_STATIC_HOSTNAME]); | free(c->data[PROP_STATIC_HOSTNAME]); | |||
c->data[PROP_STATIC_HOSTNAME] = NULL; | c->data[PROP_STATIC_HOSTNAME] = NULL; | |||
} else { | } else { | |||
char *h; | char *h; | |||
skipping to change at line 534 | skipping to change at line 535 | |||
if (isempty(name)) | if (isempty(name)) | |||
name = NULL; | name = NULL; | |||
if (streq_ptr(name, c->data[prop])) | if (streq_ptr(name, c->data[prop])) | |||
return sd_bus_reply_method_return(m, NULL); | return sd_bus_reply_method_return(m, NULL); | |||
/* Since the pretty hostname should always be changed at the | /* Since the pretty hostname should always be changed at the | |||
* same time as the static one, use the same policy action for | * same time as the static one, use the same policy action for | |||
* both... */ | * both... */ | |||
r = bus_verify_polkit_async(bus, &c->polkit_registry, m, prop == PR | r = bus_verify_polkit_async(m, CAP_SYS_ADMIN, | |||
OP_PRETTY_HOSTNAME ? | prop == PROP_PRETTY_HOSTNAME ? | |||
"org.freedesktop.hostname1.set-static-hostname" : | "org.freedesktop.hostname1.set-static-h | |||
"org.freedesktop.hostname1.set-machine-info", int | ostname" : | |||
eractive, error, cb, c); | "org.freedesktop.hostname1.set-machine- | |||
info", interactive, &c->polkit_registry, error); | ||||
if (r < 0) | if (r < 0) | |||
return r; | return r; | |||
if (r == 0) | if (r == 0) | |||
return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | return 1; /* No authorization for now, but the async polkit stuff will call us again when it has it */ | |||
if (isempty(name)) { | if (isempty(name)) { | |||
free(c->data[prop]); | free(c->data[prop]); | |||
c->data[prop] = NULL; | c->data[prop] = NULL; | |||
} else { | } else { | |||
char *h; | char *h; | |||
/* The icon name might ultimately be used as file | /* The icon name might ultimately be used as file | |||
* name, so better be safe than sorry */ | * name, so better be safe than sorry */ | |||
if (prop == PROP_ICON_NAME && !filename_is_safe(name)) | if (prop == PROP_ICON_NAME && !filename_is_safe(name)) | |||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI D_ARGS, "Invalid icon name '%s'", name); | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI D_ARGS, "Invalid icon name '%s'", name); | |||
if (prop == PROP_PRETTY_HOSTNAME && | if (prop == PROP_PRETTY_HOSTNAME && string_has_cc(name, NUL | |||
(string_has_cc(name) || chars_intersect(name, "\t"))) | L)) | |||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI D_ARGS, "Invalid pretty host name '%s'", name); | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI D_ARGS, "Invalid pretty host name '%s'", name); | |||
if (prop == PROP_CHASSIS && !valid_chassis(name)) | if (prop == PROP_CHASSIS && !valid_chassis(name)) | |||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI D_ARGS, "Invalid chassis '%s'", name); | return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI D_ARGS, "Invalid chassis '%s'", name); | |||
if (prop == PROP_DEPLOYMENT && !valid_deployment(name)) | ||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI | ||||
D_ARGS, "Invalid deployment '%s'", name); | ||||
if (prop == PROP_LOCATION && string_has_cc(name, NULL)) | ||||
return sd_bus_error_setf(error, SD_BUS_ERROR_INVALI | ||||
D_ARGS, "Invalid location '%s'", name); | ||||
h = strdup(name); | h = strdup(name); | |||
if (!h) | if (!h) | |||
return -ENOMEM; | return -ENOMEM; | |||
free(c->data[prop]); | free(c->data[prop]); | |||
c->data[prop] = h; | c->data[prop] = h; | |||
} | } | |||
r = context_write_data_machine_info(c); | r = context_write_data_machine_info(c); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to write machine info: %s", strerror(-r)) ; | log_error("Failed to write machine info: %s", strerror(-r)) ; | |||
return sd_bus_error_set_errnof(error, r, "Failed to write m achine info: %s", strerror(-r)); | return sd_bus_error_set_errnof(error, r, "Failed to write m achine info: %s", strerror(-r)); | |||
} | } | |||
log_info("Changed %s to '%s'", | log_info("Changed %s to '%s'", | |||
prop == PROP_PRETTY_HOSTNAME ? "pretty host name" : | prop == PROP_PRETTY_HOSTNAME ? "pretty host name" : | |||
prop == PROP_DEPLOYMENT ? "deployment" : | ||||
prop == PROP_LOCATION ? "location" : | ||||
prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->d ata[prop])); | prop == PROP_CHASSIS ? "chassis" : "icon name", strna(c->d ata[prop])); | |||
sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", " org.freedesktop.hostname1", | sd_bus_emit_properties_changed(bus, "/org/freedesktop/hostname1", " org.freedesktop.hostname1", | |||
prop == PROP_PRETTY_HOSTNAME ? "Pret tyHostname" : | prop == PROP_PRETTY_HOSTNAME ? "Pret tyHostname" : | |||
prop == PROP_CHASSIS ? "Chassis" : " | prop == PROP_DEPLOYMENT ? "Deploymen | |||
IconName", NULL); | t" : | |||
prop == PROP_LOCATION ? "Location" : | ||||
prop == PROP_CHASSIS ? "Chassis" : " | ||||
IconName" , NULL); | ||||
return sd_bus_reply_method_return(m, NULL); | return sd_bus_reply_method_return(m, NULL); | |||
} | } | |||
static int method_set_pretty_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) { | static int method_set_pretty_hostname(sd_bus *bus, sd_bus_message *m, void *userdata, sd_bus_error *error) { | |||
return set_machine_info(userdata, bus, m, PROP_PRETTY_HOSTNAME, met hod_set_pretty_hostname, error); | return set_machine_info(userdata, bus, m, PROP_PRETTY_HOSTNAME, met hod_set_pretty_hostname, error); | |||
} | } | |||
static int method_set_icon_name(sd_bus *bus, sd_bus_message *m, void *userd ata, sd_bus_error *error) { | static int method_set_icon_name(sd_bus *bus, sd_bus_message *m, void *userd ata, sd_bus_error *error) { | |||
return set_machine_info(userdata, bus, m, PROP_ICON_NAME, method_se t_icon_name, error); | return set_machine_info(userdata, bus, m, PROP_ICON_NAME, method_se t_icon_name, error); | |||
} | } | |||
static int method_set_chassis(sd_bus *bus, sd_bus_message *m, void *userdat a, sd_bus_error *error) { | static int method_set_chassis(sd_bus *bus, sd_bus_message *m, void *userdat a, sd_bus_error *error) { | |||
return set_machine_info(userdata, bus, m, PROP_CHASSIS, method_set_ chassis, error); | 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 *user | ||||
data, sd_bus_error *error) { | ||||
return set_machine_info(userdata, bus, m, PROP_DEPLOYMENT, method_s | ||||
et_deployment, error); | ||||
} | ||||
static int method_set_location(sd_bus *bus, sd_bus_message *m, void *userda | ||||
ta, sd_bus_error *error) { | ||||
return set_machine_info(userdata, bus, m, PROP_LOCATION, method_set | ||||
_location, error); | ||||
} | ||||
static const sd_bus_vtable hostname_vtable[] = { | static const sd_bus_vtable hostname_vtable[] = { | |||
SD_BUS_VTABLE_START(0), | SD_BUS_VTABLE_START(0), | |||
SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + si zeof(char*) * PROP_HOSTNAME, 0), | SD_BUS_PROPERTY("Hostname", "s", NULL, offsetof(Context, data) + si zeof(char*) * PROP_HOSTNAME, 0), | |||
SD_BUS_PROPERTY("StaticHostname", "s", NULL, offsetof(Context, data ) + sizeof(char*) * PROP_STATIC_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHAN GE), | SD_BUS_PROPERTY("StaticHostname", "s", NULL, offsetof(Context, data ) + sizeof(char*) * PROP_STATIC_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHAN GE), | |||
SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data ) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHAN GE), | SD_BUS_PROPERTY("PrettyHostname", "s", NULL, offsetof(Context, data ) + sizeof(char*) * PROP_PRETTY_HOSTNAME, SD_BUS_VTABLE_PROPERTY_EMITS_CHAN GE), | |||
SD_BUS_PROPERTY("IconName", "s", property_get_icon_name, 0, 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_VTA BLE_PROPERTY_EMITS_CHANGE), | SD_BUS_PROPERTY("Chassis", "s", property_get_chassis, 0, SD_BUS_VTA BLE_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) + si | ||||
zeof(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("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("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("KernelVersion", "s", NULL, offsetof(Context, data) + sizeof(char*) * PROP_KERNEL_VERSION, SD_BUS_VTABLE_PROPERTY_CONST), | |||
SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", NULL, offsetof(Co ntext, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_ CONST), | SD_BUS_PROPERTY("OperatingSystemPrettyName", "s", NULL, offsetof(Co ntext, data) + sizeof(char*) * PROP_OS_PRETTY_NAME, SD_BUS_VTABLE_PROPERTY_ CONST), | |||
SD_BUS_PROPERTY("OperatingSystemCPEName", "s", NULL, offsetof(Conte xt, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST) , | SD_BUS_PROPERTY("OperatingSystemCPEName", "s", NULL, offsetof(Conte xt, data) + sizeof(char*) * PROP_OS_CPE_NAME, SD_BUS_VTABLE_PROPERTY_CONST) , | |||
SD_BUS_METHOD("SetHostname", "sb", NULL, method_set_hostname, SD_BU S_VTABLE_UNPRIVILEGED), | SD_BUS_METHOD("SetHostname", "sb", NULL, method_set_hostname, SD_BU S_VTABLE_UNPRIVILEGED), | |||
SD_BUS_METHOD("SetStaticHostname", "sb", NULL, method_set_static_ho stname, SD_BUS_VTABLE_UNPRIVILEGED), | SD_BUS_METHOD("SetStaticHostname", "sb", NULL, method_set_static_ho stname, SD_BUS_VTABLE_UNPRIVILEGED), | |||
SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_ho stname, SD_BUS_VTABLE_UNPRIVILEGED), | SD_BUS_METHOD("SetPrettyHostname", "sb", NULL, method_set_pretty_ho stname, SD_BUS_VTABLE_UNPRIVILEGED), | |||
SD_BUS_METHOD("SetIconName", "sb", NULL, method_set_icon_name, SD_B US_VTABLE_UNPRIVILEGED), | SD_BUS_METHOD("SetIconName", "sb", NULL, method_set_icon_name, SD_B US_VTABLE_UNPRIVILEGED), | |||
SD_BUS_METHOD("SetChassis", "sb", NULL, method_set_chassis, 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, S | ||||
D_BUS_VTABLE_UNPRIVILEGED), | ||||
SD_BUS_METHOD("SetLocation", "sb", NULL, method_set_location, SD_BU | ||||
S_VTABLE_UNPRIVILEGED), | ||||
SD_BUS_VTABLE_END, | SD_BUS_VTABLE_END, | |||
}; | }; | |||
static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { | static int connect_bus(Context *c, sd_event *event, sd_bus **_bus) { | |||
_cleanup_bus_unref_ sd_bus *bus = NULL; | _cleanup_bus_close_unref_ sd_bus *bus = NULL; | |||
int r; | int r; | |||
assert(c); | assert(c); | |||
assert(event); | assert(event); | |||
assert(_bus); | assert(_bus); | |||
r = sd_bus_default_system(&bus); | r = sd_bus_default_system(&bus); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to get system bus connection: %s", strerr or(-r)); | log_error("Failed to get system bus connection: %s", strerr or(-r)); | |||
return r; | return r; | |||
skipping to change at line 656 | skipping to change at line 677 | |||
} | } | |||
*_bus = bus; | *_bus = bus; | |||
bus = NULL; | bus = NULL; | |||
return 0; | return 0; | |||
} | } | |||
int main(int argc, char *argv[]) { | int main(int argc, char *argv[]) { | |||
Context context = {}; | Context context = {}; | |||
_cleanup_event_unref_ sd_event *event = NULL; | _cleanup_event_unref_ sd_event *event = NULL; | |||
_cleanup_bus_unref_ sd_bus *bus = NULL; | _cleanup_bus_close_unref_ sd_bus *bus = NULL; | |||
int r; | int r; | |||
log_set_target(LOG_TARGET_AUTO); | log_set_target(LOG_TARGET_AUTO); | |||
log_parse_environment(); | log_parse_environment(); | |||
log_open(); | log_open(); | |||
umask(0022); | umask(0022); | |||
label_init("/etc"); | label_init("/etc"); | |||
if (argc != 1) { | if (argc != 1) { | |||
log_error("This program takes no arguments."); | log_error("This program takes no arguments."); | |||
r = -EINVAL; | r = -EINVAL; | |||
goto finish; | goto finish; | |||
} | } | |||
if (!check_nss()) | ||||
log_warning("Warning: nss-myhostname is not installed. Chan | ||||
ging the local hostname might make it unresolveable. Please install nss-myh | ||||
ostname!"); | ||||
if (argc != 1) { | if (argc != 1) { | |||
log_error("This program takes no arguments."); | log_error("This program takes no arguments."); | |||
r = -EINVAL; | r = -EINVAL; | |||
goto finish; | goto finish; | |||
} | } | |||
r = sd_event_default(&event); | r = sd_event_default(&event); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to allocate event loop: %s", strerror(-r) ); | log_error("Failed to allocate event loop: %s", strerror(-r) ); | |||
goto finish; | goto finish; | |||
skipping to change at line 708 | skipping to change at line 725 | |||
goto finish; | goto finish; | |||
} | } | |||
r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1 ", DEFAULT_EXIT_USEC, NULL, NULL); | r = bus_event_loop_with_idle(event, bus, "org.freedesktop.hostname1 ", DEFAULT_EXIT_USEC, NULL, NULL); | |||
if (r < 0) { | if (r < 0) { | |||
log_error("Failed to run event loop: %s", strerror(-r)); | log_error("Failed to run event loop: %s", strerror(-r)); | |||
goto finish; | goto finish; | |||
} | } | |||
finish: | finish: | |||
context_free(&context, bus); | context_free(&context); | |||
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; | |||
} | } | |||
End of changes. 31 change blocks. | ||||
45 lines changed or deleted | 71 lines changed or added | |||
This html diff was produced by rfcdiff 1.41. The latest version is available from http://tools.ietf.org/tools/rfcdiff/ |