nspawn: add new common make_run_host() helper

This new helper creates the /run/host/ top-level dir inside the
container.
This commit is contained in:
Lennart Poettering
2024-01-05 16:40:45 +01:00
parent 92a39246ad
commit 32fa24582c
3 changed files with 19 additions and 6 deletions

View File

@@ -388,9 +388,9 @@ int bind_user_setup(
if (!c || c->n_data == 0)
return 0;
r = userns_mkdir(root, "/run/host", 0755, 0, 0);
r = make_run_host(root);
if (r < 0)
return log_error_errno(r, "Failed to create /run/host: %m");
return r;
r = userns_mkdir(root, "/run/host/home", 0755, 0, 0);
if (r < 0)

View File

@@ -2364,6 +2364,18 @@ static int setup_keyring(void) {
return 0;
}
int make_run_host(const char *root) {
int r;
assert(root);
r = userns_mkdir(root, "/run/host", 0755, 0, 0);
if (r < 0)
return log_error_errno(r, "Failed to create /run/host/: %m");
return 0;
}
static int setup_credentials(const char *root) {
const char *q;
int r;
@@ -2371,9 +2383,9 @@ static int setup_credentials(const char *root) {
if (arg_credentials.n_credentials == 0)
return 0;
r = userns_mkdir(root, "/run/host", 0755, 0, 0);
r = make_run_host(root);
if (r < 0)
return log_error_errno(r, "Failed to create /run/host: %m");
return r;
r = userns_mkdir(root, "/run/host/credentials", 0700, 0, 0);
if (r < 0)
@@ -2713,9 +2725,9 @@ static int mount_tunnel_dig(const char *root) {
p = strjoina("/run/systemd/nspawn/propagate/", arg_machine);
(void) mkdir_p(p, 0600);
r = userns_mkdir(root, "/run/host", 0755, 0, 0);
r = make_run_host(root);
if (r < 0)
return log_error_errno(r, "Failed to create /run/host: %m");
return r;
r = userns_mkdir(root, NSPAWN_MOUNT_TUNNEL, 0600, 0, 0);
if (r < 0)

View File

@@ -5,3 +5,4 @@
int userns_lchown(const char *p, uid_t uid, gid_t gid);
int userns_mkdir(const char *root, const char *path, mode_t mode, uid_t uid, gid_t gid);
int make_run_host(const char *root);