Skip to content

Commit 55d4bf4

Browse files
yuwatabluca
authored andcommitted
nspawn: ignore failure in creating /dev/net/tun when --private-network is unspecified
Follow-up for efedb6b. Closes #35116. (cherry picked from commit 985ea98) Really rewritten from scratch. (cherry picked from commit 04ee5e2) (cherry picked from commit 45b39f9) (cherry picked from commit c25b73f) (cherry picked from commit 2ba27c3)
1 parent a186186 commit 55d4bf4

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/nspawn/nspawn.c

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2240,6 +2240,7 @@ static int copy_devnodes(const char *dest) {
22402240
NULSTR_FOREACH(d, devnodes) {
22412241
_cleanup_free_ char *from = NULL, *to = NULL;
22422242
struct stat st;
2243+
bool ignore_mknod_failure = streq(d, "net/tun");
22432244

22442245
from = path_join("/dev/", d);
22452246
if (!from)
@@ -2264,16 +2265,31 @@ static int copy_devnodes(const char *dest) {
22642265
/* Explicitly warn the user when /dev is already populated. */
22652266
if (errno == EEXIST)
22662267
log_notice("%s/dev is pre-mounted and pre-populated. If a pre-mounted /dev is provided it needs to be an unpopulated file system.", dest);
2267-
if (errno != EPERM || arg_uid_shift != 0)
2268+
if (errno != EPERM || arg_uid_shift != 0) {
2269+
if (ignore_mknod_failure) {
2270+
log_debug_errno(r, "mknod(%s) failed, ignoring: %m", to);
2271+
return 0;
2272+
}
22682273
return log_error_errno(errno, "mknod(%s) failed: %m", to);
2274+
}
22692275

22702276
/* Some systems abusively restrict mknod but allow bind mounts. */
22712277
r = touch(to);
2272-
if (r < 0)
2278+
if (r < 0) {
2279+
if (ignore_mknod_failure) {
2280+
log_debug_errno(r, "touch (%s) failed, ignoring: %m", to);
2281+
return 0;
2282+
}
22732283
return log_error_errno(r, "touch (%s) failed: %m", to);
2284+
}
22742285
r = mount_nofollow_verbose(LOG_DEBUG, from, to, NULL, MS_BIND, NULL);
2275-
if (r < 0)
2286+
if (r < 0) {
2287+
if (ignore_mknod_failure) {
2288+
log_debug_errno(r, "Both mknod and bind mount (%s) failed, ignoring: %m", to);
2289+
return 0;
2290+
}
22762291
return log_error_errno(r, "Both mknod and bind mount (%s) failed: %m", to);
2292+
}
22772293
} else {
22782294
r = userns_lchown(to, 0, 0);
22792295
if (r < 0)

0 commit comments

Comments
 (0)