Alex Richardson [Sun, 15 May 2022 10:28:51 +0000 (11:28 +0100)]
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.
Alex Richardson [Mon, 18 Apr 2022 22:18:41 +0000 (22:18 +0000)]
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.
Ralf Habacker [Wed, 2 Mar 2022 12:17:10 +0000 (13:17 +0100)]
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.
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.
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>
Simon McVittie [Thu, 21 Apr 2022 13:35:44 +0000 (14:35 +0100)]
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>
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.
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>
Ralf Habacker [Mon, 7 Mar 2022 15:38:25 +0000 (16:38 +0100)]
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>
Ralf Habacker [Tue, 1 Mar 2022 09:54:05 +0000 (10:54 +0100)]
_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>
Ralf Habacker [Tue, 8 Mar 2022 07:48:31 +0000 (08:48 +0100)]
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>
Simon McVittie [Wed, 2 Mar 2022 12:25:54 +0000 (12:25 +0000)]
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>
Simon McVittie [Tue, 1 Mar 2022 19:12:38 +0000 (19:12 +0000)]
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>
Simon McVittie [Fri, 1 Apr 2022 14:57:07 +0000 (15:57 +0100)]
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>
Alex Richardson [Fri, 1 Apr 2022 11:09:45 +0000 (11:09 +0000)]
cmake: Correct DBUS_{SYSTEM,SESSION}_CONFIG_FILE on UNIX systems
We always install to a dbus-1 subdir, but the path encoded in the binary
was missing the dbus-1/ subdirectory, so we end up getting errors when
trying to load it.
The detection is based on the variable VERSION_CODENAME from
/etc/os-release, which is supported by systemd. For further details see
https://www.freedesktop.org/software/systemd/man/os-release.html.
Ralf Habacker [Wed, 30 Mar 2022 08:50:29 +0000 (10:50 +0200)]
Add automatic detection of distribution to CI scripts
The detection is based on the variable ID from /etc/os-release,
which is supported by systemd. For further details see
https://www.freedesktop.org/software/systemd/man/os-release.html.
Simon McVittie [Fri, 1 Apr 2022 13:47:27 +0000 (14:47 +0100)]
CI: Don't wait for Windows Docker image before doing Unix builds
The default in Gitlab-CI is that each job waits for all jobs in
previous stages to complete, but we can override this default by
explicitly saying that there are no prerequisites.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Simon McVittie [Fri, 6 Nov 2020 14:42:19 +0000 (14:42 +0000)]
cmake: Look for dbus-arch-deps.h next to DBus1Config.cmake
<dbus/dbus-arch-deps.h> is architecture-dependent, and compilers have
not traditionally supported an installation path for architecture-specific
headers (Debian-based systems have /usr/include/${multiarch_tuple}, but
that isn't portable beyond Debian). When dbus was built using Autotools,
dependent projects that use CMake need to look for this header in the
right place.
Unfortunately, it seems that at least recent versions of CMake will
ignore the HINTS we get from pkg-config if they are told to search in
a non-standard prefix via ${DBus1_ROOT}.
Look for dbus-arch-deps.h in a directory derived from the filename of
the CMake config file, before trying the normal search algorithm. The
CMake config file is in ${libdir}, and so is the architecture-specific
header, so this should work reasonably reliably.
According to the CMake documentation, if we search for the same thing
multiple times, the first successful result will be used; and searching
with NO_DEFAULT_PATH is the official way to prepend things to the
search order.
Resolves: https://gitlab.freedesktop.org/dbus/dbus/-/issues/314 Signed-off-by: Simon McVittie <smcv@collabora.com>
Simon McVittie [Wed, 16 Mar 2022 13:30:33 +0000 (13:30 +0000)]
dbus-launch: If no X11, look for existing bus before failing
What we are aiming for here is that `dbus-launch --autolaunch` will
exit with an error if it would have been unable to advertise the bus
in a way that will be picked up by other instances of itself, so that
we don't get a proliferation of autolaunched dbus-launch instances,
each with its own dbus-daemon, and none of them talking to the others.
However, we don't need to do that *immediately*: we can try to look for
an existing instance first. If we find one, then we can assume that
it's suitable for use, even if X11 autolaunching was disabled at
compile-time or if connecting to the X server failed at runtime. We
only need to bail out if we get to the point where we are ready to start
forking child processes.
This lets systemd users run `dbus-launch --autolaunch` to find a
systemd-managed dbus-daemon, even if X11 autolaunching is disabled.
When combined with the previous commit, it also lets macOS users run
`dbus-launch --autolaunch` to find a launchd-managed dbus-daemon.
Resolves: dbus/dbus#385 Signed-off-by: Simon McVittie <smcv@collabora.com>
Simon McVittie [Wed, 16 Mar 2022 13:24:53 +0000 (13:24 +0000)]
dbus-launch: Generalize support for discovering an existing bus
Previously we were looking for an existing bus via
_dbus_lookup_user_bus(), meaning a user bus $XDG_RUNTIME_DIR/bus
(in practice this is managed by systemd --user, although in principle
there's nothing to stop other session frameworks from providing the
same thing).
_dbus_lookup_session_address() looks for an externally-managed
dbus-daemon in a more general way: on macOS it uses launchd, and on other
Unix it's a thin wrapper around _dbus_lookup_user_bus(). Let's try that,
so that macOS users can get their existing dbus-daemon from launchd.
This partially resolves dbus/dbus#385, although initially only for macOS
users who have (unusually) enabled X11 autolaunching support.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Alex Richardson [Sat, 19 Mar 2022 14:58:59 +0000 (14:58 +0000)]
cmake: Only add warning flags if the compiler supports them
I am compiling for FreeBSD where the compiler is Clang and doesn't accept
all the GCC warning flags. This breaks the -Werror build:
```
error: unknown warning option '-Wduplicated-branches' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wduplicated-cond' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wjump-misses-init' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wlogical-op'; did you mean '-Wlong-long'? [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wrestrict' [-Werror,-Wunknown-warning-option]
error: unknown warning option '-Wunused-but-set-variable'; did you mean '-Wunused-const-variable'? [-Werror,-Wunknown-warning-option]
```
With this change we use check_{c,cxx}_compiler_flag to check if the flag
is supported before adding it. In the future this will allow adding
clang-specific warning flags to the list of warnings as well since they
will be ignored for GCC.
Mike Gilbert [Sun, 27 Mar 2022 19:09:48 +0000 (15:09 -0400)]
sysdeps-unix: check fd before calling _dbus_fd_set_close_on_exec()
If /proc/self/oom_score_adj does not exist, fd will invalid (-1).
Attempting to set the CLOEXEC flag will obviously fail, and we lose the
original errno value from open().
Bug: https://bugs.gentoo.org/834725 Signed-off-by: Mike Gilbert <floppym@gentoo.org>
Alex Richardson [Sat, 19 Mar 2022 14:56:12 +0000 (14:56 +0000)]
cmake: Fix DBUS_SESSION_SOCKET_DIR when cross-compiling
Inferring it from the environment is not correct, since the host system
could have a different temporary directory defined. Instead of guessing
based on the host, require the user to pass an explicit directory when
cross-compiling. This is helpful for me since I am cross-compiling for
FreeBSD from macOS and on my host TMPDIR is set to
/var/folders/<random characters>/T/ instead of the expected /tmp.
Ralf Habacker [Tue, 29 Mar 2022 07:36:54 +0000 (09:36 +0200)]
tools/ci-install.sh: on debian|ubuntu reduce the need for mingw package name changes
Instead of having to specify an exact version that needs to be adjusted
with each repository update, it is now possible to specify package names
without version or partially qualified versions, which reduces the
frequency of necessary adjustments.
This is achieved by searching for the package names in a previously
downloaded list of available packages.
Alex Richardson [Sat, 19 Mar 2022 17:56:54 +0000 (17:56 +0000)]
cmake: Only pass -Wl,--export-dynamic when linking
Otherwise we get the following warnings when building .o files with Clang:
clang-13: warning: -Wl,--export-dynamic: 'linker' input unused [-Wunused-command-line-argument]
This is required to allow the -Werror build to pass on FreeBSD.
Alex Richardson [Wed, 23 Mar 2022 22:06:33 +0000 (22:06 +0000)]
cmake: Drop an unnecessary include directory
There should be no need to include the directory above the DBus sources,
if that is actually required users can always pass -I flags to CMake.
I noticed this because CLion started indexing all my cloned projects when
I opened DBus due to this include path.
Alex Richardson [Sun, 20 Mar 2022 23:25:29 +0000 (23:25 +0000)]
cmake: Detect backtrace() support on platforms such as FreeBSD
On FreeBSD use of backtrace requires linking libexecinfo. The current
check_symbol_exists() will fail due to that missing library. Fortunately,
CMake ships with a FindBacktrace module (at least since 3.0) that can
be used to correctly handle platforms such as FreeBSD (and OpenBSD
according to the FindBacktrace source).
Alex Richardson [Sat, 19 Mar 2022 14:48:04 +0000 (14:48 +0000)]
Revert "Fix gcc compile error: redundant redeclaration of ‘environ’ [-Werror=redundant-decls]"
Breaks the build on FreeBSD which doens't have an environ declaration.
The CMake check_symbol_exists call sets `HAVE_DECL_ENVIRON` to an empty
variable (which means if(DEFINED) suceeds). This normalization should not
be necessary as it will be handled correctly by `#cmakedefine01`. If not,
all the other HAVE_* defines would also be wrong.
Simon McVittie [Wed, 16 Mar 2022 14:54:55 +0000 (14:54 +0000)]
sysdeps: Implement _DBUS_DOUBLES_BITWISE_EQUAL with memcmp
memcmp is the Standard C way to compare arbitrary regions of memory
bit-by-bit, so let's use it, instead of reinventing it in a way that
violates Standard C aliasing rules.
Signed-off-by: Simon McVittie <smcv@collabora.com>
Ralf Habacker [Thu, 3 Mar 2022 11:40:17 +0000 (12:40 +0100)]
cmake: Fix race condition on creating docbook based files
With the previous implementation, race conditions could arise because a
generated intermediate file was used by multiple targets.
To fix the mentioned problem, the macro 'generate_docbook_file' has been
integrated into a in a new macro 'add_docbook' to simplify the dependency
chain and make it easier to use.
When using an xml template with the 'TEMPLATE' parameter, a separate
intermediate xml file is used for each generated output file to avoid
overwriting each other, which was the main cause of the described problem.
Due to the adaptation of the calling conventions it was necessary to
introduce the parameter 'MAN_CATEGORY'.
Ralf Habacker [Thu, 3 Mar 2022 08:48:51 +0000 (09:48 +0100)]
cmake: Set DBUS_*_CONFIG_FILE to be in datadir on Unix
The files were installed to the datadir (usually /usr/share) since
commit 70950325, but the macros used to implement dbus-daemon --system
and dbus-daemon --session still looked for them in the sysconfdir
(usually /etc).
Fixes: 70950325 "Adjust cmake build to match autoconf installation locations"