Commit Graph
5081 Commits
Author SHA1 Message Date
msizanoen1 0b82a6fa5d escape: add missing non-NULL parameter assertions 2023-03-02 19:55:47 +07:00
msizanoen1 00f57157f3 escape: Ensure that output is always valid UTF-8
This ensures that shell string escape operations will not produce output
with invalid UTF-8 from the input by escaping invalid UTF-8 data as if
they were single byte characters.
2023-03-02 19:55:12 +07:00
Lennart Poettering 90ec8ebe33 psi-util: fix error handling
We checked ERRNO_IS_NOT_SUPPORTED on a possible positive non-error code,
which isn't right.

Fix that. Also add caching, since we are about to call this more often.
2023-02-28 12:16:59 +00:00
Lennart Poettering 9b47b18a1a mempool: fix tile alignment check
We should check alignment *after* determining the pointer points into
our pool, not before. Otherwise might might end up checking alignment of
the pointer relative to our base, even though it is taken relative to
some other base.

Follow-up for: a2b052b29f
See: https://github.com/systemd/systemd/pull/26393#issuecomment-1442295012
2023-02-24 14:11:31 +01:00
Yu Watanabe 7a9afae604 time-util: make parse_timestamp() use the RFC-822/ISO 8601 standard timezone spec
If the timezone is specified with a number e.g. +0900 or so, then
let's parse the time as a UTC, and adjust it with the specified time
shift.

Otherwise, if an area has timezone change, e.g.
---
Africa/Casablanca  Sun Jun 17 01:59:59 2018 UT = Sun Jun 17 01:59:59 2018 +00 isdst=0 gmtoff=0
Africa/Casablanca  Sun Jun 17 02:00:00 2018 UT = Sun Jun 17 03:00:00 2018 +01 isdst=1 gmtoff=3600
Africa/Casablanca  Sun Oct 28 01:59:59 2018 UT = Sun Oct 28 02:59:59 2018 +01 isdst=1 gmtoff=3600
Africa/Casablanca  Sun Oct 28 02:00:00 2018 UT = Sun Oct 28 03:00:00 2018 +01 isdst=0 gmtoff=3600
---
then we could not determine isdst from the timezone (+01 in the above)
and mktime() will provide wrong results.

Fixes #26370.
2023-02-24 08:55:27 +09:00
Yu Watanabe 97c5f7ba1f time-util: drop unnecessary assignment of timezone name
As mktime() does not use timezone neme.
2023-02-24 08:55:27 +09:00
Yu Watanabe a83c1baaeb time-util: rename variables
No functional changes, just refactoring.
2023-02-24 08:55:27 +09:00
Yu Watanabe 1d2c42c5dc time-util: shorten code a bit
No functional change, just refactoring.
2023-02-24 08:55:27 +09:00
Yu Watanabe db43717e98 time-util: use usec_add() and usec_sub_unsigned()
And move the check with USEC_TIMESTAMP_FORMATTABLE_MAX at the end,
as usec_add() can handle overflow correctly.
2023-02-24 08:55:27 +09:00
Yu Watanabe f2ecfd8bc1 time-util: use result from startswith_no_case()
No functional change, just refactoring.
2023-02-24 08:55:27 +09:00
Yu Watanabe 804537bdc4 time-util: do not use strdupa()
The input string may come from command line, config files.
2023-02-24 08:55:27 +09:00
Yu Watanabe 17d1ebfc43 time-util: drop redundant else 2023-02-24 08:55:27 +09:00
Yu Watanabe dff3bddc54 time-util: add assertions 2023-02-24 08:55:27 +09:00
Yu Watanabe cf98b66d1a time-util: rename variables 2023-02-24 08:55:27 +09:00
Yu Watanabe e01a8fdd26 time-util: align string table 2023-02-24 08:55:27 +09:00
Yu Watanabe d227a42aad time-util: use DEFINE_STRING_TABLE_LOOKUP_TO_STRING() macro 2023-02-24 08:55:27 +09:00
Yu Watanabe 7464953f33 time-util: drop redundant space 2023-02-24 08:55:27 +09:00
Yu Watanabe 6b04af6072 time-util: drop unused definition of FORMAT_TIMESTAMP_WIDTH 2023-02-24 08:55:27 +09:00
Lennart Poettering dafb406383 shared: move cg_set_access() declaration to right header file
This function was moved from cgroup-util.c to cgroup-setup.c a while
back, but the prototype in the matching header files wasn't migrated.
Let's fix that.
2023-02-23 20:44:35 +00:00
Yu Watanabe e47c426b5c Merge pull request #26560 from yuwata/journal-send-fix-memleak-and-cleanups
sd-journal: several fixlets and cleanups for sd_journal_send()
2023-02-23 21:37:20 +09:00
Zbigniew Jędrzejewski-Szmek 20b569a4c6 Merge pull request #26563 from dtardon/fd-init
Initialize fds with -EBADF + drop one unneeded initialization
2023-02-23 11:43:09 +01:00
Zbigniew Jędrzejewski-Szmek a34180a22f Merge pull request #26556 from keszybz/list-timers-optimize-left
Do not say " left" on every timer in LEFT column
2023-02-23 11:37:48 +01:00
David Tardon 92651a7a2d tree-wide: initialize fds with -EBADF 2023-02-23 09:48:54 +01:00
Yu Watanabe de5cc016b5 io-util: drop double evaluation in IOVEC_INIT_STRING()
This also makes IOVEC_INIT_STRING() and IOVEC_MAKE_STRING() identical.
2023-02-23 15:09:59 +09:00
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
Zbigniew Jędrzejewski-Szmek d5e6f36c7a shared/format-table: optionally print timestamps without "left"
This just adds the base functionality and some unit tests.
With TABLE_TIMESTAMP_RELATIVE we print "5s ago" and "5s left",
with the new TABLE_TIMESTAMP_LEFT, we print "5s ago" but "5s".
This is more useful for cases where we generally only want to
print timestamps in the future.
2023-02-22 23:43:33 +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