Commit Graph
55 Commits
Author SHA1 Message Date
Daan De Meyer 74d392ed1b tree-wide: standardize header names across src/fundamental, src/basic and src/shared
Drop the -fundamental suffix from src/fundamental/ headers in favor of names
that match their src/basic/ or src/shared/ counterparts (e.g.
macro-fundamental.h -> macro.h, assert-fundamental.h -> assert-util.h,
cleanup-fundamental.h -> cleanup-util.h). Rename src/basic/{btrfs,label}.{c,h}
to use the -util suffix to match the existing shared/btrfs-util and
shared/label-util siblings. Rename src/shared/mkdir-label.{c,h} to mkdir.{c,h}
and src/shared/tmpfile-util-label.{c,h} to tmpfile-util.{c,h} to match the
corresponding src/basic names.

This saves us from having to come up with separate names for files that do
the same thing across tiers, and it makes it easier to move stuff between
src/fundamental, src/basic and src/shared: consumers just #include "foo.h"
and pick up whichever tier their -I path resolves to first, so call sites
don't need to be updated when an API moves between layers.

Where a higher-tier wrapper exists (e.g. src/basic/macro.h wrapping
src/fundamental/macro.h), the wrapper uses an explicit "../fundamental/foo.h"
or "../basic/foo.h" relative include for the lower-tier header. We can't use
GCC's #include_next directive for this — when the wrapper is reachable both
via same-dir-as-source lookup and via -I (e.g. -Isrc/shared) for the
directory it lives in, #include_next advances by exactly one slot in libcpp's
internal directory chain and lands on the same physical directory it was
already in, never reaching the lower-tier sibling (see make_cpp_dir() in
gcc/libcpp/files.cc:1986).

To make sure the right headers are always picked up, the include directories
are reordered so that e.g. src/shared always takes priority over src/basic and
similar for the other directories.

Co-developed-by: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-21 10:33:03 +09:00
Yu Watanabe 2aa496312e conf-files: introduce CONF_FILES_WARN flag and set it at various places
Closes #40285.
2026-01-16 23:05:33 +09:00
Yu Watanabe 80c5b63db5 mount-setup: memory_recursiveprot is supported since kernel v5.7
Our baseline on kernel is 5.10. Hence we can unconditionally use it.
2026-01-13 10:21:36 +09:00
Yu Watanabe 93378148d4 tree-wide: normalize comment style 2025-12-15 08:50:13 +09:00
Daan De Meyer 886c078702 mount-setup: Add memory_hugetlb_accounting to cgroupfs mount
This mount option will count HugeTLB memory usage towards the cgroup’s
overall memory usage for the memory controller.

See https://lore.kernel.org/all/20231006184629.155543-4-nphamcs@gmail.com/T/#u
for the patch introducing the new mount option.
2025-10-30 22:28:41 +01:00
Daan De Meyer 5ce388aec8 mount-setup: Add optional function which provides extra mount options 2025-10-30 22:28:39 +01:00
Daan De Meyer c46344d597 mount-setup: Reformat table
Preparation for the next commit.
2025-10-30 19:59:29 +01:00
Zbigniew Jędrzejewski-Szmek f2d3472131 core: remove duplicate logging about mountpoints
Early boot log:
Sep 01 12:06:03 fedora systemd[1]: Mounting tmpfs to /dev/shm of type tmpfs with options mode=01777,usrquota.
Sep 01 12:06:03 fedora systemd[1]: Mounting tmpfs (tmpfs) on /dev/shm (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=01777,usrquota")...
Sep 01 12:06:03 fedora systemd[1]: Mounting devpts to /dev/pts of type devpts with options mode=0600,gid=5.
Sep 01 12:06:03 fedora systemd[1]: Mounting devpts (devpts) on /dev/pts (MS_NOSUID|MS_NOEXEC "mode=0600,gid=5")...
Sep 01 12:06:03 fedora systemd[1]: Mounting tmpfs to /run of type tmpfs with options mode=0755,size=20%,nr_inodes=800k.
Sep 01 12:06:03 fedora systemd[1]: Mounting tmpfs (tmpfs) on /run (MS_NOSUID|MS_NODEV|MS_STRICTATIME "mode=0755,size=20%,nr_inodes=800k")...
Sep 01 12:06:03 fedora systemd[1]: Mounting cgroup2 to /sys/fs/cgroup of type cgroup2 with options nsdelegate,memory_recursiveprot.
Sep 01 12:06:03 fedora systemd[1]: Mounting cgroup2 (cgroup2) on /sys/fs/cgroup (MS_NOSUID|MS_NODEV|MS_NOEXEC "nsdelegate,memory_recursiveprot")...
Sep 01 12:06:03 fedora systemd[1]: Mounting pstore to /sys/fs/pstore of type pstore with options ''.
Sep 01 12:06:03 fedora systemd[1]: Mounting pstore (pstore) on /sys/fs/pstore (MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Sep 01 12:06:03 fedora systemd[1]: Mounting efivarfs to /sys/firmware/efi/efivars of type efivarfs with options ''.
Sep 01 12:06:03 fedora systemd[1]: Mounting efivarfs (efivarfs) on /sys/firmware/efi/efivars (MS_NOSUID|MS_NODEV|MS_NOEXEC "")...
Sep 01 12:06:03 fedora systemd[1]: Mounting bpf to /sys/fs/bpf of type bpf with options mode=0700.
Sep 01 12:06:03 fedora systemd[1]: Mounting bpf (bpf) on /sys/fs/bpf (MS_NOSUID|MS_NODEV|MS_NOEXEC "mode=0700")...

We logged and then called mount_verbose_full() immediately after, resulting in
duplicate logging. The second line is more informative than the first one, so
kill the first one.
2025-09-03 08:56:21 +02:00
Daan De Meyer 69a283c5f2 shared: Clean up includes
Split out of #37344.
2025-05-24 14:00:44 +02:00
Mike Yuan 512e89e750 mount-setup: swap MountMode and condition_fn in struct
To avoid unnecessary 'NULL's in structured initializer.
2025-04-11 23:44:24 +02:00
Mike Yuan 02c4d27b17 nspawn: do not spuriously override cgroup2fs options on host 2025-04-04 14:36:14 +02:00
Yu Watanabe b0c9ba4eb1 core: delegate mountns implicitly when any of pidns/cgns/netns is in use, clean up private cgroupfs mount (#36892)
Fixes #36952
2025-04-03 00:15:33 +09:00
Zbigniew Jędrzejewski-Szmek 0a5b70f3b1 shared/mount-setup: use '' to signify empty option string
We said:
systemd[1]: Mounting efivarfs to /sys/firmware/efi/efivars of type efivarfs with options n/a.
I think '' is clearer.
2025-04-01 11:28:00 +02:00
Mike Yuan 1614d0c451 core/namespace: stop applying mount options on private cgroupfs mount
We always unshare cgroup ns for ProtectControlGroups=private/strict,
while the mount options only apply to the cgroupfs instance
in initial cgns (c.f.
https://github.com/torvalds/linux/blob/b69bb476dee99d564d65d418e9a20acca6f32c3f/kernel/cgroup/cgroup.c#L1984)
Hence let's drop the thing wholesale.

Also, as noted in the comment already, mount_private_apivfs()
internally enforces nosuid/noexec, so drop explicit flags too.
2025-03-30 18:57:18 +02:00
Mike Yuan 8d538d3fbb cgroup-setup: drop hierarchy detection, always use v2 2025-03-16 15:30:39 +01:00
Mike Yuan 36dad381a2 mount-setup: remove cgroup v1 hierarchy mounting 2025-03-16 15:30:38 +01:00
Mike Yuan 64db06c421 mount-setup: generalize cgroupfs_recursiveprot_supported() 2025-03-16 15:22:13 +01:00
Mike Yuan b05c495eed mount-setup: tune down log level if usrquota is not supported, apply usrquota when smack is in use too
Follow-up for 8f5131fb9e
2025-03-08 19:16:17 +01:00
Mike Yuan 80b7f60d2e mount-setup: drop outdated comment 2025-03-08 19:16:17 +01:00
Lennart Poettering 8f5131fb9e pid1: enable usrquota support on /dev/shm 2025-01-18 23:13:06 +01:00
Yu Watanabe a4d1891475 meson: allow to customize the access mode for tty/pts devices
Then, switch the default value to "0600", due to general security
concerns about terminals being written to by other users.

Closing #35599.
2024-12-16 21:36:07 +00:00
Zbigniew Jędrzejewski-Szmek d0ab0e5fa5 pid1: stop refusing to boot with cgroup v1
Since v256 we completely fail to boot if v1 is configured. Fedora 41 was just
released with v256.7 and this is probably the first major exposure of users to
this code. It turns out not work very well. Fedora switched to v2 as default in
F31 (2019) and at that time some people added configuration to use v1 either
because of Docker or for other reasons. But it's been long enough ago that
people don't remember this and are now very unhappy when the system refuses to
boot after an upgrade.

Refusing to boot is also unnecessarilly punishing to users. For machines that
are used remotely, this could mean somebody needs to physically access the
machine. For other users, the machine might be the only way to access the net
and help, and people might not know how to set kernel parameters without some
docs. And because this is in systemd, after an upgrade all boot choices are
affected, and it's not possible to e.g. select an older kernel for boot. And
crashing the machine doesn't really serve our goal either: we were giving a
hint how to continue using v1 and nothing else.

If the new override is configured, warn and immediately boot to v1.
If v1 is configured w/o the override, warn and wait 30 s and boot to v2.
Also give a hint how to switch to v2.

https://bugzilla.redhat.com/show_bug.cgi?id=2323323
https://bugzilla.redhat.com/show_bug.cgi?id=2323345
https://bugzilla.redhat.com/show_bug.cgi?id=2322467
https://www.reddit.com/r/Fedora/comments/1gfcyw9/refusing_to_run_under_cgroup_01_sy_specified_on/

The advice is to set systemd.unified_cgroup_hierarchy=1 (instead of removing
systemd.unified_cgroup_hierarchy=0). I think this is easier to convey. Users
who are understand what is going on can just remove the option instead.

The caching is dropped in cg_is_legacy_wanted(). It turns out that the
order in which those functions are called during early setup is very fragile.
If cg_is_legacy_wanted() is called before we have set up the v2 hierarchy,
we incorrectly cache a true answer. The function is called just a handful
of times at most, so we don't really need to cache the response.
2024-11-06 13:43:25 +00:00
Mike Yuan a0a09da45e mount-setup: fix typo 2024-04-26 10:24:38 +08:00
Mike Yuan 21f8e749a1 mount-setup: use mount_verbose_full where appropriate 2024-04-24 08:39:26 +08:00
Matteo Croce 854711645b use FOREACH_ELEMENT
Use FOREACH_ELEMENT where possible. Generated with this command,
and checked manually:

    git grep -l 'FOREACH_ARRAY.*ELEMENTSOF' | \
    xargs sed -ri 's/FOREACH_ARRAY\((.*), (.*), (ELEMENTSOF.*)\)/FOREACH_ELEMENT(\1, \2)/'
2024-04-18 17:39:34 +02:00
Mike Yuan f2512de82d core: refuse cgroupv1 unless SYSTEMD_CGROUP_ENABLE_LEGACY_FORCE
Also, add a 30s sleep even if cgroup v1 is forced.

Closes #30852
2024-02-27 23:10:49 +08:00
Mike Yuan fbc8d90bd5 shared/mount-setup: split out mount_cgroup_legacy_controllers 2024-02-27 23:03:43 +08:00
Mike Yuan 72a9f4fa45 shared/mount-setup: minor modernization 2024-02-27 23:03:43 +08:00
Mike Yuan b409aacb0a mountpoint-util: introduce path_is_mount_point_full 2024-02-06 15:09:28 +08:00
Mike Yuan 38617c516a various: use FOREACH_ARRAY more
Prompted by #30622
2023-12-25 20:17:48 +09:00
Yu Watanabe b3a9d980f3 tree-wide: drop space between variable and an increment/decrement 2023-12-25 01:56:40 +09:00
cunshunxia 556c674d6e mute the memory recursiveprot log if version of kernel is low. 2023-06-28 10:59:00 +02:00
Lennart Poettering d585065624 mount-setup: exclude /run/nextroot/ from relabelling
Just like /run/initramfs/ the data in /run/nextroot/ should be a
self-contained OS tree, and not require labelling, hence don't.
2023-06-02 18:43:10 +02:00
Daan De Meyer 0690160e2c label: Rename to label-util.h 2023-05-30 14:50:56 +02:00
Lennart Poettering 93d4a200fb Merge pull request #27648 from poettering/common-dissect-dir
pid1: add common root dir inode to mount disk images to in private namespaces
2023-05-16 05:26:48 -07:00
Lennart Poettering 04dc2db08a mount-setup: minor modernization 2023-05-16 10:01:28 +02:00
Lennart Poettering ce6fa09567 mount-setup: minor log improvement 2023-05-16 10:00:04 +02:00
Lennart Poettering 4900c3e5b1 mount-setup: port to logging about mount attempts via mount_*follow_verbose() 2023-05-16 10:00:04 +02:00
Lennart Poettering 3690bfb5b2 namespace: introduce a common dir in /run/ that we can use to see new root fs up on
This creates a new dir /run/systemd/mount-rootfs/ early in PID 1 that
thus always exists. It's supposed to be used by any code that creates
its own mount namespace and then sets up a new root dir to switch into.
So far in many cases we used a temporary dir (which needed explicit
clean-up) or a purpose-specific fixed dir.

Let's create a common dir instead, that always exists (as it is created
in PID 1 early on, always).

Besides making things more robust, as manual clean-up of the inode is
not necessary anymore this also opens the door for unprivileged programs
to use the same dir, since it now always exists.

Set the access mode to 555 (instead of the otherwise previously used
0755, 0700 or similar), so that unprivileged programs can access it, but
we make clear it's not supposed to be written directly to, by anyone,
not even root.
2023-05-16 09:24:45 +02:00
Lennart Poettering 2a10774caa mount-setup: use size_t when iterating through array indexes 2023-05-02 12:06:03 +02:00
Daan De Meyer ab3a46f837 mount-setup: Fix typo 2023-02-14 15:09:32 +01:00
Zbigniew Jędrzejewski-Szmek 9f563f2792 tree-wide: use mode=0nnn for mount option
This is an octal number. We used the 0 prefix in some places inconsistently.
The kernel always interprets in base-8, so this has no effect, but I think
it's nicer to use the 0 to remind the reader that this is not a decimal number.
2022-12-14 22:12:44 +01:00
jcg 5e5fce3e91 mount-setup: don't need to mount /sys/fs/pstore if there is no ENABLE_PSTORE 2022-12-10 12:02:25 +09:00
Zbigniew Jędrzejewski-Szmek 5980d46304 strv: declare iterator of FOREACH_STRING() in the loop
Same idea as 03677889f0.

No functional change intended. The type of the iterator is generally changed to
be 'const char*' instead of 'char*'. Despite the type commonly used, modifying
the string was not allowed.

I adjusted the naming of some short variables for clarity and reduced the scope
of some variable declarations in code that was being touched anyway.
2022-03-23 11:50:18 +01:00
Yu Watanabe de010b0b2e strv: make iterator in STRV_FOREACH() declaread in the loop
This also avoids multiple evaluations in STRV_FOREACH_BACKWARDS()
2022-03-19 08:33:33 +09:00
Lennart Poettering 35cd0ba516 shared: clean up mkdir.h/label.h situation
Previously the mkdir_label() family of calls was implemented in
src/shared/mkdir-label.c but its functions partly declared ins
src/shared/label.h and partly in src/basic/mkdir.h (!!). That's weird
(and wrong).

Let's clean this up, and add a proper mkdir-label.h matching the .c
file.
2021-11-16 17:03:28 +01:00
Lennart Poettering 7c248223eb tree-wide: use new RET_NERRNO() helper at various places 2021-11-16 08:04:09 +01:00
Lennart Poettering aea0fe53ae mount-setup: port from nftw() to recurse_dir() 2021-10-07 11:59:23 +02:00
Zbigniew Jędrzejewski-Szmek 07b382cc2b meson: ignore -Dsmack-run-label= if -Dsmack=false
Compilation would fail because we could have HAVE_SMACK_RUN_LABEL without
HAVE_SMACK. This doesn't make much sense, so let's just make -Dsmack=false
completely disable smack.

Also, the logic in smack-setup.c seems dubious: '#ifdef SMACK_RUN_LABEL'
would evaluate to true even if -Dsmack-run-label='' is used. I think
this was introduced in the conversion to meson:
8b197c3a8a added

AC_ARG_WITH(smack-run-label,
AS_HELP_STRING([--with-smack-run-label=STRING],
        [run systemd --system with a specific SMACK label]),
        [AC_DEFINE_UNQUOTED(SMACK_RUN_LABEL, ["$withval"], [Run with a smack label])],
        [])

i.e. it really was undefined if not specified. And it was same
still in 72cdb3e783 when configure.ac
was dropped.

So let's use the single conditional HAVE_SMACK_RUN_LABEL everywhere.
2021-09-21 20:13:37 +02:00
Yu Watanabe 594c383554 cgroup-util: use string_hash_ops_free 2021-09-11 20:29:34 +09:00