mirror of
https://github.com/Dasharo/systemd.git
synced 2026-03-06 15:02:31 -08:00
mount-util: move opening of /proc/self/mountinfo into bind_remount_one_with_mountinfo()
Let's move things around a bit, and open /proc/self/mountinfo if needed inside of bind_remount_one_with_mountinfo(). That way bind_remount_one() can become a superthin inline wrapper around bind_remount_one_with_mountinfo(). Main benefit is that we don't even have to open /p/s/mi in case mount_setattr() actually worked for us.
This commit is contained in:
@@ -168,12 +168,12 @@ int bind_remount_recursive_with_mountinfo(
|
||||
char **deny_list,
|
||||
FILE *proc_self_mountinfo) {
|
||||
|
||||
_cleanup_fclose_ FILE *proc_self_mountinfo_opened = NULL;
|
||||
_cleanup_set_free_ Set *done = NULL;
|
||||
unsigned n_tries = 0;
|
||||
int r;
|
||||
|
||||
assert(prefix);
|
||||
assert(proc_self_mountinfo);
|
||||
|
||||
if ((flags_mask & ~MS_CONVERTIBLE_FLAGS) == 0 && strv_isempty(deny_list) && !skip_mount_set_attr) {
|
||||
/* Let's take a shortcut for all the flags we know how to convert into mount_setattr() flags */
|
||||
@@ -199,6 +199,14 @@ int bind_remount_recursive_with_mountinfo(
|
||||
return 0; /* Nice, this worked! */
|
||||
}
|
||||
|
||||
if (!proc_self_mountinfo) {
|
||||
r = fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo_opened);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
proc_self_mountinfo = proc_self_mountinfo_opened;
|
||||
}
|
||||
|
||||
/* Recursively remount a directory (and all its submounts) with desired flags (MS_READONLY,
|
||||
* MS_NOSUID, MS_NOEXEC). If the directory is already mounted, we reuse the mount and simply mark it
|
||||
* MS_BIND|MS_RDONLY (or remove the MS_RDONLY for read-write operation), ditto for other flags. If it
|
||||
@@ -392,22 +400,6 @@ int bind_remount_recursive_with_mountinfo(
|
||||
}
|
||||
}
|
||||
|
||||
int bind_remount_recursive(
|
||||
const char *prefix,
|
||||
unsigned long new_flags,
|
||||
unsigned long flags_mask,
|
||||
char **deny_list) {
|
||||
|
||||
_cleanup_fclose_ FILE *proc_self_mountinfo = NULL;
|
||||
int r;
|
||||
|
||||
r = fopen_unlocked("/proc/self/mountinfo", "re", &proc_self_mountinfo);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
return bind_remount_recursive_with_mountinfo(prefix, new_flags, flags_mask, deny_list, proc_self_mountinfo);
|
||||
}
|
||||
|
||||
int bind_remount_one_with_mountinfo(
|
||||
const char *path,
|
||||
unsigned long new_flags,
|
||||
|
||||
@@ -40,8 +40,12 @@ int mount_nofollow(const char *source, const char *target, const char *filesyste
|
||||
|
||||
int repeat_unmount(const char *path, int flags);
|
||||
int umount_recursive(const char *target, int flags);
|
||||
int bind_remount_recursive(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list);
|
||||
|
||||
int bind_remount_recursive_with_mountinfo(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list, FILE *proc_self_mountinfo);
|
||||
static inline int bind_remount_recursive(const char *prefix, unsigned long new_flags, unsigned long flags_mask, char **deny_list) {
|
||||
return bind_remount_recursive_with_mountinfo(prefix, new_flags, flags_mask, deny_list, NULL);
|
||||
}
|
||||
|
||||
int bind_remount_one_with_mountinfo(const char *path, unsigned long new_flags, unsigned long flags_mask, FILE *proc_self_mountinfo);
|
||||
|
||||
int mount_move_root(const char *path);
|
||||
|
||||
Reference in New Issue
Block a user