Commit Graph
4426 Commits
Author SHA1 Message Date
Daan De Meyer ea79ac6f36 Assorted coverity fixes (#41406) 2026-03-29 21:02:55 +02:00
Zbigniew Jędrzejewski-Szmek ab3a2f375f sd-varlink: export sd_varlink_set_sentinel
I tried to implement a varlink service using sd-varlink, and
not being able to use the approach with sentinel is exteremely
painful. This is useful internally and likewise externally.
2026-03-29 20:32:15 +02:00
Luca Boccassi c34169e9d3 sd-bus: add asserts for rbuffer_size accumulation bounds
Coverity flags rbuffer_size += k as a potential overflow, but k is
always bounded by the iov size (which is the difference between the
allocated buffer and current rbuffer_size). Add asserts to make this
invariant explicit.

CID#1548044
CID#1548071

Follow-up for a7e3212d89
2026-03-28 20:09:40 +00:00
Luca Boccassi c8b53fcfd3 sd-event: add assert to help static analysis trace signal bounds
Coverity flags the signal_sources array access as a potential
out-of-bounds read because it cannot trace through the SIGNAL_VALID()
macro to know that ssi_signo < _NSIG. Add an explicit assert after
the runtime check to make the constraint visible to static analyzers.

CID#1548033

Follow-up for 7a64c5f23e
2026-03-28 19:56:31 +00:00
Michael Vogt 9f691ad3c0 varlink: comment that "more" flag IDL comment is API
External tools that use the systemd varlink ecosystem require
to know if a specific varlink method supports/requires the
"more" flag from the IDL. This is tracked upstream in
https://github.com/varlink/varlink.github.io/issues/26

As an intermediate step systemd adds the (very nice) comments
```
 # [Requires 'more' flag]
or
 # [Supports 'more' flag]
```
to the various methods.

This commit extends the comment around the code that adds the
comment to clarify that this should be considered API and that
the comment should not be changed as external tools (like e.g.
the varlink-http-bridge) rely on it.
2026-03-25 12:27:50 +01:00
Lennart Poettering 9eb207356c json-util: add json_dispatch_in6_addr() 2026-03-24 21:24:47 +01:00
Lennart Poettering 3839f5efec json-util: optionally accept string-based serialization for IPv4 addresses 2026-03-24 21:24:47 +01:00
Lennart Poettering e7a176fe46 Define options and verbs through "magic macros" (#40880)
This is an another alternative for #40656, based on @poettering's
suggestion to use an ELF section.

The output of --help is generated using format-table, but the details of
the formatting a bit off: different sections in the table (verbs, option
groups) are not aligned to the same column. Our current table formatting
doesn't make this easy. If somebody has an idea how to do this without
too much pain, please make suggestions.

Another thing that I didn't know how to do nicely, was to use the two
columns of separation. But maybe this doesn't matter. If we switch to
one column everywhere, I don't think people will care.

Example output:
```console
$ build/systemd-id128 -h | cat    
systemd-id128 [OPTIONS...] COMMAND

Generate and print 128-bit identifiers.

Commands:
  new                Generate a new ID
  machine-id         Print the ID of current machine
  boot-id            Print the ID of current boot
  invocation-id      Print the ID of current invocation
  var-partition-uuid Print the UUID for the /var/ partition
  show [NAME|UUID]   Print one or more UUIDs
  help               Show this help

Options:
  -h --help            Show this help
     --version         Show package version
     --no-pager        Do not start a pager
     --no-legend       Do not show headers and footers
     --json=FORMAT     Output inspection data in JSON (takes one of pretty,
                       short, off)
  -j                   Equivalent to --json=pretty (on TTY) or --json=short
                       (otherwise)
  -p --pretty          Generate samples of program code
  -P --value           Only print the value
  -a --app-specific=ID Generate app-specific IDs
  -u --uuid            Output in UUID format

See the systemd-id128(1) man page for details.
```

The output wraps automatically with terminal width. If the terminal is
extremely narrow, ellipsization occurs. I think this doesn't matter
and/or is actually a feature. Such narrow terminals mostly occur in
testing, so it doesn't matter what exactly we do, as long as it is
something somewhat reasonable.

Anyway, I think this is enough as PoC. Please compare this with the
previous approach. /cc @behrmann, @YHNdnzj, @poettering

The three binaries that are converted have options, verbs, optional
arguments, and options terminate option parsing, so most of the
functionality is there. One thing that I didn't implement that was
present in previous PRs is "namespaces", i.e. multiple parsers in the
same source file. I expect that we can handle this similarly to option
groups.
2026-03-23 22:17:05 +01:00
Frantisek Sumsal 924f5a3461 sd-varlink: gracefully reject arrays/maps with a null element
Follow-up for 799392286e.
2026-03-22 19:37:47 +01:00
Zbigniew Jędrzejewski-Szmek 57a1f1ab96 bus-error: fix typo 2026-03-22 16:52:22 +01:00
Zbigniew Jędrzejewski-Szmek 77549ac1c4 Stop disabling -Wattributes (#41174)
In one of the reviews one of the LLMs noticed that the pragma is set but
never unset, so it remains in effect for the rest of the translation
unit. From the comment, it's not clear how old those "old compilers"
were, so let's try if things work without this workaround.
2026-03-20 17:10:10 +01:00
Lennart Poettering 2c74a91cb8 sd-json: when parsing optionally insist top-level variant is object or array
Typically, the top-level JSON object has to be an object, in any json
document we parse, hence let's add a simple way to enforce that.

Make use of this in various places.

(Note, various other JSON parsers insist on this logic right from the
beginning, but I actually thinking making this insisting optional like
this patch does it is the cleaner approach)
2026-03-20 15:34:56 +01:00
Luca Boccassi 69c087bade test: skip D-Bus FD truncation test with dbus-daemon
dbus-daemon intentionally disconnects peers when FDs get
truncated. Detect it and skip it in that case, as the purpose
of the test is not to exercise the D-Bus implementation, but
our library.
When running with dbus-broker (Fedora, etc) we'll get full
coverage.

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

Follow-up for 744d589632
2026-03-20 15:25:26 +01:00
Zbigniew Jędrzejewski-Szmek a0eae2ab7b Stop disabling -Wattributes
In one of the reviews one of the LLMs noticed that the pragma is set but
never unset, so it remains in effect for the rest of the translation
unit. From the comment, it's not clear how old those "old compilers" were,
so let's try if things work without this workaround.
2026-03-19 11:46:30 +01:00
seaeunlee 59aed18d69 hostname: add API for getting custom fields from machine-info 2026-03-18 20:47:00 +00:00
Yu Watanabe a62cd5a153 sd-device: refuse spurious properties
Properties are set through uevent, udev rules, or program output by IMPORT.
They may contain spurious characters and udev database parsers may be confused.
Let's refuse spurious properties.
2026-03-10 06:32:30 +09:00
Yu Watanabe 460b580810 sd-device: do not register a property with an empty string
The function device_add_property() handles property with NULL value as
removing the property. Let's also make an empty value is handled as
same.

Note, ENV{hoge}=="" udev property handles both NULL value and an empty string
in the same way.
2026-03-10 03:33:23 +09:00
Yu Watanabe d3df01c4eb sd-device: use device_add_property() at one more place 2026-03-10 03:05:15 +09:00
Lennart Poettering dfb1fa0197 sd-varlink: pin error message while we invoke a reply callback
Let's make sure the parameters/error pointers into the message remain
valid as long as the reply callback is running, even if the reply
otherwise resets the pending message.
2026-03-06 14:51:35 +01:00
Yu Watanabe 8903e6b5f7 tree-wide: suppress misc-use-internal-linkage warnings
Suppress warnings like the following from clang tidy:
```
../src/boot/addon.c:11:19: error: function 'efi_main' can be made static to enforce internal linkage [misc-use-internal-linkage,-warnings-as-errors]
   11 | EFIAPI EFI_STATUS efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *system_table);
      |                   ^
```

Some warnings are suppressed simply by setting comments to ignore the warning,
some are by making global variables static, or include a suitable header.
2026-03-05 20:23:24 +01:00
Frantisek Sumsal 90f5d2a202 tree-wide: various fixlets suggested by Coccinelle 2026-03-05 10:27:58 +01:00
Frantisek Sumsal a8335fb91f tree-wide: use typed SD_JSON_BUILD_PAIR_* macros more 2026-03-05 10:27:58 +01:00
Mike Yuan f1f38e2fc1 sd-journal/catalog: make catalog_file_dirs static 2026-03-04 14:32:17 +01:00
Yu Watanabe 43116c5662 tree-wide: use DIGITS and friends 2026-03-03 22:18:26 +01:00
Yu Watanabe 4b4eba1666 tree-wide: use _contains() rather than _get()/_find() 2026-03-02 23:10:22 +09:00
Mike Yuan 8df624bfdd sd-varlink: add missing space 2026-02-28 12:01:06 +01:00
Mike Yuan 4e6e3b8707 sd-json: fix off-by-one issue when updating parent for array elements
Follow-up for 8525bb369a
2026-02-26 14:23:12 +01:00
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