Commit Graph
5056 Commits
Author SHA1 Message Date
Yu Watanabe 65e7d565e4 io-util: introduce IOVEC_NULL 2023-02-23 15:09:59 +09:00
Lennart Poettering 253a83ea44 io-util: introduce iovec_array_free()
It will be used in later commits.
2023-02-23 15:09:59 +09:00
Lennart Poettering ff3f1464ec memory-util: add a concept for gcc cleanup attribute based array destruction 2023-02-23 11:43:43 +09:00
Lennart Poettering a649419aae capability-util: add new capability_get_ambient() helper 2023-02-22 23:45:40 +01:00
Lennart Poettering 66c1e440c7 cap-list: add capability_set_to_string_negative() 2023-02-22 23:45:40 +01:00
Lennart Poettering 8cf4674d86 cap-list: add capability_set_to_strv() 2023-02-22 23:45:40 +01:00
Lennart Poettering 921330af40 Merge pull request #26448 from poettering/sd-event-mempress
sd-event: add memory pressure event source
2023-02-22 16:23:59 +01:00
Yu Watanabe 58fbf167d7 Merge pull request #26528 from keszybz/valgrind-simplification
Drop the -Dvalgrind configuration option
2023-02-22 23:04:12 +09:00
Lennart Poettering 158fe190af sd-event: add high-level sd_event_add_memory_pressure() event source
Typically, in reasonably complex programs we want to realease various
caches (such as glibc allocation caches) in case of memory pressure.
Let's add explicit infrastructure for that to sd-event, that can hook
Linux' Pressure Stall Information (PSI) logic with our event loop.

This adds sd_event_add_memory_pressure() as easy, one-step API to
install an even source that is called under memory pressure.

The parameters which file to watch (the per-cgroup PSI file, or the
system-wide file /proc/pressure/memory) can be configured via env vars.
The idea is that the service manager sooner or later gains controls for
setting this up correctly.

Alternatively to the PSI a similar logic is supported but instead of
waiting for POLLPRI on a procfs/cgroupfs fd we'll wait for POLLIN on
FIFO or AF_UNIX sockets. This is useful for testing, and possibly in
other environments, for example to hook up this protocol directly with
GNOME's low memory monitor.

By default this watches on the cgroup-local PSI so that we aren't
affected by pressure on cgroups we are not related to.
2023-02-22 13:09:42 +01:00
Zbigniew Jędrzejewski-Szmek 50b35193ec meson: merge our two valgrind configuration conditions into one
Most of the support for valgrind was under HAVE_VALGRIND_VALGRIND_H, i.e. we
would enable if the valgrind headers were found. The operations then we be
conditionalized on RUNNING_UNDER_VALGRIND.

But in a few places we had code which was conditionalized on VALGRIND, i.e. the
config option. I noticed because I compiled with -Dvalgrind=true on a machine
that didn't have valgrind.h, and the build failed because
RUNNING_UNDER_VALGRIND was not defined. My first idea was to add a check that
the header is present if the option is set, but it seems better to just remove
the option. The code to support valgrind is trivial, and if we're
!RUNNING_UNDER_VALGRIND, it has negligible cost. And the case of running under
valgrind is always some special testing/debugging mode, so we should just do
those extra steps to make valgrind output cleaner. Removing the option makes
things simpler and we don't have to think if something should be covered by the
one or the other configuration bit.

I had a vague recollection that in some places we used -Dvalgrind=true not
for valgrind support, but to enable additional cleanup under other sanitizers.
But that code would fail to build without the valgrind headers anyway, so
I'm not sure if that was still used. If there are uses like that, we can
extend the condition for cleanup_pools().
2023-02-22 11:39:44 +01:00
Yu Watanabe 911f8f0183 process-util: rename FORK_NULL_STDIO -> FORK_REARRANGE_STDIO
And make safe_fork_full() takes fds to be assigned to stdio.
2023-02-21 07:37:51 +09:00
Yu Watanabe e814f8b246 Merge pull request #26506 from keszybz/tiny-cleanups
Various trivial cleanups and follow-ups
2023-02-21 06:41:01 +09:00
Lennart Poettering 76875ba9cb capability-util: use UINT32_MAX as shortcut where appropriatea 2023-02-20 16:49:46 +01:00
Lennart Poettering 3b3ebabfa6 capability-util: add macro for largest cap we're willing to accept
Let's hide the hard to grasp 62 behind a name.
2023-02-20 16:49:45 +01:00
Lennart Poettering 3fd5190b5e capability-util: add CAP_MASK_ALL + CAP_MASK_UNSET macros
We should be more careful with distinguishing the cases "all bits set in
caps mask" from "cap mask invalid". We so far mostly used UINT64_MAX for
both, which is not correct though (as it would mean
AmbientCapabilities=~0 followed by AmbientCapabilities=0) would result
in capability 63 to be set (which we don't really allow, since that
means unset).
2023-02-20 16:49:45 +01:00
Lennart Poettering 6c5fff017e cap-list: make sure never to accidentally return more than 63 caps
The rest of our codebase stores caps masks in a uint64_t, and also
assumes UINT64_MAX was a suitable value for "unset mask". Hence refuse
any caps outside of 0…62.

(right now the kernel knows 40 caps, hence 22 more to go before we have
to reconsider our life's choices.)
2023-02-20 16:49:45 +01:00
Lennart Poettering ebb93f3ccf cap-list: rework capability_set_to_string()
Let's use strextend_with_separator() and CAPABILITY_TO_STRING().
2023-02-20 16:49:45 +01:00
Lennart Poettering c52c4d6974 cap-list: add CAPABILITY_TO_STRING() macro using compound initialization to allocate fallback buffer
Let's add a helper that can return a numeric string in case we don't
recognize a name for a capability.
2023-02-20 16:27:26 +01:00
Lennart Poettering d0e67c69ba cap-list: refuse parsing numeric capability 63
We refuse it otherwise currently, simply because we cannot store it in a
uint64_t caps mask value anymore while retaining the ability to use
UINT64_MAX as "unset" marker.

The check actually was in place already, just one off.
2023-02-20 16:13:49 +01:00
Lennart Poettering 3f444e94f5 cap-list: modernize capability_set_from_string() a bit
Make return parameter optional. And return whether there were any caps
we didn't recognize via 0/1 return value.
2023-02-20 16:13:49 +01:00
Lennart Poettering 8142d73574 cap-list: rename capability_set_to_string_alloc() → capability_set_to_string()
We typically don't use the _alloc() suffix anymore for anything, hence
drop it here too.
2023-02-20 16:13:49 +01:00
Daan De Meyer eb483e7ae1 Merge pull request #26465 from DaanDeMeyer/openat-helpers
Add more openat() helpers of utility functions
2023-02-20 13:58:59 +01:00
Zbigniew Jędrzejewski-Szmek f274f8bf25 sleep: use shared constant for freeze timeout
Let's keep all the timeout definitions in one place.
2023-02-20 13:38:32 +01:00
Daan De Meyer 361bcb2097 env-file: Add write_env_file_at() 2023-02-20 12:43:31 +01:00
Yu Watanabe b9fadf2e2c process-util: show requested process name in the log
This is useful for debugging issues like #26474.
2023-02-19 12:17:52 +09:00
Lennart Poettering d499fdbcf0 shared: move psi-util.[ch] to basic/ so that we can use it in sd-event 2023-02-17 23:46:19 +00:00
Lennart Poettering c56e8d8f41 util: move mallinfo compat glue from selinux code into generic code 2023-02-17 23:45:23 +00:00
Yu Watanabe ebc19b154c hashmap: fix build with valgrind
Follow-up for a2b052b29f.
2023-02-17 22:56:37 +00:00
Lennart Poettering a2b052b29f mempool: rework mempool_cleanup() to only release freed tiles
This substantially reworks mempool_cleanup() so that it releases pools
with all freed tiles only, but keeps all pools with still-allocated
tiles around.

This is more correct, as the previous implementation just released all
pools regardless if anything was still used or not. This would make
valgrind shut up but would just hide memory leaks altogether. Moreover
if called during regular runtime of a program would result in bad memory
accesses all over.

Hence, let's add a proper implementation and only trim pools we really
know are empty.

This way we can safely call these functions later, when under memory
pressure, at any time.
2023-02-17 15:03:53 +01:00
Lennart Poettering 4392b983b8 mempool: make mempool_free_tile() return NULL
To match how we usually do this current allocation code.

(Also, make it accept a NULL pointer, also in order to match behaviour
in the rest of our codebase)
2023-02-17 15:03:10 +01:00
Lennart Poettering 72381db942 mempool: introduce new helper pool_ptr()
This new helper returns the beginning of the usable area of the pool
object.

For now this is only used once, a later commit will use it more.
2023-02-17 15:02:18 +01:00
Lennart Poettering 993a9314c4 mempool: rename local variable to match current coding style 2023-02-17 15:01:36 +01:00
Lennart Poettering b6ff400ffb mempool: use size_t for all memory object sizes and counts 2023-02-17 15:00:55 +01:00
Lennart Poettering 9a0f0ef557 hashmap: expose helper for releasing memory pools independently of valgrind
Let's clean this up and export this always, so that we can later call
when we are under memory pressure.
2023-02-17 14:59:54 +01:00
Lennart Poettering 6aa90884a0 process-util: add helper get_process_threads()
Let's add a proper helper for querying the number of threads in a
process.
2023-02-17 14:27:58 +01:00
Lennart Poettering 6ac55dfb46 sync-util: port fsync_directory_of_file() to fd_is_opath()
As suggested here:

https://github.com/systemd/systemd/pull/26450#pullrequestreview-1302922404
2023-02-17 20:50:01 +09:00
Lennart Poettering 9857dc1117 Merge pull request #26438 from poettering/event-source-shorten
sd-event: reduce memory use of sd_event_source objects
2023-02-17 12:46:55 +01:00
Luca Boccassi b8933fa843 Merge pull request #26341 from DaanDeMeyer/chase-fixes
chase-symlinks fixes
2023-02-17 11:44:47 +00:00
Lennart Poettering fdc2ad76b4 Merge pull request #26447 from poettering/sigqueue
pid1/systemctl: add ability to enqueue POSIX RT sigs with associated value to service processes
2023-02-17 10:51:58 +01:00
Lennart Poettering 9a603dc251 socket-util: make connect_unix_path() work with a NULL path 2023-02-17 10:51:35 +01:00
Lennart Poettering d6e9e8c7b9 macro: add macro for determining size of struct with trailing union 2023-02-17 10:09:30 +01:00
Lennart Poettering 4ea517a6e0 strv: add strv_copy_n() helper for copying part of a n strv 2023-02-17 09:55:35 +01:00
Yu Watanabe 5f904eb751 xattr-util: check if fd has O_PATH and do not try setxattr() twice
Follow-up for a4d2461c46.
2023-02-17 07:34:49 +09:00
Yu Watanabe ea61e2e9bd fd-util: introduce a simple helper to check a file descriptor has O_PATH 2023-02-17 07:18:42 +09:00
Lennart Poettering 1e344c1dc7 log: add common helper log_set_target_and_open()
quite often we want to set a log target and immediately open it. Add a
common helper for that.
2023-02-16 16:32:41 +01:00
Luca Boccassi 8dcfecc833 Merge pull request #26410 from DaanDeMeyer/xattr-symlink
Copy symlink xattrs
2023-02-15 19:55:04 +00:00
Dmitry V. Levin 30fd9a2dab treewide: fix a few typos in NEWS, docs and comments 2023-02-15 10:41:03 +00:00
Yu Watanabe 0b75493da0 tree-wide: fix typo and comment style update 2023-02-15 10:08:16 +09:00
Daan De Meyer a4d2461c46 xattr-util: Add xsetxattr()
Like getxattr_malloc() but for setxattr() and friends.
2023-02-14 12:51:38 +01:00
Zbigniew Jędrzejewski-Szmek 0c90efc9db various: boldify version output
Follow-up for 4453ebe4db.
With the feature list all dandified, the most important part of the
output, i.e. the project name and version, are less visible.
2023-02-09 15:32:33 +00:00