mirror of
https://github.com/systemd/systemd.git
synced 2025-01-10 05:18:17 +03:00
Merge pull request #34280 from yuwata/cleanups
tree-wide: trivial cleanups
This commit is contained in:
commit
c81c2ed1eb
@ -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");
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user