1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-27 01:55:32 +03:00

nspawn: bind mount /etc/resolv.conf from the host by default

This commit is contained in:
Lennart Poettering 2012-04-25 15:08:00 +02:00
parent b55d0651c0
commit 2547bb414c

View File

@ -263,6 +263,28 @@ static int setup_timezone(const char *dest) {
return 0;
}
static int setup_resolv_conf(const char *dest) {
char *where;
assert(dest);
if (arg_private_network)
return 0;
/* Fix resolv.conf, if possible */
if (asprintf(&where, "%s/etc/resolv.conf", dest) < 0) {
log_error("Out of memory");
return -ENOMEM;
}
if (mount("/etc/resolv.conf", where, "bind", MS_BIND, NULL) >= 0)
mount("/etc/resolv.conf", where, "bind", MS_BIND|MS_REMOUNT|MS_RDONLY, NULL);
free(where);
return 0;
}
static int copy_devnodes(const char *dest) {
static const char devnodes[] =
@ -966,6 +988,9 @@ int main(int argc, char *argv[]) {
if (setup_timezone(arg_directory) < 0)
goto child_fail;
if (setup_resolv_conf(arg_directory) < 0)
goto child_fail;
if (chdir(arg_directory) < 0) {
log_error("chdir(%s) failed: %m", arg_directory);
goto child_fail;