Commit Graph

6670 Commits

Author SHA1 Message Date
Lennart Poettering
5e71f86dff alloc-util: add realloc0() helper than is like realloc() but zero-initializes appended space 2023-10-06 07:44:47 +02:00
Lennart Poettering
2c07d314b2 fileio: revamp search_and_fopen()
Let's modernize and clean up search_and_fopen a bit: let's add support
for regular open() (instead of fopen()), as well as access() (if caller
just wants to check if a file exists without opening it.

This unifies much of the code involved, which previously was duplicated
in search_and_fopen() and search_and_fopen_nulstr()
2023-10-05 19:01:28 +02:00
Lennart Poettering
b0ae589b3e pidref: add trivial helper pidref_set_self() to set pidref to our handle to our own process 2023-10-05 17:08:35 +02:00
Daan De Meyer
d852352b9c mountpoint-util: Check hardcoded list before asking kernel if option is supported
mount_option_supported() will call fsopen() which will probe the
kernel filesystem module. This means that we'll suddenly start
probing filesystem modules when running generators as those determine
which mount options to use. To prevent generators from loading kernel
filesystem modules as much as possible, let's always first check the
hardcoded list of filesystem which we know support a feature before
falling back to asking the kernel.
2023-10-05 16:50:30 +02:00
Lennart Poettering
c6711da087 Merge pull request #29454 from poettering/cg-pidref-get-path
cgroup-util: add cg_pidref_get_path() helper and use it
2023-10-05 15:44:25 +02:00
Lennart Poettering
a906224288 cgroup-util: add cg_pidref_get_path() helper and use it 2023-10-05 13:26:25 +02:00
Lennart Poettering
b30da1c632 cgroup-util: make sure cg_get_owner() only works for cgroups, not cgroup attribute files 2023-10-05 11:12:38 +02:00
Lennart Poettering
bd1791b597 cgroup-util: drop "controller" argument from various cgroup helper calls
systemd's own cgroup hierarchy is special to us, we use it to actually
manage processes. Because of that many calls tha apply to cgroups are
only ever called with the SYSTEMD_CGROUP_CONTROLLER as controller
argument. Let's hence remove the argument altogether.

This in particular touches the kill and xattr routines.

This changes no behaviour, we just drop an argument that is always set
to the same value anyway.

This is preparation to eventually getting rid of the cgroupvs1, because
on cgroupvs2 the cgroup paths do not change for different controllers,
there's only a single hierarchy there.
2023-10-05 11:11:04 +02:00
Yu Watanabe
fcdd21ec6a tree-wide: fix typo 2023-10-04 08:58:10 +09:00
NRK
be1666886b macro: use __builtin_unreachable on NDEBUG
note that this slightly changes the semantic of assert when NDEBUG is
defined. if there's an extern function call (without attribute pure or
similar) then the compiler has to assume it has side effects and still
emit the function call.

whereas the old assert guaranteed that nothing will be evaluated on
NDEBUG.

Closes: https://github.com/systemd/systemd/issues/29408
2023-10-03 21:34:38 +02:00
Luca Boccassi
df3e378a5d Merge pull request #29339 from bluca/mount_namespace_new_api
Use new mount API for bind/image mount tunnel
2023-10-02 16:04:26 +01:00
Lennart Poettering
015d19e3ac Merge pull request #29405 from poettering/boot-xmalloc0
boot: add xmalloc0() + memzero() helpers
2023-10-02 16:45:40 +02:00
Luca Boccassi
f273c09c51 mountpoint-util: add bool mount_new_api_supported() helper 2023-10-02 14:02:32 +01:00
Lennart Poettering
4ac79c2b77 memory-util: move memzero() to src/fundamental/ to share with UEFI
(and while we are at it, make sure it returns the input pointer as
output)
2023-10-02 15:00:13 +02:00
Yu Watanabe
7e2a5fbd85 fileio: make read_full_file_full() usable with size and READ_FULL_FILE_UNBASE64
When READ_FULL_FILE_UNBASE64 (or READ_FULL_FILE_UNHEX) is specified,
setting size argument by caller is difficult, as it is hard to estimate
the encoded length.

This makes when size is specified with decoding option, let's read file
more, and check decoded size later with the specified size.
2023-10-02 10:36:43 +09:00
Daan De Meyer
4444564a95 Merge pull request #29193 from keszybz/path-util-adjustment
Make unit mangling follow paths
2023-09-29 11:33:12 +02:00
Lennart Poettering
ec8dc83530 pidref: add pidref_verify() helper
This new helper can be used after reading process info from procfs, to
verify that the data that was just read actually matches the pidfd, and
does not belong to some new process that just reused the numeric PID of
the process we originally pinned.
2023-09-28 23:22:58 +02:00
Lennart Poettering
9cb7e49f11 pidref: add pidref_hash_ops
This adds a "hash_ops" structure, which allows using PidRef structures
as keys in Hashmap and Set objects.
2023-09-28 23:22:58 +02:00
Lennart Poettering
837659825f pidref: add helpers for managing PidRef on the heap
Usually we want to embed PidRef in other structures, but sometimes it
makes sense to allocate it on the heap in case it should be used
standalone. Add helpers for that.

Primary usecase: use as key in Hashmap objects, that for example map
process to unit objects in PID 1.

This adds pidref_free()/pidref_freep() for freeing such an allocated
struct, as well as pidref_dup() (for duplicating an existing PidRef
on the heap 1:1), and pidref_new_pid() (for allocating a new PidRef from a
PID).
2023-09-28 23:22:58 +02:00
Lennart Poettering
dcfcea6d02 pidref: add PIDREF_MAKE_FROM_PID()
This helper truns a pid_t into a PidRef. It's different from
pidref_set_pid() in being "passive", i.e. it does not attempt to acquire
a pidfd for the pid.

This is useful when using the PidRef as a lookup key that shall also
work after a process is already dead, and hence no conversion to a pidfd
is possible anymore.
2023-09-28 23:22:58 +02:00
Lennart Poettering
12c7d27b65 cgroup-util: add cg_read_pidref() helper
Just like cg_read_pid() but returns a PidRef
2023-09-28 23:22:58 +02:00
Zbigniew Jędrzejewski-Szmek
5342eb4633 Rework unit_name_mangle_with_suffix() to (very slightly) simplify the path
'systemctl status /../dev' now looks for 'dev.mount', not '-..-dev.service',
and 'systemctl status /../foo' looks for 'foo.mount', not '-..-foo.service'. I
think this much more useful. I think the escaping is not very useful, so I plan
to submit a later series which changes that behaviour. But I think this first
step here is already useful on its own.

Note that the patch is smaller than it seems: before, is_device_path() would
return true only for absolute paths, so moving of is_device_path() under the
path_is_absolute() conditional doesn't influence the logic.
2023-09-28 13:09:25 +02:00
Lennart Poettering
4ed9e2619c bootctl: highlight SecureBoot enabled state in green 2023-09-28 12:07:15 +02:00
Lennart Poettering
0869e1326a oomd: correct listening sockets
So, unfortunately oomd uses "io.system." rather than "io.systemd." as
prefix for its sockets. This is a mistake, and doesn't match the
Varlink interface naming or anything else in oomd.

hence, let's fix that.

Given that this is an internal protocol between PID1 and oomd let's
simply change this without retaining compat.
2023-09-25 23:27:18 +02:00
Lennart Poettering
8e47958423 string-util: make strgrowpad0() a bit safer
Let#s make sure we never shorten the allocation leaving an invalid
string (i.e. a memory allocation without a trailing NUL) around.
2023-09-25 19:10:37 +02:00
Lennart Poettering
b907b9075e alloc-util: remove duplicate empty line 2023-09-25 18:49:21 +02:00
Zbigniew Jędrzejewski-Szmek
a0fe45a93f Merge pull request #29224 from keszybz/netdev-config-parsing
Use a helper to simplify parsing of ranges in netdev config and related changes
2023-09-22 14:29:47 +02:00
Zbigniew Jędrzejewski-Szmek
660087dc9c tree-wide: add path_simplify_alloc() and use it
path_simplify_full()/path_simplify() are changed to allow a NULL path, for
which a NULL is returned. Generally, callers have already asserted before that
the argument is nonnull. This way path_simplify_full()/path_simplify() and
path_simplify_alloc() behave consistently.

In sd-device.c, logging in device_set_syspath() is intentionally dropped: other
branches don't log.

In mount-tool.c, logging in parse_argv() is changed to log the user-specified
value, not the simplified string. In an error message, we should show the
actual argument we got, not some transformed version.
2023-09-22 08:13:34 +02:00
Zbigniew Jędrzejewski-Szmek
003ccba650 basic/path-util: make path_simplify() skip leading '/..'
I.e., /.. becomes /, /../foo becomes /foo, /../../bar becomes /bar, etc. We can
do this unconditionally, without access to the file system, because the parent
of the root directory always resolves to. /.. in other places is handled as
before, because resolving it properly would require access to the file system
which we don't want to do in path_simplify().
2023-09-21 18:01:03 +02:00
Joerg Behrmann
7c52d5236a treewide: split commandline into command line 2023-09-20 16:37:23 +01:00
Lennart Poettering
b401efe5d2 time-util: use clock_nanosleep() rather than nanosleep()
nanosleep() is kinda broken since it sleeps in the CLOCK_REALTIME clock,
i.e. is subject to time changes.

Let's use clock_nanosleep() instead with CLOCK_MONOTONIC, which is
really the only thing that makes sense.
2023-09-20 11:22:20 +02:00
Mike Yuan
c8d44d818f Merge pull request #29231 from poettering/cgroup-utils-tweaklets
minor tweaks/modernizations in cgroup-util.[ch]
2023-09-20 13:06:16 +08:00
Lennart Poettering
3b74b4958b pidref: add pidref_equal() helper
This compares two PidRef structures via the pid_t field. Ideally we'd do
a stricter comparison here, that is safe towards PID reuse, but so far
the pidfd API lacks suitable mechanisms for that, hence do the best we
can do.
2023-09-20 13:02:21 +08:00
Lennart Poettering
5ed7cdfb8f cgroup-util: tighten range check before casting to pid_t 2023-09-19 22:43:06 +02:00
Lennart Poettering
8ab40789d9 cgroup-util: initialize return param on all success returns
As per coding style.
2023-09-19 22:43:06 +02:00
Lennart Poettering
aef43552fc cgroup-util: rename return param to 'ret', as per coding style 2023-09-19 22:43:06 +02:00
Joerg Behrmann
7227dd816f treewide: fix typos
- mostly: usecase -> use case
- continously -> continuously
- single typos in docs/FILE_DESCRIPTOR_STORE.md
2023-09-19 10:05:38 +02:00
Zbigniew Jędrzejewski-Szmek
3b6cabd806 basic/parse-util: add helper to parse bounded unsigned values
"parse_range" is already used for stuff like "a-b", so use "bounded" here to
avoid confusion.
2023-09-19 09:35:52 +02:00
Lennart Poettering
a0d1659c23 pidref: add sigqueue() helper 2023-09-18 19:08:09 +02:00
Zbigniew Jędrzejewski-Szmek
a410b3a3d4 basic: indent prototypes of two functions with many arguments 2023-09-18 14:09:34 +02:00
Zbigniew Jędrzejewski-Szmek
00d811a548 basic/path-util: change 'char *func' to 'char* func'
Both styles were mixed in the file, but I find the latter much nicer,
because it's not the func that is the pointer, but the return type.
2023-09-18 14:09:34 +02:00
Zbigniew Jędrzejewski-Szmek
8f1998b8d3 basic/path-util: do not say that /dev and /sys are device paths
"/dev" or "/dev/" is the mount point, not a device path. In particular,
'systemctl status /dev' clearly does not refer to a device, so let's tweak
the code a bit to say that those are not device paths.

(Treating "/../dev" same as "/dev" would be also be reasonable, but that
requires chase(), which requires disk access, which we don't want to do from
this lightweight function.)
2023-09-18 14:09:32 +02:00
Luca Boccassi
fd0a804271 Merge pull request #29130 from poettering/unit-defaults
core: introduce UnitDefaults structure for unit defaults
2023-09-09 19:15:46 +01:00
Lennart Poettering
3bda3f17fa pidref: add structure that can reference a pid via both pidfd and pid_t
Let's start with the conversion of PID 1 to pidfds. Let's add a simple
structure with just two fields that can be used to maintain a reference
to arbitrary processes via both pid_t and pidfd.

This is an embeddable struct, to keep it in line with where we
previously used a pid_t directly to track a process.

Of course, since this might contain an fd on systems where we have pidfd
this structure has a proper lifecycle.

(Note that this is quite different from sd_event_add_child() event
source objects as that one is only for child processes and collects
process results, while this infra is much simpler and more generic and
can be used to reference any process, anywhere in the tree.)
2023-09-09 14:03:31 +02:00
Lennart Poettering
7b9da3861a Revert "tree-wide: Mount file descriptors via /proc/<pid>/fd" 2023-09-08 22:13:09 +01:00
Lennart Poettering
bfb27b06da manager: add manager_set_unit_defaults() call that sets all unit defaults in one go
No change in behaviour. Just some refactoring.
2023-09-08 15:25:05 +02:00
Mike Yuan
b8f18c3089 Merge pull request #29123 from yuwata/conf-parser-cleanups-for-config-section
conf-parser: several cleanups and generalizations for ConfigSection
2023-09-08 18:11:12 +08:00
Lennart Poettering
fea82394bc Merge pull request #29071 from YHNdnzj/loop-write-full
io-util: introduce loop_write_full and use it where appropriate
2023-09-08 10:24:39 +02:00
Yu Watanabe
7bf9e0d5f6 hashmap: introduce HASHMAP_BASE_FOREACH() and friend 2023-09-08 12:55:44 +09:00
наб
ef658a63f8 parse_timestamp: accept RFC3339-style timezone and %FT%R[:%S[.%N]]
We basically parsed the RFC3339 format already, except with a space:
      NOTE: ISO 8601 defines date and time separated by "T".
      Applications using this syntax may choose, for the sake of
      readability, to specify a full-date and full-time separated by
      (say) a space character.
so now we handle both
  2012-11-23 11:12:13.456
  2012-11-23T11:12:13.456
as equivalent.

Parse directly-suffixed Z and +05:30 timezones as well:
  2012-11-23T11:12:13.456Z
  2012-11-23T11:12:13.456+02:00
as they're both defined by RFC3339.

We do /not/ allow z or t; the RFC says
      NOTE: Per [ABNF] and ISO8601, the "T" and "Z" characters in this
      syntax may alternatively be lower case "t" or "z" respectively.

      This date/time format may be used in some environments or contexts
      that distinguish between the upper- and lower-case letters 'A'-'Z'
      and 'a'-'z' (e.g. XML).  Specifications that use this format in
      such environments MAY further limit the date/time syntax so that
      the letters 'T' and 'Z' used in the date/time syntax must always
      be upper case.  Applications that generate this format SHOULD use
      upper case letters.
We /are/ in a case-sensitive environment, neither are in wide-spread
use, and "z" poses an issue of whether "todayz" should be the same
as "todayZ" ("today UTC") or an error (it should be an error).

Fractional seconds are limited to six digits (they're nominally
   time-secfrac    = "." 1*DIGIT
), since we only support 1µs-resolution timestamps, and limit to six
digits in our other sub-second formats.

Parsing
  2012-11-23T11:12
is an extension two ways (no seconds, no timezone),
mirroring our "canonical" format.

Fixes #5194
2023-09-07 17:33:15 +02:00