Commit Graph
4399 Commits
Author SHA1 Message Date
Luca Boccassi a851c5118b test: avoid hanging forever waiting for udev if not a booted system
test_sd_device_enumerator_filter_subsystem hangs forever in OBS builds,
as it waits for the udev queue to be drained. But this is not a booted
system, with systemd and udev, so nothing will do that.
Skip the test in that case.
2026-02-25 04:53:20 +09:00
Lennart Poettering a69dffbf4f sd-varlink: add a bit of debug logging indicating when exit-on-idle triggers 2026-02-24 17:11:54 +01:00
Lennart Poettering a0276f6e12 sd-varlink: use correct error variable 2026-02-24 17:09:33 +01:00
Lennart Poettering 332ecf40f2 sd-netlink: pin reply slot while we execute callback
The callback might drop the last ref to the slot object, and we still
want to access it. Hence do what we usually do in these cases: keep an
extra reference while processing the callback.
2026-02-24 17:09:33 +01:00
Yu Watanabe e0a2369dd1 sd-device: do not try to remove previous tag indexes
The removed code in device_tag_index() in fact does nothing,
as sd_device.all_tags is never cleared. Moreover, not only the code
is meaningless, but it is theoretically/logically wrong, as the symlinks
in /run/udev/tags/ should be 'sticky', hence we should even not try to
remove them.
2026-02-23 05:46:42 +09:00
Yu Watanabe fc03d200c7 sd-device: do not clear sd_device.all_tags even on TAG="hoge"
The current tag concept has been introduced by
e77b146f82 (v247) to make symlinks in
/run/udev/tags/ are 'sticky'.

However, when TAG= (rather than TAG+=) is specified, then the tags
assigned in the previous events were also cleared.
This fixes the issue and now symlinks in /run/udev/tags/ are really
'sticky'.

Fortunately, TAG= is mostly unused. So, the issue should not affect
and the fix should not change anything on almost all systems.
2026-02-23 05:46:42 +09:00
Yu Watanabe 1c867dc71a sd-device: move copy_all_tags() from udev
No functional change, preparation for the next commit.
2026-02-23 05:46:42 +09:00
Yu Watanabe b65467b647 sd-device: shorten code a bit 2026-02-23 05:46:42 +09:00
Lennart Poettering a98fc72e29 json: add json_variant_compare() helper for comparint two json variants by order 2026-02-20 08:15:29 +01:00
Daan De Meyer e38fac0cc5 sd-bus: Make sure we can connect to user machines as well (#40698)
Don't unconditionally look into /run/systemd/machines. If we're a
connected to a session bus, look at the machines for the current user
instead.
2026-02-17 19:13:40 +01:00
Daan De Meyer 6119252f5a sd-bus: Don't fork unnecessarily to connect to container
Let's check if we're already in the right namespaces and call connect()
directly if that's the case. This can easily happen when the machine is
specified as .host or so.
2026-02-17 17:52:20 +01:00
Daan De Meyer a12c5bf4f5 sd-bus: Make sure we can connect to user machines as well
Don't unconditionally look into /run/systemd/machines. If we're a
connected to a session bus, look at the machines for the current user
instead.
2026-02-17 17:52:20 +01:00
Yu Watanabe b96f417ea6 xaccess: Rework from boolean into a list of tags (#40645)
Fixes: #40634
2026-02-18 01:24:59 +09:00
Mike Yuan b52a202b61 sd-json: fix doubled space 2026-02-17 16:26:36 +01:00
Alessandro Astone 1f7f2bc610 xaccess: Rework from boolean into a list of tags
XDG_SESSION_EXTRA_DEVICE_ACCESS will now take a colon-separated list of
identifiers. For every identifier $ID, the session is granted access to all
devices tagged as "xaccess-$ID" in udev.

Fixes: #40634
2026-02-17 15:27:24 +01:00
Yu Watanabe 2e8cfb7cef sd-bus: use bus_error_message() at several more places
For CID#1645014, CID#1645016, and CID#1645017.
2026-02-17 17:00:42 +09:00
Mike Yuan b166461f82 varlink-serialize: deserialize to correct event priority 2026-02-16 09:44:58 +01:00
Mike Yuan eeead6e177 sd-varlink: fail if a method call wasn't replied to and the callback didn't store it 2026-02-16 09:44:56 +01:00
Mike Yuan 1f9ba6ba73 sd-varlink: take output queue into account in sd_varlink_flush() 2026-02-16 09:44:56 +01:00
Mike Yuan 86ac1083c9 sd-varlink: _reset_fds() should reset fds for the reply being constructed
... (aka pushed_fds), not what's already enqueued to be sent out.
2026-02-16 09:44:56 +01:00
Mike Yuan 959f6923e5 sd-varlink: use free_and_replace at one more place 2026-02-16 09:44:56 +01:00
Mike Yuan 9257690859 sd-varlink: replace manual move_fd() with FORK_PACK_FDS + FORK_CLOEXEC_OFF
Note that this actually matters: we might otherwise clobber
the logging fds reopened when rearranging fd '3'.

While at it, avoid logging from library functions.
2026-02-16 09:44:56 +01:00
Mike Yuan 122bde2c45 sd-varlink: also validate peer ucred for SD_VARLINK_SERVER_MYSELF_ONLY 2026-02-16 09:44:55 +01:00
Mike Yuan 3482e4dd70 sd-varlink: log about client uid that hit connection limit 2026-02-16 09:44:55 +01:00
Mike Yuan e2fb041564 sd-varlink: shorten the code a bit 2026-02-16 09:44:55 +01:00
Mike Yuan 05d1cfee90 sd-json: unify JSON_BUILD_PAIR_IN?_ADDR_*
This also swaps family and address params for
plain JSON_BUILD(_PAIR)_IN_ADDR, aligning with
_WITH_STRING flavors.
2026-02-16 09:44:54 +01:00
Mike Yuan 926ae62a27 json-util: sort includes 2026-02-16 09:44:53 +01:00
Mike Yuan daeb7dd390 sd-json: use FOREACH_ARRAY more 2026-02-16 09:44:53 +01:00
Yu Watanabe c33b112cac sd-varlink: fix typo
Follow-up for c0696f1f5d.
2026-02-16 14:32:15 +09:00
Luca Boccassi 5b822977c2 sd-json: also skip assert_cc in VS Code parser
For some reason the VS Code parser thinks sd_json_variant is still 48 bytes,
so skip the assert when running in that parser too

Follow-up for 337712e777
2026-02-13 19:34:45 +00:00
Luca Boccassi 987f0fb062 sd-json: update comment regarding struct size
The assert at the bottom was updated when the size changed, but
the comment wasn't:

assert_cc(sizeof(sd_json_variant) == 40U);

Follow-up for 337712e777
2026-02-13 19:33:21 +00:00
Michael Vogt b5f8725989 varlinkctl: add pluggable protocol support to sd-varlink
When sd_varlink_connect_url() gets an unknown URL we now
check if there is a `$LIBEXECDIR/varlink-bridges/$scheme`
binary and execute it (with the url as the first arguments).

This makes varlink more flexible as it provides a way to
dynamically add "bridges" in LIBEXECDIR/varlink-bridges/. This is
conceptually similar to the libvarlink `varlink --bridge` command
and allows to e.g. call varlink over http{,s} via e.g. the new
varlink-http-bridge.

With a running varlink-http-bridge [0] one can do:
```console
$ varlinkctl call http://localhost:8080/ws/sockets/io.systemd.Hostname \
    io.systemd.Hostname.Describe {}
{
        "Hostname" : "top",
...
```

Closes: https://github.com/systemd/systemd/issues/40640

[0] https://github.com/mvo5/varlink-http-bridge/pull/1
2026-02-13 19:07:20 +01:00
Daan De Meyer 71de0a22ff core/service: support credentials refreshing on reload (#40093)
Closes https://github.com/systemd/systemd/issues/21099
Closes https://github.com/systemd/systemd/issues/35227
2026-02-13 10:21:44 +01:00
Daan De Meyer c0696f1f5d sd-varlink: Introduce varlink_set_sentinel()
Streaming methods which are not used as a continuous subscription but
instead only send a series of objects all end up with the same workaround
to be able to figure out when to send sd_varlink_reply() or sd_varlink_notify().
Let's generalize this in sd-varlink itself.

Let's introduce the concept of a sentinel, which is a reply that will be sent
by sd-varlink if no other reply was queued by a method callback. The sentinel
is configured with varlink_set_sentinel(). If a sentinel is configured,
sd_varlink_reply() can be used more than once in streaming methods to queue
multiple values to stream to the client. The last queued reply is not sent
until the callback finishes. When the callback finishes, the last reply is
sent without "continues: more". If no reply was queued, the sentinel is sent.

This always using only sd_varlink_reply() in such streaming methods and
leaves sd_varlink_notify() available solely for continuous subscription
streaming methods, where we never use sd_varlink_reply() and instead disconnect
when the server exits.
2026-02-11 14:24:03 +01:00
Daan De Meyer 22f1d5a625 sd-varlink: Move code around
Preparation for next commits
2026-02-11 14:24:03 +01:00
Yaping Li a0f2d74cba Metrics: Refactor to drop usage of strv
This addresses Daan's feedback on #39202
2026-02-11 12:43:28 +01:00
Mike Yuan f9e0a62392 sd-daemon: escape special characters in notification logging text
Follow-up for 21eb636aaa

Our sd_notify() protocol uses newline as separator, which
is not suitable for direct logging.
2026-02-10 21:53:39 +01:00
Mike Yuan 8b7e98f183 journal-send: check if $LOG_NAMESPACE denotes our /run/systemd/journal/ is already namespaced properly 2026-02-09 09:41:47 +01:00
Alessandro Astone 87840e144b login: Add XDG_SESSION_EXTRA_DEVICE_ACCESS variable for additional access
A session created with XDG_SESSION_EXTRA_DEVICE_ACCESS will be granted
additional powers.
Exactly which powers are granted is going to be defined by udevd.
2026-02-06 16:20:18 +01:00
Mike Yuan 5817c73391 mountpoint-util: rework name_to_handle_at() unique mount id handling
name_to_handle_at_try_unique_mntid_fid() in its current form is
ill-designed for various reasons:

* AT_HANDLE_FID requires file system support, while unique mount id
  is a VFS concept hence is always available if supported. Hence
  the fallback for AT_HANDLE_MNT_ID_UNIQUE should be independent
  of fid.
* The request for AT_HANDLE_MNT_ID_UNIQUE can be identified via
  specifying ret_unique_mnt_id, no need for opening up the control
  to caller (and currently the function simply doesn't handle
  mismatch between ret params and flags).
* The caller cannot realistically differentiate whether the returned
  mount id is actually unique.
* The path_get_unique_mnt_id() fallback did not handle AT_SYMLINK_FOLLOW.

Let's instead move the statx() fallback into name_to_handle_at_loop()
directly, and revamp interaction of ret_mnt_id/ret_unique_mnt_id:
if both are set, it indicates that the caller can handle both, hence
set what we have and return 0/1 for whether we managed to acquire
the unique one.

The !ret_handle && ret_mnt_id logic is removed. Let's not rely on
undocumented bizaare behavior and it's unused anyways.
path_get_mnt_id_at() exists for a reason...
2026-02-05 14:14:40 +01:00
gvenugo3 cf27c70d70 networkd-json: add human-readable address strings for IP addresses
Add JSON_BUILD_PAIR_IN_ADDR_WITH_STRING, JSON_BUILD_PAIR_IN6_ADDR_WITH_STRING,
and JSON_BUILD_PAIR_IN4_ADDR_WITH_STRING macros (plus _NON_NULL variants) that
emit both the binary address array and a human-readable string representation.

For example, an address field now emits both:
  "Address": [192, 168, 1, 1]
  "AddressString": "192.168.1.1"

This improves usability of the JSON/Varlink output for debugging and tooling
that consumes networkd state.

Updated networkd-json.c to use these new macros for addresses, neighbors,
nexthops, routes, routing policy rules, DNS servers, NTP servers, SIP servers,
domains, DHCPv6 prefixes, and link-local addresses.

Also updated the Varlink interface definitions to include the new string fields.
2026-02-04 10:34:30 +01:00
Yu Watanabe 65b50ae2c8 sd-bus: do not log in higher than LOG_DEBUG from library
Follow-up for 6c8de404c9.

This also adds full stop to the log message, and make "vs" followed by
dot for consistency to other messages.
2026-02-03 16:49:46 +09:00
Mike Yuan c49c8331b9 sd-bus/bus-message: more prudently verify it's SCM_RIGHTS that got truncated
Follow-up for 6c8de404c9

As discussed in
https://github.com/systemd/systemd/pull/40089#issuecomment-3672063388,
if any other control msg got truncated it's a genuine error, and
we should reject the message as a whole.
2026-01-28 03:34:25 +01:00
Mike Yuan f452c324e7 sd-bus/bus-socket: reinstate MSG_TRUNC handling in bus_socket_read_message()
We switched away from recvmsg_safe() in order to gracefully
handle MSG_CTRUNC. But MSG_TRUNC really shouldn't happen.

While at it, do not use RET_NERRNO with ssize_t.
2026-01-28 03:34:25 +01:00
Mike Yuan 43e08aea6e sd-bus/bus-socket: restore recvmsg_safe() during auth
At auth stage we reject any fds, hence either way the connection
would fail. Let's play it safe and check for MSG_(C)TRUNC still.
2026-01-28 03:07:01 +01:00
Zbigniew Jędrzejewski-Szmek 69d130aac5 preparations for installer PR (#40446)
As suggested by @keszybz the generic preparatory work split out of
#38764
2026-01-27 15:04:47 +01:00
Allison Karlitskaya 744d589632 sd-bus: add test cases for truncated fds
We add some test cases for the previous commits: first (with Claude's
help) we exercise the message creation API internally by passing it
various combinations of incorrect fds with the might_be_truncated flag
set to true or false.

Then we try more of a "real world" test by lowering our fd limit and
sending ourselves a message via the bus and making sure that we
successfully receive a message that has had at least some of its fds
truncated.
2026-01-26 16:07:26 +01:00
Allison Karlitskaya 6c8de404c9 sd-bus: allow receiving messages with MSG_CTRUNC set
In the event that we can't receive all of the fds from the message
(which can happen for a number of reasons including LSM denials or
hitting the fd limit of the process) the kernel will set the MSG_CTRUNC
flag.  Through our use of recvmsg_safe() we've been treating this as a
fatal error, which will result in dropping the connection.

Let's dial that back a bit: we can receive the message, but when the
user attempts to access the missing fds via sd_bus_message_read_basic()
we can return the (existing) error code of -EBADMSG to indicate that the
fd is missing.

We can do this by using recvmsg() directly, and relaxing some of the
checks on message creation: when (and only when) we have received
MSG_CTRUNC we allow a smaller than expected (per the header) number of
fds to be present.  The error check in sd_bus_message_read_basic() was
already there so we don't need to do anything about that.

This puts the receiver of the message into a difficult situation: you
can call sd_bus_message_read_basic() as often as you want but as long as
it keeps returning -EBADMSG it won't progress through the message and
you won't be able to close whatever container you're in.  That means
that the user will probably need to abandon processing the message
anyway.  So why not just drop the message up front?  This approach is
more likely to yield a useful error message, which will be invaluable
for people trying to track down problems caused by LSM denials.

Fixes #34688
2026-01-26 16:07:23 +01:00
Lennart Poettering 17ade5b2af sd-id128-util: allow XAT_FDROOT pass through in id128_get_machine_at() 2026-01-25 20:51:50 +01:00
Mike Yuan cc94dca5bc sd-event: use FOREACH_ARRAY 2026-01-24 18:51:21 +01:00