Blender V5.3
dbus_dynload.c
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include <stddef.h> /* `NULL`. */
12#include <string.h> /* `memset`. */
13
14#include "dbus_dynload_API.h"
15#include "dbus_dynload_utils.h"
16
17#include "dbus_dynload.h" /* Own include. */
18
19/* Public handle. */
20struct DBusDynload dbus_dynload = {NULL};
21
22static DynamicLibrary lib = NULL;
23
24bool dbus_dynload_init(const bool verbose)
25{
26 if (lib != NULL) {
27 return true;
28 }
29
30 /* Library paths. */
31 const char *paths[] = {
32 "libdbus-1.so.3",
33 "libdbus-1.so",
34 };
35 const int paths_num = sizeof(paths) / sizeof(*paths);
36 int path_index;
37 if (!(lib = dynamic_library_open_array_with_error(paths, paths_num, verbose, &path_index))) {
38 return false;
39 }
40
41 /* NOTE: unlike `wayland_dynload`, there is no `atexit` unload. DBUS is used from a background
42 * thread which may still be running at exit (see #GHOST_SystemDBusUnix), unloading the library
43 * from under it would crash. Keeping it loaded for the life of the process is harmless. */
44
45#define DBUS_DYNLOAD_FN(symbol) \
46 if (!(dbus_dynload.symbol = dynamic_library_find_with_error( \
47 lib, #symbol, paths[path_index], verbose))) \
48 { \
49 memset(&dbus_dynload, 0x0, sizeof(dbus_dynload)); \
50 dynamic_library_close(lib); \
51 lib = NULL; \
52 return false; \
53 }
54#include "dbus_dynload.h"
55#undef DBUS_DYNLOAD_FN
56
57 return true;
58}
59
60/* Validate local signatures against the original header. */
61#pragma GCC diagnostic push
62#pragma GCC diagnostic ignored "-Wredundant-decls"
63#define DBUS_DYNLOAD_VALIDATE
64#include "dbus_dynload.h"
65#pragma GCC diagnostic pop
static DynamicLibrary lib
struct DBusDynload dbus_dynload
bool dbus_dynload_init(bool verbose)
DynamicLibrary dynamic_library_open_array_with_error(const char **paths, const int paths_num, const bool verbose, int *r_path_index)
void * DynamicLibrary