X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fnspawn%2Fnspawn.c;h=7e96efd425425f4f2d196356a38201774ff5b06e;hb=fddbb89c46ea5d39e52e361b390ea34a06cbb67c;hp=34436b82a2879b3778bce44dcb27f59298740a11;hpb=e8c8ddccfc63574069c30b7e75f0ccfd5b03eab9;p=elogind.git diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 34436b82a..7e96efd42 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -758,7 +758,7 @@ static int mount_binds(const char *dest, char **l, bool ro) { * and char devices. */ if (S_ISDIR(source_st.st_mode)) { r = mkdir_label(where, 0755); - if (r < 0) { + if (r < 0 && errno != EEXIST) { log_error("Failed to create mount point %s: %s", where, strerror(-r)); return r; @@ -1101,7 +1101,8 @@ static int copy_devnodes(const char *dest) { "full\0" "random\0" "urandom\0" - "tty\0"; + "tty\0" + "net/tun\0"; const char *d; int r = 0; @@ -1132,10 +1133,17 @@ static int copy_devnodes(const char *dest) { log_error("%s is not a char or block device, cannot copy", from); return -EIO; - } else if (mknod(to, st.st_mode, st.st_rdev) < 0) { + } else { + r = mkdir_parents(to, 0775); + if (r < 0) { + log_error("Failed to create parent directory of %s: %s", to, strerror(-r)); + return -r; + } - log_error("mknod(%s) failed: %m", dest); - return -errno; + if (mknod(to, st.st_mode, st.st_rdev) < 0) { + log_error("mknod(%s) failed: %m", dest); + return -errno; + } } } @@ -1281,7 +1289,7 @@ static int setup_hostname(void) { if (arg_share_system) return 0; - if (sethostname(arg_machine, strlen(arg_machine)) < 0) + if (sethostname_idempotent(arg_machine) < 0) return -errno; return 0; @@ -1537,7 +1545,7 @@ static int register_machine(pid_t pid, int local_ifindex) { return r; } - r = sd_bus_message_append(m, "(sv)", "DeviceAllow", "a(ss)", 10, + r = sd_bus_message_append(m, "(sv)", "DeviceAllow", "a(ss)", 11, /* Allow the container to * access and create the API * device nodes, so that @@ -1550,6 +1558,7 @@ static int register_machine(pid_t pid, int local_ifindex) { "/dev/random", "rwm", "/dev/urandom", "rwm", "/dev/tty", "rwm", + "/dev/net/tun", "rwm", /* Allow the container * access to ptys. However, * do not permit the @@ -2922,33 +2931,30 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) { } switch (status.si_code) { + case CLD_EXITED: r = status.si_status; if (r == 0) { if (!arg_quiet) - log_debug("Container %s exited successfully.", - arg_machine); + log_debug("Container %s exited successfully.", arg_machine); *container = CONTAINER_TERMINATED; - } else { - log_error("Container %s failed with error code %i.", - arg_machine, status.si_status); - } + } else + log_error("Container %s failed with error code %i.", arg_machine, status.si_status); + break; case CLD_KILLED: if (status.si_status == SIGINT) { if (!arg_quiet) - log_info("Container %s has been shut down.", - arg_machine); + log_info("Container %s has been shut down.", arg_machine); *container = CONTAINER_TERMINATED; r = 0; break; } else if (status.si_status == SIGHUP) { if (!arg_quiet) - log_info("Container %s is being rebooted.", - arg_machine); + log_info("Container %s is being rebooted.", arg_machine); *container = CONTAINER_REBOOTED; r = 0; @@ -2957,15 +2963,13 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) { /* CLD_KILLED fallthrough */ case CLD_DUMPED: - log_error("Container %s terminated by signal %s.", - arg_machine, signal_to_string(status.si_status)); - r = -1; + log_error("Container %s terminated by signal %s.", arg_machine, signal_to_string(status.si_status)); + r = -EIO; break; default: - log_error("Container %s failed due to unknown reason.", - arg_machine); - r = -1; + log_error("Container %s failed due to unknown reason.", arg_machine); + r = -EIO; break; }