diff options
author | Martin Pitt <martin.pitt@ubuntu.com> | 2016-11-22 08:36:20 +0100 |
---|---|---|
committer | Martin Pitt <martin.pitt@ubuntu.com> | 2016-11-23 17:05:10 +0100 |
commit | 7901cea1997c3881f3da93ecc5ad03e6de1e87b7 (patch) | |
tree | 43523f187f6f965c7a6dbf97617092cb6fe928d8 /src/network | |
parent | 2c99aba7260a402e8f81d85aab12ce25d3d8786a (diff) |
networkd: set DHCP-acquired timezone and hostname after connecting to D-Bus
If setting the received timezone or transient hostname fails because D-Bus is
not (yet) up, store the data in the Manager object and try again after
connecting to D-Bus.
Diffstat (limited to 'src/network')
-rw-r--r-- | src/network/networkd-manager.c | 19 | ||||
-rw-r--r-- | src/network/networkd-manager.h | 2 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/network/networkd-manager.c b/src/network/networkd-manager.c index a32d5648b6..4e3f9e35c6 100644 --- a/src/network/networkd-manager.c +++ b/src/network/networkd-manager.c @@ -192,6 +192,18 @@ int manager_connect_bus(Manager *m) { if (r < 0) return log_error_errno(r, "Failed to attach bus to event loop: %m"); + /* Did we get a timezone or transient hostname from DHCP while D-Bus wasn't up yet? */ + if (m->dynamic_hostname) { + r = manager_set_hostname(m, m->dynamic_hostname); + if (r < 0) + return r; + } + if (m->dynamic_timezone) { + r = manager_set_timezone(m, m->dynamic_timezone); + if (r < 0) + return r; + } + return 0; } @@ -1119,6 +1131,9 @@ void manager_free(Manager *m) { sd_bus_slot_unref(m->prepare_for_sleep_slot); sd_event_source_unref(m->bus_retry_event_source); + free(m->dynamic_timezone); + free(m->dynamic_hostname); + free(m); } @@ -1384,6 +1399,8 @@ int manager_set_hostname(Manager *m, const char *hostname) { int r; log_debug("Setting transient hostname: '%s'", strna(hostname)); + if (free_and_strdup(&m->dynamic_hostname, hostname) < 0) + return log_oom(); if (!m->bus) { /* TODO: replace by assert when we can rely on kdbus */ @@ -1431,6 +1448,8 @@ int manager_set_timezone(Manager *m, const char *tz) { assert(tz); log_debug("Setting system timezone: '%s'", tz); + if (free_and_strdup(&m->dynamic_timezone, tz) < 0) + return log_oom(); if (!m->bus) { log_info("Not connected to system bus, ignoring timezone."); diff --git a/src/network/networkd-manager.h b/src/network/networkd-manager.h index 13363c70fa..c81f5057b7 100644 --- a/src/network/networkd-manager.h +++ b/src/network/networkd-manager.h @@ -63,6 +63,8 @@ struct Manager { usec_t network_dirs_ts_usec; DUID duid; + char* dynamic_hostname; + char* dynamic_timezone; }; static inline const DUID* link_duid(const Link *link) { |