Skip to content

Commit

Permalink
core/namespace: s/normalize_mounts()/drop_unused_mounts()
Browse files Browse the repository at this point in the history
Rename the normalize_mounts() helper to drop_unused_mounts. All the
helpers called in there get rid of mounts that are unused for a variety
of reasons. And whereas the helpers are aptly prefixed with "drop" the
overall helper isn't and instead uses "normalize".

Make it more obvious what the helper actually does by renaming it from
normalize_mounts() to drop_unused_mounts(). Readers of code calling this
helper will immediately see that it will get rid of unused mounts.

Link: systemd/systemd#22206
(cherry picked from commit fbf90c0)
(cherry picked from commit 09936a7)
(cherry picked from commit 2540b0e)
  • Loading branch information
brauner authored and bluca committed Nov 4, 2022
1 parent 4ded4cd commit 917e747
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/namespace.c
Original file line number Diff line number Diff line change
Expand Up @@ -1548,7 +1548,14 @@ static size_t namespace_calculate_mounts(
ns_info->private_ipc; /* /dev/mqueue */
}

static void normalize_mounts(const char *root_directory, MountEntry *mounts, size_t *n_mounts) {
/* Walk all mount entries and dropping any unused mounts. This affects all
* mounts:
* - that are implicitly protected by a path that has been rendered inaccessible
* - whose immediate parent requests the same protection mode as the mount itself
* - that are outside of the relevant root directory
* - which are duplicates
*/
static void drop_unused_mounts(const char *root_directory, MountEntry *mounts, size_t *n_mounts) {
assert(root_directory);
assert(n_mounts);
assert(mounts || *n_mounts == 0);
Expand Down Expand Up @@ -1629,7 +1636,7 @@ static int apply_mounts(
if (!again)
break;

normalize_mounts(root, mounts, n_mounts);
drop_unused_mounts(root, mounts, n_mounts);
}

/* Create a deny list we can pass to bind_mount_recursive() */
Expand Down Expand Up @@ -2160,7 +2167,7 @@ int setup_namespace(
if (r < 0)
goto finish;

normalize_mounts(root, mounts, &n_mounts);
drop_unused_mounts(root, mounts, &n_mounts);
}

/* All above is just preparation, figuring out what to do. Let's now actually start doing something. */
Expand Down

0 comments on commit 917e747

Please sign in to comment.