1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

shared/mount-setup: minor modernization

This commit is contained in:
Mike Yuan 2024-02-22 13:03:09 +08:00
parent 821333263c
commit 72a9f4fa45
No known key found for this signature in database
GPG Key ID: 417471C0A40F58B3
2 changed files with 17 additions and 18 deletions

View File

@ -167,8 +167,11 @@ static int mount_one(const MountPoint *p, bool relabel) {
int r, priority;
assert(p);
assert(p->what);
assert(p->where);
assert(p->type);
priority = (p->mode & MNT_FATAL) ? LOG_ERR : LOG_DEBUG;
priority = FLAGS_SET(p->mode, MNT_FATAL) ? LOG_ERR : LOG_DEBUG;
if (p->condition_fn && !p->condition_fn())
return 0;
@ -180,13 +183,13 @@ static int mount_one(const MountPoint *p, bool relabel) {
r = path_is_mount_point_full(p->where, /* root = */ NULL, AT_SYMLINK_FOLLOW);
if (r < 0 && r != -ENOENT) {
log_full_errno(priority, r, "Failed to determine whether %s is a mount point: %m", p->where);
return (p->mode & MNT_FATAL) ? r : 0;
return FLAGS_SET(p->mode, MNT_FATAL) ? r : 0;
}
if (r > 0)
return 0;
/* Skip securityfs in a container */
if (!(p->mode & MNT_IN_CONTAINER) && detect_container() > 0)
if (!FLAGS_SET(p->mode, MNT_IN_CONTAINER) && detect_container() > 0)
return 0;
/* The access mode here doesn't really matter too much, since
@ -207,39 +210,35 @@ static int mount_one(const MountPoint *p, bool relabel) {
else
r = mount_nofollow_verbose(priority, p->what, p->where, p->type, p->flags, p->options);
if (r < 0)
return (p->mode & MNT_FATAL) ? r : 0;
return FLAGS_SET(p->mode, MNT_FATAL) ? r : 0;
/* Relabel again, since we now mounted something fresh here */
if (relabel)
(void) label_fix(p->where, 0);
if (p->mode & MNT_CHECK_WRITABLE) {
if (FLAGS_SET(p->mode, MNT_CHECK_WRITABLE))
if (access(p->where, W_OK) < 0) {
r = -errno;
(void) umount2(p->where, UMOUNT_NOFOLLOW);
(void) rmdir(p->where);
log_full_errno(priority, r, "Mount point %s not writable after mounting, undoing: %m", p->where);
return (p->mode & MNT_FATAL) ? r : 0;
log_full_errno(priority, r, "Mount point '%s' not writable after mounting, undoing: %m", p->where);
return FLAGS_SET(p->mode, MNT_FATAL) ? r : 0;
}
}
return 1;
}
static int mount_points_setup(size_t n, bool loaded_policy) {
int ret = 0, r;
int r = 0;
assert(n <= ELEMENTSOF(mount_table));
FOREACH_ARRAY(mp, mount_table, n) {
r = mount_one(mp, loaded_policy);
if (r != 0 && ret >= 0)
ret = r;
}
FOREACH_ARRAY(mp, mount_table, n)
RET_GATHER(r, mount_one(mp, loaded_policy));
return ret;
return r;
}
int mount_setup_early(void) {

View File

@ -3,10 +3,10 @@
#include <stdbool.h>
bool mount_point_is_api(const char *path);
bool mount_point_ignore(const char *path);
int mount_setup_early(void);
int mount_setup(bool loaded_policy, bool leave_propagation);
int mount_cgroup_controllers(void);
bool mount_point_is_api(const char *path);
bool mount_point_ignore(const char *path);