diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-05-07 18:37:32 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-05-17 20:46:45 +0200 |
commit | 3a9530e5f19565a9cadb7f20bd987c61e0e7c377 (patch) | |
tree | f0ecc881eb1ed00d3a57ec7ce472c356e514c6cc /src/nspawn/nspawn-settings.c | |
parent | conf-parser: shorten config_parse_string() by using free_and_strdup() and emp... (diff) | |
download | systemd-3a9530e5f19565a9cadb7f20bd987c61e0e7c377.tar.xz systemd-3a9530e5f19565a9cadb7f20bd987c61e0e7c377.zip |
nspawn: make the hostname of the container explicitly configurable with a new --hostname= switch
Previously, the container's hostname was exclusively initialized from
the machine name configured with --machine=, i.e. the internal name and
the external name used for and by the container was synchronized. This
adds a new option --hostname= that optionally allows the internal name
to deviate from the external name.
This new option is mainly useful to ultimately implement the OCI runtime
spec directly in nspawn, but it might be useful on its own for some
other usecases too.
Diffstat (limited to 'src/nspawn/nspawn-settings.c')
-rw-r--r-- | src/nspawn/nspawn-settings.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/nspawn/nspawn-settings.c b/src/nspawn/nspawn-settings.c index 19bf1d4b94..3757380e28 100644 --- a/src/nspawn/nspawn-settings.c +++ b/src/nspawn/nspawn-settings.c @@ -8,6 +8,7 @@ #include "alloc-util.h" #include "cap-list.h" #include "conf-parser.h" +#include "hostname-util.h" #include "nspawn-network.h" #include "nspawn-settings.h" #include "parse-util.h" @@ -82,6 +83,7 @@ Settings* settings_free(Settings *s) { strv_free(s->syscall_whitelist); strv_free(s->syscall_blacklist); rlimit_free_all(s->rlimit); + free(s->hostname); strv_free(s->network_interfaces); strv_free(s->network_macvlan); @@ -603,3 +605,31 @@ int config_parse_syscall_filter( return 0; } + +int config_parse_hostname( + const char *unit, + const char *filename, + unsigned line, + const char *section, + unsigned section_line, + const char *lvalue, + int ltype, + const char *rvalue, + void *data, + void *userdata) { + + char **s = data; + + assert(rvalue); + assert(s); + + if (!hostname_is_valid(rvalue, false)) { + log_syntax(unit, LOG_ERR, filename, line, 0, "Invalid hostname, ignoring: %s", rvalue); + return 0; + } + + if (free_and_strdup(s, empty_to_null(rvalue)) < 0) + return log_oom(); + + return 0; +} |