Commit graph

6299 commits

Author SHA1 Message Date
Alex Richardson
eb70deaaab dbus-sysdeps-unix.c: Silence -Wcast-align when using CMSG_DATA
This triggers when building on FreeBSD with clang, but since we know that
the CMSG_DATA() will be aligned we can silence the warning using a cast.
2022-05-17 11:21:33 +00:00
Alex Richardson
d68c843b27 dbus-string.c: use memcpy() in _dbus_string_insert_{2,4,8}_aligned
This fixes a -Wcast-align warning from Clang, and I believe this could
be a genuine issue on some architectures since the octets argument is
an unsigned char pointer that only has alignment 1. Using memcpy() instead
will generate the same code on architectures that support unaligned loads
and stores (i.e. almost all current ones) and individual stores on those
that don't (e.g. old MIPS).
2022-05-17 11:21:33 +00:00
Alex Richardson
1b72096261 dbus-marshal-basic.c: Silence Clang -Wcast-align false-positives
Clang performs the -Wcast-align analysis before code generation and
optimizations, so the compiler cannot see that the alignment is actually
guaranteed to be sufficient for these casts. Silence the warning by adding
casts to void* and/or changing the types of some variables.
2022-05-17 11:21:33 +00:00
Ralf Habacker
cfde6fd49c Merge branch 'cmake-junit-xml-output' into 'master'
tools/ci-build.sh: Add a ci_cmake_junit_output argument

See merge request dbus/dbus!299
2022-05-17 11:02:17 +00:00
Alex Richardson
364fe6be69 tools/ci-install.sh: Install newer CMake on openSuSE
This is needed for JUnit XML output for tests.
2022-05-17 10:48:06 +00:00
Alex Richardson
f366b38f31 tools/ci-build.sh: Add a ci_cmake_junit_output argument
CMake 3.21 can emit JUnit XML test results which can be visualized by
GitLab. This also updates the gitlab CI config file to make use of this
feature whenever possible.
2022-05-17 10:48:06 +00:00
Simon McVittie
f385a747b5 Merge branch 'fix-cmake-dbus-use-sync' into 'master'
cmake: Fix definition of DBUS_USE_SYNC

See merge request dbus/dbus!306
2022-05-16 18:52:16 +00:00
Alex Richardson
b932c343c4 cmake: Fix definition of DBUS_USE_SYNC
dbus-sysdeps-unix.c checks for DBUS_USE_SYNC using 0/1 checks not defined
checks, so we should be using #cmakedefine01. This fixes lots of -Wundef
warnings when compiling for FreeBSD and ensures that we actually use
atomics instead of the pthread fallback there.
2022-05-16 18:39:26 +00:00
Simon McVittie
146f48ba0b Merge branch 'fix-wshadow' into 'master'
dir-watch-kqueue: Silence -Wshadow warning

See merge request dbus/dbus!307
2022-05-16 18:36:38 +00:00
Alex Richardson
2480181af4 dir-watch-kqueue: Silence -Wshadow warning
This should be the last warning that is preventing us from using -Werror
for FreeBSD builds.
2022-05-15 11:35:35 +01:00
Ralf Habacker
9722d62149 Merge branch 'ci-templates' into 'master'
Use freedesktop/ci-templates for the GitLab CI

See merge request dbus/dbus!301
2022-05-09 12:29:47 +00:00
Alex Richardson
4ce02f196b Use freedesktop/ci-templates for the GitLab CI
The CI templates include infrastructure to create docker images with all
packages specified in tools/ci-install.sh. Using those docker images
speeds up the CI since we don't have to install all the dependencies in
every pipeline. We could extend this to also create containers that have
mingw pre-installed but for now we only create an image with the
dependencies that are required for every job.
2022-05-07 16:48:29 +01:00
Simon McVittie
c6aa71b5de Merge branch 'fix-issue-369' into 'master'
Add assertions to the [c|r]mutex related functions on Windows

Closes #369

See merge request dbus/dbus!243
2022-05-05 14:20:39 +00:00
Ralf Habacker
c6e1ba086f Add doc to platform related [c|r]mutex functions 2022-05-01 19:54:06 +02:00
Ralf Habacker
5f1bc83d36 Add unit tests for platform-specific mutex implementation.
The tests are enabled with the embedded tests; the required
low-level functions from the dbus library are decorated with
DBUS_EMBEDDED_TESTS_EXPORT to indicate the appropriate usage.

On Windows, all tests are run; on unix-like operating systems,
individual tests are disabled:
- the tests on #NULL pointers of type DBus[C|R]Mutex, since they
  point to a data structure and would cause a segment violation
  when accessed.
- the multiple lock test for type DBusCMutex, since it would block
  the current thread.

Since the whole point of "rmutex" is to be able to lock multiple
times, the "rmutex double lock" test is enabled on unix-like
operating systems too.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-05-01 19:52:48 +02:00
Ralf Habacker
72a7758e38 Add assertions to the [c|r]mutex related functions on Windows
This detects some error conditions that can only occur as a
result of a programming error, such as attempting to unlock a
mutex that is not locked.

Fixes #369

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-05-01 18:55:05 +02:00
Ralf Habacker
31307769ca Merge branch 'fix-strict-warning-related' into 'master'
Fix mingw gcc 10.3 compiler warnings

Closes #383

See merge request dbus/dbus!275
2022-05-01 16:41:06 +00:00
Ralf Habacker
29946ad7c1 tests: Fix build warning "dereferencing type-punned pointer will break strict-aliasing rules"
To avoid that build break in test-marshall-recursive-util.c the newly
added function _dbus_string_append_buffer_as_hex() is used to print
the hex bytes.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-05-01 16:28:51 +00:00
Ralf Habacker
2e63543b93 dbus-string: Add _dbus_string_append_buffer_as_hex()
This function provides a portable way to print data as hex values.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
[smcv: Only compile this when needed, improve assertions, coding style]
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-01 16:28:51 +00:00
Simon McVittie
76fe49b7ab dbus: Move DBUS_PRIVATE_EXPORT to private header
Unlike the rest of the macros in dbus-macros.h, this one would never
have made sense to use in a public header.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-01 16:28:51 +00:00
Simon McVittie
f8e3736385 dbus: Move DBUS_ENABLE_EMBEDDED_TESTS to a new dbus-macros-internal.h
This avoids a circular dependency: I want to use
DBUS_ENABLE_EMBEDDED_TESTS in dbus-string.h, but
DBUS_ENABLE_EMBEDDED_TESTS was previously defined in dbus-internals.h,
which depends on dbus-string.h.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-05-01 16:28:51 +00:00
Ralf Habacker
87341dab13 Merge branch 'test-socket-dir' into 'master'
cmake: Allow overriding TEST_SOCKET_DIR

See merge request dbus/dbus!295
2022-05-01 16:28:23 +00:00
Alex Richardson
856a4ee54e cmake: Allow overriding TEST_SOCKET_DIR
This matches the autotools build where that option can also be overridden.
2022-05-01 16:16:25 +00:00
Ralf Habacker
6666d9f6ff Merge branch 'cmake-user-args' into 'master'
tools/ci-build.sh: Pass user arguments to cmake last

See merge request dbus/dbus!296
2022-05-01 16:10:01 +00:00
Alex Richardson
50689407cf tools/ci-build.sh: Pass user arguments to cmake last
This allows a user to override ENABLE_WERROR for platforms that are not
yet -Werror clean.
2022-05-01 15:57:40 +00:00
Simon McVittie
bf04d6fb54 Merge branch 'fix-c++-warnings' into 'master'
cmake: fixes for compiler warning support

Closes #387

See merge request dbus/dbus!293
2022-04-21 14:08:44 +00:00
Ralf Habacker
523796873f cmake: Let the c++ compiler use the warnings available to it
Fixes #387

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-04-21 13:51:55 +00:00
Ralf Habacker
f075650634 cmake: in macro generate_compiler_warning_flags prevent duplicates in variable containing unsupported warnings
Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-04-21 13:51:55 +00:00
Ralf Habacker
fb5449e08f cmake: Fix detecting -Wformat-* warnings for gcc
gcc expects -Wformat to be set along with these type of warnings.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-04-21 13:51:55 +00:00
Ralf Habacker
bbd3f90a8d cmake: Fix not detecting unsupported g++ related warning checks
Unsupported warnings are detected by cmake through errors during
compilation, which causes g++ not to detect them, since they are
only output as warnings. Setting -Werror ensures this.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
2022-04-21 13:51:55 +00:00
Ralf Habacker
4b73505869 Ignore gcc 10.3 'inline' warnings: 'call is unlikely and code size would grow'
As long as gcc does something with compatible semantics, it is up to gcc
how to optimize our code.

The alternative would be to export the functions in question from the
shared library, which has the disadvantage of greatly increasing the
number of calls across a shared library boundary.

Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
2022-04-21 13:56:26 +01:00
Ralf Habacker
b90b838c93 bus_service_remove_owner(): Assert that service has an owner
gcc 10.3 warns that link->data is a possible NULL dereference.
However, that can't actually happen without an earlier programming
error, because bus_service_remove_owner() is only valid to call for
a connection that is currently in the queue to own the service,
in which case we know _bus_service_find_owner_link() will succeed.

Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
2022-04-21 13:55:59 +01:00
Ralf Habacker
21a6441f33 _dbus_string_test(): Fix fatal build error caused by "-Wstrict-aliasing"
To fix this problem, the problematic code was replaced by a new function
_dbus_string_get_allocated_size(), which uses the existing macro
DBUS_CONST_STRING_PREAMBLE for these purposes.

Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de>
Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
2022-04-21 13:55:38 +01:00
Ralf Habacker
da36b47af1 bus: Add assertions to silence compiler warnings
gcc 10.3 warns that link->data might be NULL, which would make
new_owner->conn a null pointer dereference. However, we know that
we only add valid, non-null BusOwner objects to the list, so that
can't happen in reality.

Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
2022-04-21 13:55:15 +01:00
Ralf Habacker
3e8423d299 test-segfault: Fix build error caused by a null pointer dereference warning
Only do the deliberate crash via undefined behaviour (which the compiler
is quite right to warn us about!) if raise() isn't available.

The pointer needs to be volatile otherwise the compiler is free to remove
the store.

Part-of: https://gitlab.freedesktop.org/dbus/dbus/-/merge_requests/275
Reviewed-by: Simon McVittie <smcv@collabora.com>
2022-04-21 13:54:23 +01:00
Simon McVittie
f2982fc37b Merge branch 'closefrom' into 'master'
sysdeps: Use closefrom() or close_range() if available

Closes #278

See merge request dbus/dbus!265
2022-04-21 12:18:23 +00:00
Simon McVittie
63632eaf8d test: Add basic test coverage for _dbus_close_all and friends
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
6a4a89ccea test-utils-glib: Add backports of some convenience macros
Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
b7c325e573 test-utils-glib: Ensure correct precedence in g_assert_nonnull()
It's best-practice to put macro arguments in parentheses so that they
are always treated as a unit.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
ccea70515e sysdeps: On Linux, wrap close_range syscall directly if necessary
This was added to the Linux kernel in version 5.9, but the wrapper
wasn't added to glibc until 2.34. Adding our own wrapper for the
system call means we can use close_range() on Debian 11 and
contemporary distributions.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
d307616177 sysdeps: Include <linux/close_range.h> if available
This lets us use CLOSE_RANGE_CLOEXEC whenever the kernel headers
support it, even if glibc doesn't include this header via unistd.h yet.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:44 +01:00
Simon McVittie
ee694ade61 sysdeps: Use close_range() if available
The version with no flags set, which is a slight generalization of
closefrom(), is available on recent Linux and FreeBSD.

The version with CLOSE_RANGE_CLOEXEC is Linux-specific.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:14 +01:00
Simon McVittie
faa3b2ef4a sysdeps: Only use closefrom() if known to be async-signal-safe
closefrom() is known to be async-signal-safe on FreeBSD, NetBSD and
OpenBSD, and safe to call after fork() on Solaris, but not necessarily
on DragonflyBSD.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:14 +01:00
rim
54c62040b2 Use closefrom() to not loop over all possible file descriptors
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/278
2022-04-21 11:02:14 +01:00
Simon McVittie
a6154cb8ef CI: Add a manual CI job for Ubuntu 22.04 'jammy'
This has a very recent version of glibc, and in particular is new enough
to have close_range().

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-21 11:02:13 +01:00
Simon McVittie
48f32958b7 Merge branch 'dont-crash-watch' into 'master'
bus/dir-watch: Do not crash with > 128 dirs

See merge request dbus/dbus!302
2022-04-20 11:29:31 +00:00
Jan Tojnar
b551b3e973 bus/dir-watch: Do not crash with > 128 dirs
Without this running, dbus-daemon with long XDG_DATA_DIRS
will crash on out-of-bounds write:

	$ XDG_DATA_DIRS=$(seq  -f "/foo/%g" -s ':' 129) dbus-daemon --session
	*** stack smashing detected ***: terminated
2022-04-20 11:24:40 +02:00
Simon McVittie
14b5119f9e Merge branch 'int64_modifier' into 'master'
build: Define DBUS_INT64_MODIFIER, analogous to G_GINT64_MODIFIER

See merge request dbus/dbus!289
2022-04-19 18:47:41 +00:00
Simon McVittie
6130ac4267 build: Define DBUS_INT64_MODIFIER, analogous to G_GINT64_MODIFIER
Using PRId64, etc. to print dbus_int64_t or dbus_uint64_t is not 100%
portable. On platforms where both long and long long are 64-bit (such as
Linux and macOS), we will prefer to define dbus_int64_t as long.
If the operating system has chosen to define int64_t as long long,
which is apparently the case on macOS, then the compiler can warn that
we are passing a long argument to PRId64, which is "lld" and therefore
expects a long long argument (even though that ends up with the same
bit-pattern being used).

We can't necessarily just use int64_t and uint64_t directly, even if all
our supported platforms have them available now, because swapping
dbus_int64_t between long and long long might change C++ name mangling,
causing ABI breaks in third-party libraries if they define C++ functions
that take a dbus_int64_t argument.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2022-04-19 18:27:47 +00:00
Simon McVittie
8972fcb029 Merge branch 'cmake-config-file-unix' into 'master'
cmake: Correct DBUS_{SYSTEM,SESSION}_CONFIG_FILE on UNIX systems

See merge request dbus/dbus!297
2022-04-19 12:06:58 +00:00