Commit Graph
2940 Commits
Author SHA1 Message Date
Luca Boccassi 54cd2d6869 sd-bus: add comment and test in sd_bus_path_decode() for empty string
3970	        e = object_path_startswith(path, prefix);
(gdb) p path
$1 = 0x55c5a166f768 "/org/freedesktop/portable1/image"
(gdb) p prefix
$2 = 0x55c59ffc2928 "/org/freedesktop/portable1/image"
(gdb) p e
$1 = 0x5581a1675788 ""

This can be a bit confusing in certain cases, so add a comment and a
test to make the behaviour clearer and explicit.
2022-05-21 03:44:09 +09:00
Daan De Meyer dcb4e45ad8 sd-bus: Fix introspect memory leak
We have to free the contents of the set on top of the set itself.

Fixes #23443.
2022-05-20 14:53:28 +09:00
Mike Gilbert 260c0a80ac meson: add 'devel' install_tag to libsystemd.pc and libudev.pc 2022-05-14 11:59:13 -04:00
Yu Watanabe fc0cbed2db test-sd-device: skip gpio subsystem
There exist /sys/class/gpio and /sys/bus/gpio, and both have gpiochip%N
device. However, these point to different devpaths.
2022-05-13 02:51:00 +09:00
Yu Watanabe 4d38294baf sd-device: always translate sysname to sysfs filename
Previously, in sd_device_new_from_subsystem_sysname(), '/' in sysname
was replaced '!' for several limited subsystems. This was based on a wrong
assumption that no sysname in e.g. driver subsystem does not contain '!'.
And the assumption is actually wrong, and trigger issue #23327.

In device_set_sysname_and_sysnum() we unconditionally replace '!' in the
filename. Hence, the translation in sd_device_new_from_subsystem_sysname()
must be also done unconditionally.

Fixes #23327.
2022-05-13 02:51:00 +09:00
Zbigniew Jędrzejewski-Szmek c4f883b78e fuzzers: ignore size limits when compiled standalone
This way we can still call fuzzers on old samples, but oss-fuzz will not waste
its and our time finding overly large inputs.
2022-05-12 14:57:07 +02:00
Yu WatanabeandZbigniew Jędrzejewski-Szmek 7593691aad fuzzers: add input size limits, always configure limits in two ways
Without the size limits, oss-fuzz creates huge samples that time out. Usually
this is because some of our code has bad algorithmic complexity. For data like
configuration samples we don't need to care about this: non-rogue configs are
rarely more than a few items, and a bit of a slowdown with a few hundred items
is acceptable. This wouldn't be OK for processing of untrusted data though.

We need to set the limit in two ways: through .options and in the code. The
first because it nicely allows libFuzzer to avoid wasting time, and the second
because fuzzers like hongfuzz and afl don't support .options.

While at it, let's fix an off-by-one (65535 is the largest offset for a
power-of-two size, but we're checking the size here).

Co-authored-by: Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
2022-05-12 13:31:11 +02:00
Yu Watanabe b692ad36b9 sd-device-enumerator: fix inverted return value of match_initialized()
Fixes a bug introduced by d8b50e5df7.

Fixes https://github.com/systemd/systemd/pull/22662#issuecomment-1124163773.
Fixes RHBZ#2083374 (https://bugzilla.redhat.com/show_bug.cgi?id=2083374).
2022-05-12 09:31:23 +02:00
Lennart Poettering 3bf175f076 tests: avoid (struct sockaddr*) casts
We prefer using using union sockaddr_union instead of casting sockaddr
to the correct types.

Coding style, nothing else.

Follow-up for 0dd5ec58fa.
2022-05-09 13:56:39 +02:00
Daan De Meyer 5517607ad7 journal: Make journal_default_metrics() static
Only caller resides in the same file as were it's defined so no
need to have it be public.
2022-05-05 16:32:24 +02:00
Daan De Meyer 206c0897a2 sd-network: Keep inotify watch if watch descriptor didn't change
In sd_network_monitor_flush(), we shouldn't remove the inotify
watch for the current directory if the directory the network
monitor is waiting for wasn't created yet.

inotify_add_watch() returns the same unique watch descriptor if a
path is already being watched. Let's return the watch descriptor
from monitor_add_inotify_watch() so we can check if it's the same
as the watch descriptor of the inotify event. If they are equal,
we're still watching the same path and we don't need to remove the
inotify watch just yet.
2022-05-04 07:00:56 +09:00
Daan De Meyer 4374d7eaac journal: Use header macros everywhere instead of JournalFile fields
Let's standardize on the journal header as a single source of truth
and remove redundant information from the JournalFile struct.
2022-05-03 17:23:02 +02:00
Lennart Poettering 968680b23d Merge pull request #23135 from DaanDeMeyer/journal-move
journal: Only move to object if requested
2022-05-03 10:01:39 +02:00
Yu Watanabe 15345fc677 sd-device: introduce device_get_property_bool() 2022-04-30 04:14:10 +09:00
Zbigniew Jędrzejewski-Szmek 4d5713bb7e Merge pull request #23119 from yuwata/test-sd-device-exclude-bdi
test: exclude "bdi" subsystem
2022-04-27 16:56:53 +02:00
Yu Watanabe ff56124b11 test: exclude "bdi" subsystem and loop block devices
On several CI environments, it seems that some loop block devices and
corresponding bdi devices are sometimes removed during the test is
running. Let's exclude them.

Fixes #22970.
2022-04-27 16:32:42 +09:00
Yu Watanabe 9409710097 sd-device-enumerator: introduce sd_device_enumerator_add_nomatch_sysname() 2022-04-27 16:32:42 +09:00
Yu Watanabe c11810ed30 sd-device-enumerator: use set_fnmatch() 2022-04-27 16:32:42 +09:00
Lennart Poettering d4cc5c8037 journal-verify: tighten check for compression of non-objects 2022-04-26 21:55:49 +02:00
Lennart Poettering 4d698d12de compress: make Compression a regular non-sparse enum
Given we have two different types for the journal object flags and the
Compression enum, let's make the latter a regular non-sparse enum, and
thus remove some surprises. We have to convert anyway between the two,
and already do via COMPRESSION_FROM_OBJECT().
2022-04-26 21:55:49 +02:00
Lennart Poettering acc50c92eb basic: move compress.[ch] → src/basic/
The compression helpers are used both in journal code and in coredump
code, and there's a good chance we'll use them later for other stuff.

Let's hence move them into src/basic/, to make them a proper internal
API we can use from everywhere where that's desirable. (pstore might be
a candidate, for example)

No real code changes, just some moving around, build system
rearrangements, and stripping of journal-def.h inclusion.
2022-04-26 21:45:03 +02:00
Zbigniew Jędrzejewski-Szmek 23ce0271dc Merge pull request #23160 from keszybz/compress-defines
meson: simplify setting of default compression
2022-04-25 10:57:51 +02:00
Yu Watanabe 8ac6b05b7c tree-wide: Fix typo 2022-04-25 10:06:08 +09:00
Zbigniew Jędrzejewski-Szmek ee00684c50 meson: use a single constant for default compression setting
Suggested by Daniele Nicolodi:
https://github.com/systemd/systemd/pull/23160#discussion_r855853716

This is possible only if the macro is never used in #if, but only in C code.
This means that all places that use #if have to be refactored into C, but we
reduce the duplication a bit, and C is nicer to read than preprocessor
conditionals.
2022-04-22 15:08:28 +02:00
Zbigniew Jędrzejewski-Szmek 1d997b8114 meson: simplify setting of default compression
Follow-up for da13d2ca07. Instead of having
separate definitions of the bitmask flags, just define DEFAULT_COMPRESSION_FOO=0|1
directly.

(It *should* be possible to do this more simply, but the problem is that
anything that is used in #if cannot refer to C constants or enums. This is the
simplest I could come up with that preserves the property that we don't use #ifdef.)

The return value from compress_blob() is changed to propagate the error instead
of always returning -EOPNOTSUPP. The callers don't care about the specific error
value. compress_blob_*() are changed to return the compression method on success, so
that compress_blob() can be simplified. compress_stream_*() and compress_stream() are
changed in the same way for consistency, even though the callers do not currently use
this information (outside of tests).
2022-04-22 12:02:29 +02:00
Lennart Poettering 7f40cb7c86 sd-bus: switch to a manual overflow check in sd_bus_track_add_name()
This is generally used in a directly client controllable way, hence we
should handle ref count overflow gracefully, instead of hitting an
assert().

As discussed:

https://github.com/systemd/systemd/pull/23099#discussion_r854341850
2022-04-21 08:58:35 +09:00
Daan De Meyer 9a390e86b7 journal: Document generic_array_bisect()
It's not trivial to figure out that this function does not search
for an exact match for the given needle, but whichever object in
the given direction that's closest to the needle.

Let's add a documentation blurb to explain how the function works
for to help future developers looking at this function.
2022-04-20 23:58:39 +02:00
Daan De Meyer 4d8b09e4b8 journal: Only move to object if requested 2022-04-20 22:16:06 +02:00
Lennart Poettering 947914cb44 Merge pull request #23099 from yuwata/sd-bus-track-fixlets
sd-bus: fix counter
2022-04-20 18:23:05 +02:00
Daan De Meyer b9b156ea3c Merge pull request #23124 from yuwata/fixes-for-post-merge-review
Fixes for post merge review
2022-04-20 17:15:40 +02:00
Luca Boccassi da13d2ca07 compression: add separate pre-processor definitions
Follow-up for https://github.com/systemd/systemd/commit/cd3c6322dbc6370448bafc216ee4e19e32a79d9e

journal-def.h should be self-contained too, as it represents the journal object ABI.
Duplicate the enums, as they also need to be in config.h for it to be self-contained,
and enums are not available to the preprocessor. Use an assert to ensure they don't
diverge.
2022-04-19 23:18:19 +02:00
Yu Watanabe 9dbfcaf229 sd-device: use string_replace_char() and strspn_from_end() 2022-04-20 02:19:44 +09:00
Yu Watanabe e4e1353c25 sd-device: refuse O_DIRECTORY returned from path_extract_filename()
In both cases, it is expected that the symlink targets do not end with '/'.

Addresses https://github.com/systemd/systemd/pull/23089#discussion_r853007218.
2022-04-20 01:43:27 +09:00
Yu Watanabe 056a18e465 test: add several tests for track item 2022-04-19 18:02:10 +09:00
Yu Watanabe 63ec7a8490 test: shorten code a bit 2022-04-19 18:02:10 +09:00
Yu Watanabe c399ed923d sd-bus: use hashmap_contains() and drop unnecessary cast 2022-04-19 18:02:10 +09:00
Yu Watanabe 55bfacc6c3 sd-bus: do not return negative errno when unknown name is specified
When 'recursive' is false, then sd_bus_track_remove_name() does not
return negative errno when unknown name is specified. Let's follow the
same pattern for the case that 'recursive' is true.
2022-04-19 18:02:10 +09:00
Yu Watanabe 6a7ca27740 sd-bus: do not read unused value 2022-04-19 18:02:10 +09:00
Yu Watanabe c2d7dd35d2 sd-bus: introduce ref/unref function for track_item 2022-04-19 18:01:46 +09:00
Yu Watanabe b21f237d99 sd-bus: fix reference counter to be incremented
Fixes #23097.
2022-04-19 17:58:08 +09:00
Yu Watanabe 915774ecb8 Merge pull request #23101 from yuwata/sd-device-cleanups
sd-device: several cleanups
2022-04-18 07:01:42 +09:00
Luca Boccassi cd3c6322db compression: add build-time option to select default
Compression and decompression are controlled by the same build flag,
so if one wants to use, say, LZ4 to compress, ZSTD has to be disabled,
which means one loses the ability to read zstd-compressed journals.

Add a default-compression meson option, that allows to select any of
the available compression algorithms as the default.
2022-04-18 05:43:59 +09:00
Yu Watanabe 23d20adc05 sd-device: rename arguments and variables 2022-04-18 04:34:14 +09:00
Yu Watanabe 9c5d7151c1 sd-device: fix possible use-of-uninitialized-value 2022-04-18 04:34:14 +09:00
Yu Watanabe 17761fb3bf sd-device: use ERRNO_IS_DEVICE_ABSENT() at one more place 2022-04-18 04:34:14 +09:00
Yu Watanabe d82827a107 sd-device: rename function arguments for storing results 2022-04-18 04:34:14 +09:00
Yu Watanabe c77c1cc201 sd-device: use correct type and parser for device node uid and gid 2022-04-18 04:34:14 +09:00
Yu Watanabe d37c69c1bf sd-device: shorten code a bit 2022-04-18 04:34:14 +09:00
Yu Watanabe ce1d08ba94 sd-device: use path_extract_filename() at one more place
This also does several cleanups.
2022-04-18 04:34:14 +09:00
Yu Watanabe 60e50fb20d sd-device: reset sysname and sysnum on renaming 2022-04-18 04:34:14 +09:00