Commit Graph
82957 Commits
Author SHA1 Message Date
Lennart Poettering 9afe65d974 pid1: properly report if we managed to kill a process by cgroup 2025-07-08 02:32:42 +02:00
Yu Watanabe 3ef791876b core: add quota support for State, Cache, and Log exec directories (#35892)
Based on https://github.com/systemd/systemd/issues/7820, this adds support for
quota enforcement to State, Cache, and Log exec directories.
* Add new directives, StateDirectoryQuota=, CacheDirectoryQuota=, and
  LogDirectoryQuota=, to define quotas as percentages (hard limits for
  blocks and inodes) or absolute values (hard limits for blocks only).
* Add new directives, StateDirectoryQuotaAccounting=,
  CacheDirectoryQuotaAccounting= and LogDirectoryQuotaAccounting= to keep
  track of storage quotas but not enforce them (effectively just assigning
  a project ID to defined exec directories).

Example:
```
StateDirectory=quotadir
StateDirectoryQuota=1%

Jan 06 22:55:46 abeltran: Storage quotas set for /var/lib/private/quotadir. Block limit = 2639404, inode limit = 671088

root@abeltran:/var/lib/private# lsattr -pR
3153000189 --------------e----P-- ./quotadir

root@abeltran:/var/lib/private# repquota  -P /datadrive
*** Report for project quotas on device /dev/sdc1
Block grace time: 7days; Inode grace time: 7days
                        Block limits                File limits
Project         used    soft    hard  grace    used  soft  hard  grace
----------------------------------------------------------------------
#0        --  213200       0       0           4086     0     0         
#3153000189 -- 2639404       0 2639404              2     0 671088   
```
2025-07-08 09:18:20 +09:00
Yu Watanabe ef6b6f31c7 bootspec: fix string table naming for BootEntryType/BootEntrySource (#38106)
This was all very confusing and not matching our coding style
recommendations. Let's fix that.

Prompted by #37897, which really should make use of BootEntryType, but
we better clean it up first.
2025-07-08 09:11:30 +09:00
Lennart Poettering bb176bdb51 man: also use title case in systemd.service(5)
Follow-up for: 172dd81e92
2025-07-08 09:05:58 +09:00
Yu Watanabe 825a1f9ecb core/cgroup: prepare for removal of tracking/bookkeeping logic specific to cgroup v1 (#38099) 2025-07-08 08:37:01 +09:00
Andres Beltran c777c05125 test: add test for quotas on Exec directories 2025-07-07 17:31:05 +00:00
Andres Beltran e8e274c8da Add quota support for systemctl 2025-07-07 17:31:05 +00:00
Andres Beltran a89afe1948 Add quota support for DBus 2025-07-07 17:31:03 +00:00
Andres Beltran 26c6f3271a core: add quota support for State, Cache, and Log exec directories 2025-07-07 17:28:47 +00:00
Andres Beltran 744086b58d shared: add exec-directory-util.ch 2025-07-07 17:28:47 +00:00
Andres Beltran 81e6b3685a quota-util: add methods to read and set project IDs 2025-07-07 17:28:47 +00:00
Andres Beltran 652ba6e0dc chattr-util: add helpers to read and set project IDs 2025-07-07 17:28:47 +00:00
Lennart Poettering 1e7ba4780d bootspec: boot_entry_source_to_json_string() to boot_entry_source_to_string()
As with the previous changes for BootEntryType, let's also clean up the
naming for BootEntrySource.
2025-07-07 18:26:59 +02:00
Lennart Poettering 2030922e2d bootspec: rename boot_entry_source_to_string() to boot_entry_source_description_to_string()
Similar to the previous changes, let's make clear this string table
contains *descriptive*, i.e. meaningful human-readable strings.
2025-07-07 18:25:22 +02:00
Lennart Poettering 9880c7f103 bootspec: rename BootEntryType values
So we exposed different names for the entry types in JSON than we named
our enum values. Which is very confusing. Let's unify that. Given that
the JSON fields are externally visible let's stick to that naming, even
though I think "unified" and "conf" would have been more descriptive.

This ensures we follow our usual logic that the enum identifiers and the
strings they map to use the same naming.
2025-07-07 18:23:59 +02:00
Lennart Poettering a1c7aa6a95 bootspec: include 'UKI' in descriptive name for type #2
I am pretty sure that "UKI" is the best known name for type #2 boot
loader spec entries, hence we really should put it in the name.
2025-07-07 18:13:06 +02:00
Lennart Poettering 199989e168 bootspec: rename boot_entry_type_to_string() to boot_entry_type_description_to_string()
This helper does not translate BootEntryType to a string matching the
enum's value names, but instead returns a human readable descriptive
string. Let's make it clearer what this, by including "description" in
the name.
2025-07-07 18:13:06 +02:00
Mike Yuan 6fbb1abf03 TODO: add future deprecation of DefaultMemoryMin/Low= 2025-07-07 17:57:49 +02:00
Mike Yuan f273212797 core/cgroup: unit_realize_cgroup_now_disable() is NOP for non-slice units 2025-07-07 17:55:14 +02:00
Mike Yuan dc537d9479 core/cgroup: make unit_get_ancestor_disable_mask() static 2025-07-07 17:55:13 +02:00
Mike Yuan 7af676c1b6 core/cgroup: tweak unit_invalidate_cgroup_bpf() a bit
- Rename to unit_invalidate_cgroup_bpf_firewall() to make it clear
  that this is about CGROUP_CONTROLLER_BPF_FIREWALL only
- Report whether things changed in unit_invalidate_cgroup()
  to avoid duplicate checks
2025-07-07 17:55:13 +02:00
Mike Yuan ed82caeb39 core/cgroup: dial down "controller" noise
Add some missing assertions while at it.
2025-07-07 17:55:13 +02:00
Mike Yuan 00c4851af0 core/cgroup: workaround for kernel < 5.4 is now irrelevant 2025-07-07 17:55:13 +02:00
Mike Yuan 432e42703e core/cgroup: remove any reference to cgv1 controllers 2025-07-07 17:55:12 +02:00
Mike Yuan 92172973b1 core/cgroup: regroup functions 2025-07-07 17:55:12 +02:00
Mike Yuan 09f380e4e7 core/cgroup: drop unneeded cast 2025-07-07 17:55:12 +02:00
Mike Yuan f3393148a5 core/cgroup: introduce cgroup_context_has_device_policy() helper 2025-07-07 17:55:12 +02:00
Mike Yuan f26d5d76e9 core/cgroup: drop dangling cgroup_context_copy() prototype
Follow-up for 8c35e8a9d2
2025-07-07 17:55:12 +02:00
Mike Yuan 65df8be24b core/cgroup: constify CGROUP_TASKS_MAX_UNSET 2025-07-07 17:54:38 +02:00
Mike Yuan 24e67cea45 man/supported-controllers: refresh list 2025-07-07 17:54:38 +02:00
DaanDeMeyer 90fa161b5b nspawn: Support idmapped mounts on homed managed home directories
Christian made this possible in Linux 6.15 with a new system call
open_tree_attr() that combines open_tree() and mount_setattr().
Because idmapped mounts are (rightfully) not nested, we have to do
some extra shenanigans to make source we're putting the right source
uid in the userns for any idmapped mounts that we do in nspawn.

Of course we also add the necessary boilerplate to make open_tree_attr()
available in our code and wrap open_tree_attr() and the corresponding
fallback in a new function which we then use everywhere else.
2025-07-07 13:58:52 +02:00
DaanDeMeyer bda934d4e5 forward: Add struct mount_attr forward declaration 2025-07-07 13:35:54 +02:00
DaanDeMeyer 2d9759ae6a basic: Add open_tree_attr() syscall wrapper 2025-07-07 13:35:47 +02:00
DaanDeMeyer 3bb59e28f9 basic: Use Static_assert() in missing_syscall_def.h
Let's use Static_assert() so we don't have to include forward.h in
missing_syscall_def.h.
2025-07-07 12:35:56 +02:00
Zbigniew Jędrzejewski-Szmek a2123bf9d4 man: improve Description= documentation (#38101)
Fixes: #36165
2025-07-07 11:56:09 +02:00
Lennart Poettering 172dd81e92 man: improve Description= documentation
This is an attempt to address the issues raised in #36165.

Fixes: #36165
2025-07-07 11:21:25 +02:00
Lennart Poettering d03714e4e4 tree-wide: "human readable" → "human-readable"
Apparently, the spelling with a hyphen is better style in the English
language.

Suggested by: #36165
2025-07-07 11:21:25 +02:00
dependabot[bot] 663108304a build(deps): bump github/codeql-action from 3.28.18 to 3.29.2
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 3.28.18 to 3.29.2.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/ff0a06e83cb2de871e5a09832bc6a81e7276941f...181d5eefc20863364f96762470ba6f862bdef56b)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-version: 3.29.2
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-07-07 17:36:42 +09:00
Lennart Poettering 64a78cb082 Unify error messages for transient settings, fix handling of Ex variants (#38083) 2025-07-07 09:39:40 +02:00
Daan De Meyer c97fd65417 Explicitly include more headers (#38100)
Continuation of 4f18ff2e29.
2025-07-07 08:26:46 +02:00
Yu Watanabe 10b0bc476b timesync,test: explicitly include sys/timex.h when struct timex is used
struct timex is defined by sys/timex.h -> bits/timex.h.
Glibc includes the header in time.h, but let's explicitly include it
when the struct is used.

Similar to 4f18ff2e29, but for sys/timex.h.
2025-07-07 12:44:18 +09:00
Yu Watanabe 83a047fe23 tree-wide: include sys/stat.h where necessary
These source files uses symbols provided by sys/stat.h, e.g. struct stat,
S_IFREG, S_IFBLK, and so on. Let's explicitly include sys/stat.h where
necessary.

Glibc's fcntl.h includes bits/stat.h, which provides these symbols, so
these symbols can be used without explicitly including sys/stat.h. But,
based on the discussion in #37922, we should explicitly include relevant
headers, and should not rely on the indirect inclusion.

Similar to 4f18ff2e29, but for sys/stat.h.
2025-07-07 12:44:10 +09:00
Lennart Poettering 0ae2ac9759 Two follow-ups for recent PRs (#38062) 2025-07-06 22:06:52 +02:00
Zbigniew Jędrzejewski-Szmek 228d84e37a systemd-analyze: stop printing Ex transient settings
The test will fail if we ever add one again in the future by mistake.
2025-07-06 18:17:47 +02:00
Zbigniew Jędrzejewski-Szmek 41288f2daf shared/bus-unit-util: fix PrivateTmp=/PrivateUsers=/ProtectControlGroups= and Ex variants
For some fields, we perform careful parsing and verification on the sender
side. For other fields, we accept any string or strv. I think that actually
this is fine: we should optimize for the correct case, i.e. the user runs a
command that is valid. The server must perform parsing in all cases, so doing
the verification on the sender side doesn't add value. When doing parsing
locally, in case of invalid or unsupported input, we would generate the error
message locally, so we would avoid the D-Bus call, but the message itself is
not better and from the user's point of view, the result is the same. And by
doing the parsing only on the server side, we deal better with the case where
the sender has an older version of the software. By not doing verification, we
implicitly "support" new values. And when the sender has a newer version that
supports additional fields, that does not help as long as the server uses an
older version. So in case of version mismatches, parsing on the server side is
as good or better.

Resolves https://github.com/systemd/systemd/issues/37174.
2025-07-06 18:17:45 +02:00
Zbigniew Jędrzejewski-Szmek fb98c75e0e shared/bus-unit-util: tweak bus_append_exec_command to use Ex prop only if necessary
This changes little in behaviour, the conceptual part is more important. The
non-Ex variant is the actual name on the command line, and we should use the
non-Ex D-Bus property too, if it works. This increases compatibility with old
versions. But the code was mostly doing the right thing. Even the tests tested
the right thing.

Follow-up for b3d593673c and
898fc00e79.

The test is simplified by taking advantage of the fact that both names
on the commandline are supposed to behave identically.

Partially resolves https://github.com/systemd/systemd/issues/37174.
2025-07-06 18:17:43 +02:00
Zbigniew Jędrzejewski-Szmek 6f06afde59 shared/bus-unit-util: rework error messages for NFTSet=
Let's be nice to the user and print the exact reason why we won't accept
a setting.
2025-07-06 18:06:51 +02:00
Zbigniew Jędrzejewski-Szmek 95a3cfcbf6 shared/bus-unit-util: rework error messages
We generally want to have error messages with a fixed structure that convey the
important information, i.e. field name, error value, and the offending text for
options that take short values. (The text is not printed for strings encoded with
base64 and hexmem or for credentials.)

Let's use a helper that prints the message in a fixed format in the majority of
cases. In the few places where a custom message is useful, the helper is not
used. The helper:
- prints the field name, value, and error info,
- quotes the value,
- handles -ENOMEM, so we don't need to handle it separately everywhere.

When this code was originally written, parse functions would return -1
as error. Nowadays day all return a good errno, so it is fine if we print
the corresponding strerror.
2025-07-06 18:06:49 +02:00
Zbigniew Jędrzejewski-Szmek ce120ac823 shared/bus-unit-util: tweak error handling in bus_append_exec_command
exec_command_flags_to_strv() should not fail, unless we screwed up, so assert
instead of returning an error. Also, no need to strdup constant _PATH_BSHELL;
drop that so that we can get rid of the oom error handling. Finally, rename
l → cmdline for clarity.
2025-07-06 17:47:11 +02:00
Yu Watanabe ffe8f21302 basic/include: replace _Static_assert() with static_assert()
If one of the header is included in a C++ source file, then using
_Static_assert() triggers compile error for some reasons.
Let's use static_assert(), which can be used by both C and C++ code.
2025-07-06 22:02:18 +09:00