Commit Graph

82675 Commits

Author SHA1 Message Date
Zbigniew Jędrzejewski-Szmek
1e99c4e2be test-string-util: add a small test for xsprintf 2025-07-08 13:02:37 +02:00
Zbigniew Jędrzejewski-Szmek
c179466616 Merge shared/exec-directory-util.? into basic/unit-def.?
Suggested in
https://github.com/systemd/systemd/pull/35892#discussion_r2180322856.

This is a tiny amount of code and does not warrant having a separate file
and spawning a separate instance of the compiler during the build.

Note: it took me a while to confirm that the contents of that table and
function don't end up in libsystemd.so. The issue is that they _are_ present in
it, unless LTO is used. We actually use link_whole[libbasic_static] for
libsystemd, so we end up with all that code there. LTO is needed to clean
that up.
2025-07-08 12:57:33 +02:00
Zbigniew Jędrzejewski-Szmek
f283459b9f shared/open-file: add line break
We don't generally parenthesize additions, so drop that too.
2025-07-08 10:22:59 +02:00
Zbigniew Jędrzejewski-Szmek
d9a460b2b6 Adjust bitfields in struct Condition
As is usually the case, the bitfields don't create the expected space savings,
because the field that follows needs to be aligned. But we don't want to fully
drop the bitfields here, because then ConditionType and ConditionResult are
each 4 bytes, and the whole struct grows from 32 to 40 bytes (on amd64). We
potentially have lots of little Conditions and that'd waste some memory.

Make each of the four fields one byte. This still allows the compiler to
generate simpler code without changing the struct size:

E.g. in condition_test:
                 c->result = CONDITION_ERROR;
-   78fab:      48 8b 45 e8             mov    -0x18(%rbp),%rax
-   78faf:      0f b6 50 01             movzbl 0x1(%rax),%edx
-   78fb3:      83 e2 03                and    $0x3,%edx
-   78fb6:      83 ca 0c                or     $0xc,%edx
-   78fb9:      88 50 01                mov    %dl,0x1(%rax)
+   78f8b:      48 8b 45 e8             mov    -0x18(%rbp),%rax
+   78f8f:      c6 40 03 03             movb   $0x3,0x3(%rax)
2025-07-08 10:22:59 +02:00
Lennart Poettering
976444f64f update TODO 2025-07-08 09:56:45 +02:00
Lennart Poettering
14354d70e1 test: invoke systemd-nspawn properly from a session
Let's not run user code outside of user context, that's not how things
are deployed, and means we cannot test the session setup properly
2025-07-08 15:55:01 +09:00
Yu Watanabe
5cc21b78b6 minor fixes to nspawn, machined, vmspawn (#38110)
Nothing earth shattering. Just clean-ups.
2025-07-08 15:54:49 +09:00
Lennart Poettering
18eafedb1a nspawn: Support idmapped mounts on homed managed home directories (#38069)
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-08 06:51:41 +02:00
Lennart Poettering
5279acb58d vmspawn: tighten parser of EXIT_STATUS=
The EXIT_STATUS is supposed to encapuslate an ANSI C process exit
status, which is 8bit unsigned. Hence parse it as such, do not accept
negative values, or values > 255.
2025-07-08 06:43:17 +02:00
Lennart Poettering
ba4624ff6c nspawn: fix parser of --notify-ready=
This switch takes a bool only, not an enum, hence don't claim otherwise
in the error log message.
2025-07-08 06:42:14 +02:00
Lennart Poettering
3779bdd5a3 nspawn: add argument comments to various calls 2025-07-08 06:42:04 +02:00
Lennart Poettering
93555abe29 nspawn: don't use strjoina() for user controlled strings 2025-07-08 06:40:46 +02:00
Lennart Poettering
a13fda9e67 machinectl: fix status output indentation
All other status output lines use tabs, use that for the ID shift line
too. otherwise output will appear unaligned if log viewers have fixed
tab stop positions.
2025-07-08 06:40:35 +02:00
Lennart Poettering
0d8f8be2fd add api to kill subcgroups of units (#38102) 2025-07-08 06:33:32 +02:00
Lennart Poettering
a5ddad2795 tree-wide: switch a bunch of sd_bus_error_setf() to sd_bus_error_set() 2025-07-08 06:00:33 +02:00
Lennart Poettering
8cf772edc1 test: add testcase for subcgroup killing 2025-07-08 03:29:40 +02:00
Lennart Poettering
6b02854f50 systemctl: add --kill-subgroup= switch for killing subcgroup 2025-07-08 03:14:53 +02:00
Lennart Poettering
0f23564ad4 pid1: add ability to kill processes in a subgroup of a unit
This is useful for things like machined, where the system machined wants
to manage a machine owned by the user somewhere down the tree.
2025-07-08 03:14:53 +02:00
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