diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-11-21 23:15:41 +0100 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2016-11-23 16:32:06 +0100 |
commit | 59eb33e0fec9b1502a9089561dcfda3f16a1816e (patch) | |
tree | b861cc79d6a5e0eebb1e521a8cfbd34034eaaaab | |
parent | 3d4cf7de48a74726694abbaa09f9804b845ff3ba (diff) |
networkd: move setting hostname and timezone to Manager
Hostname and time zone are global settings, not link specific. Move these
methods from Link into Manager.
-rw-r--r-- | src/network/networkd-dhcp4.c | 6 | ||||
-rw-r--r-- | src/network/networkd-link.c | 103 | ||||
-rw-r--r-- | src/network/networkd-link.h | 2 | ||||
-rw-r--r-- | src/network/networkd-manager.c | 89 | ||||
-rw-r--r-- | src/network/networkd-manager.h | 3 |
5 files changed, 95 insertions, 108 deletions
diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index ca23c1c2a7..c5c5b95c8f 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -255,7 +255,7 @@ static int dhcp_lease_lost(Link *link) { if (hostname) { /* If a hostname was set due to the lease, then unset it now. */ - r = link_set_hostname(link, NULL); + r = manager_set_hostname(link->manager, NULL); if (r < 0) log_link_warning_errno(link, r, "Failed to reset transient hostname: %m"); } @@ -439,7 +439,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) { (void) sd_dhcp_lease_get_hostname(lease, &hostname); if (hostname) { - r = link_set_hostname(link, hostname); + r = manager_set_hostname(link->manager, hostname); if (r < 0) log_link_error_errno(link, r, "Failed to set transient hostname to '%s': %m", hostname); } @@ -451,7 +451,7 @@ static int dhcp_lease_acquired(sd_dhcp_client *client, Link *link) { (void) sd_dhcp_lease_get_timezone(link->dhcp_lease, &tz); if (tz) { - r = link_set_timezone(link, tz); + r = manager_set_timezone(link->manager, tz); if (r < 0) log_link_error_errno(link, r, "Failed to set timezone to '%s': %m", tz); } diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index b38eec1ba7..cb7df633b7 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1175,109 +1175,6 @@ static int link_set_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userd return 0; } -static int set_hostname_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { - _cleanup_link_unref_ Link *link = userdata; - const sd_bus_error *e; - - assert(m); - assert(link); - - if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) - return 1; - - e = sd_bus_message_get_error(m); - if (e) - log_link_warning_errno(link, sd_bus_error_get_errno(e), "Could not set hostname: %s", e->message); - - return 1; -} - -int link_set_hostname(Link *link, const char *hostname) { - int r; - - assert(link); - assert(link->manager); - - log_link_debug(link, "Setting transient hostname: '%s'", strna(hostname)); - - if (!link->manager->bus) { - /* TODO: replace by assert when we can rely on kdbus */ - log_link_info(link, "Not connected to system bus, ignoring transient hostname."); - return 0; - } - - r = sd_bus_call_method_async( - link->manager->bus, - NULL, - "org.freedesktop.hostname1", - "/org/freedesktop/hostname1", - "org.freedesktop.hostname1", - "SetHostname", - set_hostname_handler, - link, - "sb", - hostname, - false); - - if (r < 0) - return log_link_error_errno(link, r, "Could not set transient hostname: %m"); - - link_ref(link); - - return 0; -} - -static int set_timezone_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { - _cleanup_link_unref_ Link *link = userdata; - const sd_bus_error *e; - - assert(m); - assert(link); - - if (IN_SET(link->state, LINK_STATE_FAILED, LINK_STATE_LINGER)) - return 1; - - e = sd_bus_message_get_error(m); - if (e) - log_link_warning_errno(link, sd_bus_error_get_errno(e), "Could not set timezone: %s", e->message); - - return 1; -} - -int link_set_timezone(Link *link, const char *tz) { - int r; - - assert(link); - assert(link->manager); - assert(tz); - - log_link_debug(link, "Setting system timezone: '%s'", tz); - - if (!link->manager->bus) { - log_link_info(link, "Not connected to system bus, ignoring timezone."); - return 0; - } - - r = sd_bus_call_method_async( - link->manager->bus, - NULL, - "org.freedesktop.timedate1", - "/org/freedesktop/timedate1", - "org.freedesktop.timedate1", - "SetTimezone", - set_timezone_handler, - link, - "sb", - tz, - false); - if (r < 0) - return log_link_error_errno(link, r, "Could not set timezone: %m"); - - link_ref(link); - - return 0; -} - static int set_mtu_handler(sd_netlink *rtnl, sd_netlink_message *m, void *userdata) { _cleanup_link_unref_ Link *link = userdata; int r; diff --git a/src/network/networkd-link.h b/src/network/networkd-link.h index 77f72d070e..e6190fbe57 100644 --- a/src/network/networkd-link.h +++ b/src/network/networkd-link.h @@ -159,8 +159,6 @@ bool link_has_carrier(Link *link); int link_ipv6ll_gained(Link *link, const struct in6_addr *address); int link_set_mtu(Link *link, uint32_t mtu); -int link_set_hostname(Link *link, const char *hostname); -int link_set_timezone(Link *link, const char *timezone); int ipv4ll_configure(Link *link); int dhcp4_configure(Link *link); diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index c3d3f48a3f..a32d5648b6 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -1365,3 +1365,92 @@ void manager_dirty(Manager *manager) { /* the serialized state in /run is no longer up-to-date */ manager->dirty = true; } + +static int set_hostname_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { + Manager *manager = userdata; + const sd_bus_error *e; + + assert(m); + assert(manager); + + e = sd_bus_message_get_error(m); + if (e) + log_warning_errno(sd_bus_error_get_errno(e), "Could not set hostname: %s", e->message); + + return 1; +} + +int manager_set_hostname(Manager *m, const char *hostname) { + int r; + + log_debug("Setting transient hostname: '%s'", strna(hostname)); + + if (!m->bus) { + /* TODO: replace by assert when we can rely on kdbus */ + log_info("Not connected to system bus, ignoring transient hostname."); + return 0; + } + + r = sd_bus_call_method_async( + m->bus, + NULL, + "org.freedesktop.hostname1", + "/org/freedesktop/hostname1", + "org.freedesktop.hostname1", + "SetHostname", + set_hostname_handler, + m, + "sb", + hostname, + false); + + if (r < 0) + return log_error_errno(r, "Could not set transient hostname: %m"); + + return 0; +} + +static int set_timezone_handler(sd_bus_message *m, void *userdata, sd_bus_error *ret_error) { + Manager *manager = userdata; + const sd_bus_error *e; + + assert(m); + assert(manager); + + e = sd_bus_message_get_error(m); + if (e) + log_warning_errno(sd_bus_error_get_errno(e), "Could not set timezone: %s", e->message); + + return 1; +} + +int manager_set_timezone(Manager *m, const char *tz) { + int r; + + assert(m); + assert(tz); + + log_debug("Setting system timezone: '%s'", tz); + + if (!m->bus) { + log_info("Not connected to system bus, ignoring timezone."); + return 0; + } + + r = sd_bus_call_method_async( + m->bus, + NULL, + "org.freedesktop.timedate1", + "/org/freedesktop/timedate1", + "org.freedesktop.timedate1", + "SetTimezone", + set_timezone_handler, + m, + "sb", + tz, + false); + if (r < 0) + return log_error_errno(r, "Could not set timezone: %m"); + + return 0; +} diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index a90d9a933f..13363c70fa 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -97,5 +97,8 @@ int manager_address_pool_acquire(Manager *m, int family, unsigned prefixlen, uni Link* manager_find_uplink(Manager *m, Link *exclude); +int manager_set_hostname(Manager *m, const char *hostname); +int manager_set_timezone(Manager *m, const char *timezone); + DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free); #define _cleanup_manager_free_ _cleanup_(manager_freep) |