From dd86e6c45c158e7cc67681fdef05a0325dc23f99 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 5 Sep 2024 13:54:31 +0900 Subject: [PATCH 1/4] mount-util: wrap long line --- src/shared/mount-util.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index 3992afe8c7..d98df3809d 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -1445,7 +1445,14 @@ int remount_idmap_fd( return 0; } -int remount_idmap(char **p, uid_t uid_shift, uid_t uid_range, uid_t source_owner, uid_t dest_owner,RemountIdmapping idmapping) { +int remount_idmap( + char **p, + uid_t uid_shift, + uid_t uid_range, + uid_t source_owner, + uid_t dest_owner, + RemountIdmapping idmapping) { + _cleanup_close_ int userns_fd = -EBADF; userns_fd = make_userns(uid_shift, uid_range, source_owner, dest_owner, idmapping); @@ -1500,6 +1507,7 @@ static int get_sub_mounts( const char *prefix, SubMount **ret_mounts, size_t *ret_n_mounts) { + _cleanup_(mnt_free_tablep) struct libmnt_table *table = NULL; _cleanup_(mnt_free_iterp) struct libmnt_iter *iter = NULL; SubMount *mounts = NULL; From fe7a126ce8784f6c44c1455e65af2e4cadb8d16f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 5 Sep 2024 19:37:52 +0900 Subject: [PATCH 2/4] base-filesystem: use FOREACH_ELEMENT() --- src/shared/base-filesystem.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/shared/base-filesystem.c b/src/shared/base-filesystem.c index 0d5075e1e6..389c77eee0 100644 --- a/src/shared/base-filesystem.c +++ b/src/shared/base-filesystem.c @@ -136,23 +136,23 @@ int base_filesystem_create_fd(int fd, const char *root, uid_t uid, gid_t gid) { /* The "root" parameter is decoration only – it's only used as part of log messages */ - for (size_t i = 0; i < ELEMENTSOF(table); i++) { - if (faccessat(fd, table[i].dir, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) + FOREACH_ELEMENT(i, table) { + if (faccessat(fd, i->dir, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) continue; - if (table[i].target) { /* Create as symlink? */ + if (i->target) { /* Create as symlink? */ const char *target = NULL; /* check if one of the targets exists */ - NULSTR_FOREACH(s, table[i].target) { + NULSTR_FOREACH(s, i->target) { if (faccessat(fd, s, F_OK, AT_SYMLINK_NOFOLLOW) < 0) continue; /* check if a specific file exists at the target path */ - if (table[i].exists) { + if (i->exists) { _cleanup_free_ char *p = NULL; - p = path_join(s, table[i].exists); + p = path_join(s, i->exists); if (!p) return log_oom(); @@ -167,16 +167,16 @@ int base_filesystem_create_fd(int fd, const char *root, uid_t uid, gid_t gid) { if (!target) continue; - r = RET_NERRNO(symlinkat(target, fd, table[i].dir)); + r = RET_NERRNO(symlinkat(target, fd, i->dir)); } else { /* Create as directory. */ WITH_UMASK(0000) - r = RET_NERRNO(mkdirat(fd, table[i].dir, table[i].mode)); + r = RET_NERRNO(mkdirat(fd, i->dir, i->mode)); } if (r < 0) { - bool ignore = IN_SET(r, -EEXIST, -EROFS) || table[i].ignore_failure; + bool ignore = IN_SET(r, -EEXIST, -EROFS) || i->ignore_failure; log_full_errno(ignore ? LOG_DEBUG : LOG_ERR, r, - "Failed to create %s/%s: %m", root, table[i].dir); + "Failed to create %s/%s: %m", root, i->dir); if (ignore) continue; @@ -184,8 +184,8 @@ int base_filesystem_create_fd(int fd, const char *root, uid_t uid, gid_t gid) { } if (uid_is_valid(uid) || gid_is_valid(gid)) - if (fchownat(fd, table[i].dir, uid, gid, AT_SYMLINK_NOFOLLOW) < 0) - return log_error_errno(errno, "Failed to chown %s/%s: %m", root, table[i].dir); + if (fchownat(fd, i->dir, uid, gid, AT_SYMLINK_NOFOLLOW) < 0) + return log_error_errno(errno, "Failed to chown %s/%s: %m", root, i->dir); } return 0; From 0e40a263415d642c9d958619ccd05ed1fc18da56 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 6 Sep 2024 13:10:04 +0900 Subject: [PATCH 3/4] nspawn: fix indentation --- src/nspawn/nspawn.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 92077866a2..86d03399e9 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -4067,7 +4067,7 @@ static int outer_child( return r; if (arg_read_only && arg_volatile_mode == VOLATILE_NO && - !has_custom_root_mount(arg_custom_mounts, arg_n_custom_mounts)) { + !has_custom_root_mount(arg_custom_mounts, arg_n_custom_mounts)) { r = bind_remount_recursive(directory, MS_RDONLY, MS_RDONLY, NULL); if (r < 0) return log_error_errno(r, "Failed to make tree read-only: %m"); From 31a9aedf030bf39dc1d96eb9a643f94a1ab11cd0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Fri, 6 Sep 2024 12:39:58 +0900 Subject: [PATCH 4/4] test: fix copy-and-paste error in comment --- test/units/TEST-13-NSPAWN.nspawn.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/units/TEST-13-NSPAWN.nspawn.sh b/test/units/TEST-13-NSPAWN.nspawn.sh index 7c21825d63..339ad6b3c4 100755 --- a/test/units/TEST-13-NSPAWN.nspawn.sh +++ b/test/units/TEST-13-NSPAWN.nspawn.sh @@ -133,7 +133,7 @@ testcase_sanity() { bash -xec 'test -e /usr/has-usr; mountpoint /var; touch /read-only && exit 1; touch /var/nope' test ! -e "$root/read-only" test ! -e "$root/var/nope" - # volatile=state: tmpfs overlay is mounted over rootfs + # volatile=overlay: tmpfs overlay is mounted over rootfs systemd-nspawn --directory="$root" \ --volatile=overlay \ bash -xec 'test -e /usr/has-usr; touch /nope; touch /var/also-nope; touch /usr/nope-too'