Commit Graph
4323 Commits
Author SHA1 Message Date
David Tardon 94446e4f5a tree-wide: flatten nested error checks 2025-12-10 18:59:44 +09:00
Zbigniew Jędrzejewski-Szmek 9454927c76 sd-netlink: read error message for NFNL_MSG_BATCH_BEGIN (#39967)
Before:
```
$ unshare --user --map-users=0:$(id -u):1 --map-groups=0:$(id -g):1 build/test-firewall-util
/* test_v6 */
src/test/test-firewall-util.c:34: Assertion failed: "r = fw_nftables_add_masquerade(nfnl, true, AF_INET6, &u1, 128)" failed with unexpected error: -110/ETIMEDOUT
Aborted (core dumped)
```

After:
```
$ unshare --user --map-users=0:$(id -u):1 --map-groups=0:$(id -g):1 /var/build/test-firewall-util
/* test_v6 */
test-firewall-util: Failed to add IPv6 masquerade, skipping tests: Operation not permitted
/* test_v4 */
test-firewall-util: Failed to add IPv4 masquerade, skipping tests: Operation not permitted
```
2025-12-05 12:12:03 +01:00
Zbigniew Jędrzejewski-Szmek d9e894ef72 Fix systemctl start --verbose off-by-one logs (#39927) 2025-12-05 11:09:14 +01:00
Yu Watanabe 691d63dbdd sd-netlink: also read the reply for NFNL_MSG_BATCH_BEGIN message
When we send a batch of nfnl messages, but e.g. without sufficient
privilege, the kernel may only return an error message for
NFNL_MSG_BATCH_BEGIN and ignore all later messages.
So, we need to read the response for the NFNL_MSG_BATCH_BEGIN,
and if it is an error ignore the replies for the rest.
2025-12-04 08:24:28 +09:00
Yu Watanabe ea97ca9a06 sd-netlink: drop unused ret_messages argument
This is not only unused, the kernel never provide any meaningful reply
for batch message. Let's drop it.
2025-12-04 08:24:28 +09:00
Yu Watanabe 991703009e sd-netlink: introduce sd_netlink_ignore_serial()
When we send a message with NLM_F_ACK, but if later we are not
interested in the reply and do not want to call sd_netlink_read(),
the reply will be stored in the rqueue forever.

Let's introduce a way to ignore received message without waiting reply.
2025-12-04 08:24:28 +09:00
Yu Watanabe 32682ba02d sd-netlink: introduce netlink_now() and move timespan_to_timestamp()
When sd-event is attached to the sd-netlink object, use the timestamp of
the current event, otherwise call now().

This mostly change nothing. Preparation for later change.
2025-12-04 08:24:28 +09:00
Luca Boccassi a3b6ad69ab cgroup-util: fix cg_pid_get_user_unit() to actually query user units
Refactor switched to the wrong implementation for this inline,
breaking querying for user units

Fixes https://github.com/systemd/systemd/issues/39949

Follow-up for 015025cba2
2025-12-02 10:50:41 +09:00
Zbigniew Jędrzejewski-Szmek 21eb636aaa sd-notify: print a debug message when sd_notify() succeds
… and also when it fails, in the few cases where this wasn't done already.
When I was debugging https://github.com/systemd/systemd/issues/39048, it
was quite confusing that we print copious information about D-Bus messages
and all other steps we're undertaking, but nothing about the sd-notify
messages which are much more important. Add some debug messages for the
cases where we didn't print anything. (The case where $NOTIFY_SOCKET is
not set in left unchanged. The variable is often left unset and we don't
need to spam logs in that trivial case.)
2025-11-27 20:03:00 +01:00
Daan De Meyer 6a9f0641cd tree-wide: Fix declaration/definition parameter name mismatches 2025-11-26 19:02:31 +09:00
Yu Watanabe caf7cb2737 SD_JSON_BUILD_PAIR() conversions with coccinelle script (#39858) 2025-11-26 16:35:35 +09:00
Daan De Meyer c421392811 fsprg: Drop const from gcry_mpi_t arguments
gcry_mpi_t is defined as "typedef struct gcry_mpi *gcry_mpi_t;".
When const is applied to this type, it resolves to
"struct gcry_mpi *const" instead of what we expect ("const struct gcry_mpi *").

So we end up with a const pointer to a mutable object instead of a mutable
pointer to a const object. Since the pointer passed to the function
is copied regardless, making it const has zero benefit.

You'd think we could instead stop using gcry_mpi_t and replace it with
"const struct gcry_mpi *", except that gcrypt leaked this mess into its
api, so it expects const pointers to mutable objects as well, which means
we can't take pointers to const objects as arguments, as we'd discard the qualifier
when calling a gcrypt function.

To avoid confusion, let's drop the const qualifiers from the gcry_mpi_t arguments.
2025-11-26 16:22:32 +09:00
Daan De Meyer 9a6a8f35eb tree-wide: Small fixes for various clang-tidy warnings 2025-11-26 16:22:00 +09:00
Frantisek Sumsal ade882f16f sd-journal: fix a copy-paste error
Dereference the Directory pointer in the debug message instead of the
(probably already freed) JournalFile one.
2025-11-26 00:36:03 +01:00
Daan De Meyer 0bac1ed242 tree-wide: Fix constness issues with newer glibc
Latest glibc uses _Generic to have strstr() and other functions return
const char* or char* based on whether the input is a const char* or a
char*. This causes build failures as we previously always expected a char*.

Let's fix the compilation failures and add our own macros similar to glibc's
to have string functions that return a mutable or const pointer depending on
the input.
2025-11-25 20:49:39 +01:00
Jelle van der Waa c12966c14f treewide: prefer using SD_JSON_BUILD_PAIR_* over SD_JSON_BUILD_PAIR()
Include a coccinelle script that patches this automatically.
2025-11-24 21:05:10 +01:00
Lennart Poettering a08f2ea02d process-util: also disable dlopen() in safe_fork() 2025-11-24 11:56:47 +01:00
Daan De Meyer 87fbd33372 clang-tidy: Fix all remaining misc-include-cleaner violations
- Remove unused includes
- Add common false positive headers to misc-include-cleaner.IgnoreHeaders
- Add IWYU pragma keep for uncommon false positive headers
2025-11-22 10:19:41 +01:00
Daan De Meyer cf063b8a1c sd-bus: Exit event loop with error code instead of EXIT_FAILURE
Instead of failing the event loop with a generic EXIT_FAILURE
error code when exit-on-disconnect is used, let's propagate the
error code instead of swallowing it.

Whereas previously sd_event_loop() would always fail with exit code
'1' when exit-on-disconnect is used with an sd-bus instance registered
with the event loop that encounters a failure, now we'll correctly
propagate the error to sd_event_loop() that caused sd-bus to fail and
exit the event loop. Additionally, the error is now also properly
propagated to outstanding reply callbacks for async dbus calls started
with sd_bus_call_async() and friends, whereas before we always used
ETIMEDOUT for these calls which is extremely confusing for users.

Why is this confusing? We always start sd-bus instances asynchronously,
in other words, sd_bus_start() will not actually wait until the bus instance
is connected, but it'll happen in the background, either driven by the first
sd_bus_call() when there is no event loop or by sd-event when there is an
event loop attached to the sd-bus instance. Assuming an event loop is attached,
when we fail to connect to the bus, the sd-bus instance will close down and the
first async method call we queued will fail with ETIMEDOUT. Nowhere in this process
do we inform the user that we failed to connect to the bus because of e.g. a permission
error, except for a debug log message.

By propagating the error to sd_event_exit() if exit-on-disconnect is enabled
and always propagating it to outstanding reply callbacks, debugging failures
becomes much easier as users will now get the actual error code causing the
bus instance to close down instead of ETIMEDOUT and 1 respectively.
2025-11-21 09:57:51 +01:00
Yu Watanabe b525a72f7b cgroup-util: drop cgroup v1 support from cg_pid_get_path()
We have dropped cgroup v1 support in v258. Let's drop legacy code.
Then, we can drop 'controller' argument from cg_pid_get_path() and
cg_pidref_get_path().
2025-11-17 21:30:29 +09:00
Yu Watanabe 4365351b93 cgroup-util: introduce cg_is_available() and check it in tests
Now most of our code does not support cgroup v1. Let's skip test cases
if we are running on cgroup v1.
2025-11-17 21:29:51 +09:00
Yu Watanabe a112c7646b tree-wide: swap arguments for streq()
We usually set a variable first, then constant.
2025-11-16 14:01:56 +09:00
Yu Watanabe de8ea7e219 test: add missing assertion
Follow-up for 5a5cb6ba50.
Fixes CID#1643217.
2025-11-16 05:51:22 +09:00
Yu Watanabe 8e4ef4a18c sd-event: do not ignore result of callbacks
Follow-up for 4c8b6d636c and
6aff6d3ffc.
Fixes CID#1643218 and friends.
2025-11-16 05:44:35 +09:00
Yu Watanabe fe9bccb2b7 Make new sd-path configuration search functionality generic (#39684)
Reverts systemd/systemd#38680

After taking a closer look I'm not convinced by the approach, see below.

First of all, all other SD_PATH_SEARCH_* are either somewhat generic,
i.e. encode the common prefix for configurations, binaries, etc., or are
subdirectories under systemd/ hence in our own "domain". The
tmpfiles/sysctl/binfmt we don't prefix with "systemd" precisely because
the concept is generic and there're actually other impls of them. A
specific SD_PATH_SEARCH_SYSCTL doesn't fit into our existing scheme.
Instead something along the lines of "SEARCH_SYSTEM_CONFIGURATION" shall
be introduced, and consumers will just suffix
sysctl.d/tmpfiles.d/binfmt.d for the final result.

And secondly, I don't grok why systemd-sysctl now unnecessarily calls
into sd-path to obtain the fixed search path. None of our other tools do
that.

-----------

An alternate approach, SD_PATH_SYSTEM_SEARCH_CONFIGURATION, which does
exactly above, will be introduced instead. It provides a universal
interface for querying any system config with our idiomatic
/etc/:/run/:/usr/local/lib/:/usr/lib/ hierarchy.
2025-11-15 10:09:19 +09:00
Yu Watanabe 08d207ba73 musl: introduce two wrappers (#39700) 2025-11-15 04:18:48 +09:00
Yu Watanabe 1569b1e25f tree-wide: use SD_JSON_BUILD_PAIR_* macros if possible (#39732) 2025-11-15 04:02:51 +09:00
Yu Watanabe bb7d5e52a2 musl: test-bus-error: drop ._need_free flag checks
Its value depends on how strerror_r() implemented, and the
implementations of the function in glibc and musl are actually
different. Let's drop the checks.
2025-11-15 03:39:35 +09:00
Jelle van der Waa 8ef5e56f97 sd-json: prefer using SD_JSON_BUILD_PAIR_UNSIGNED
No functional change, just refactoring.
2025-11-14 15:19:54 +01:00
Daan De Meyer 6aff6d3ffc sd-event: Move SOURCE_POST check into mark_post_sources_pending()
Rename to maybe_mark_post_sources_pending() as well to match the new
behavior.

Follow up for 4c8b6d636c
2025-11-14 15:18:33 +01:00
Daan De Meyer c71a8e68ce sd-event: Add comment in event_source_offline() for memory pressure
Follow up for d0ddb0aafb
2025-11-14 15:18:33 +01:00
Daan De Meyer a3dd54c097 sd-event: Make sure iterations of defer and exit sources are updated
Defer and exit event sources are marked pending once when they are added
and never again afterwards. This means their pending_iteration is never
incremented after they are initially added, which breaks fairness among
event sources with equal priority which depend on the pending_iteration
variable getting updated in source_set_pending(). To fix this, let's assign
iterations for defer and exit sources in source_dispatch() instead so that
those get their pending_iteration updated as well.
2025-11-14 11:38:59 +01:00
Daan De Meyer 5a5cb6ba50 sd-event: Add exit-on-idle support
Sometimes it's hard to assign responsibility to a specific event source
for exiting when there's no more work to be done. So let's add exit-on-idle
support where we exit when there are no more event sources.
2025-11-14 11:38:56 +01:00
Daan De Meyer c11e1001db sd-event: Allow passing WNOWAIT to sd_event_add_child()
This allows doing the reaping outside of the callback, we'll use this
when adding fibers in a later commit.
2025-11-14 10:34:32 +01:00
Daan De Meyer 0a79791d0a sd-event: Drop faulty shortcut
We can't take this shortcut, as we might have to drop the
EPOLLONESHOT flag for some event sources, so drop the shortcut.
2025-11-14 10:34:32 +01:00
Daan De Meyer d0ddb0aafb sd-event: Only register memory presure if write buffer size is zero
As documented in sd_event_add_memory_pressure(), we can only add
the memory pressure fd to epoll once we've written the watch string,
so make sure we don't register the memory pressure in
event_source_online() until we've written the watch string.
2025-11-14 10:34:32 +01:00
Daan De Meyer 4c8b6d636c sd-event: Mark post sources as pending after dispatching
More post event sources might get added during dispatching, we want
to make sure those become pending as well if we're dispatching a non-post
event source.
2025-11-14 10:34:30 +01:00
Daan De Meyer 59a81bbb80 sd-bus: Pass --user and --quiet to systemd-stdio-bridge if local
If we're switching users but not entering a container, then we can
assume that new switches for systemd-stdio-bridge are available, so
make use of them in that case.
2025-11-13 14:45:51 +01:00
Zbigniew Jędrzejewski-Szmek dc04a884e0 systemd-path: add 'system-search-configuration'
This provides functionality to replace what was provided by the preceding
revert:

  $ build/systemd-path system-search-configuration --suffix=sysctl.d
  /etc/sysctl.d:/run/sysctl.d:/usr/local/lib/sysctl.d:/usr/lib/sysctl.d

The result is identical, but more generic, since by changing suffix we can also
get the answer for sysusers.d, tmpfiles.d, and any other of the directories
which follow the same general rule.
2025-11-13 14:11:11 +01:00
Yu Watanabe d278d5bc3d sd-journal: fix relative path handling (#38681)
Fixes #38667.
2025-11-13 05:12:00 +09:00
Yu Watanabe 733c5c98ad sd-journal: resolve paths passed to sd_journal_open_files() and friends
Fixes #38667.
2025-11-12 15:18:40 +01:00
Yu Watanabe 09811f99f4 sd-journal: use -EBADF for invalidated file descriptor 2025-11-12 15:18:40 +01:00
Daan De Meyer 13027e040a test-bus-chat: Migrate to TEST() and new assertion macros
- Also contains various other small cleanups
2025-11-12 14:24:14 +01:00
Daan De Meyer e59ed77e13 test-bus-watch-bind: Migrate to new assertion macros 2025-11-12 14:24:14 +01:00
Daan De Meyer 0fd7280fbc test-bus-server: Migrate to new assertion macros 2025-11-12 14:24:14 +01:00
Daan De Meyer 4fd7bec2c9 test-bus-peersockaddr: Migrate to new assertion macros 2025-11-12 14:24:12 +01:00
Daan De Meyer 491706368b test-bus-objects: Migrate to new assertion macros 2025-11-12 14:20:24 +01:00
Daan De Meyer 6b136bcd02 test-event: Migrate to new assertion macros 2025-11-12 14:20:24 +01:00
Yu Watanabe 6b656a5b40 test-bus-error: use STRERROR() at several more places 2025-11-12 14:17:44 +08:00
Mike Yuan 14a9fb7a8e Revert "sd_path_lookup*() add new type SD_PATH_SEARCH_SYSCTL" 2025-11-12 01:32:11 +01:00