summaryrefslogtreecommitdiff
path: root/dbus/dbus-internals.c
Commit message (Collapse)AuthorAgeFilesLines
* Add SPDX license marker for the AFL-2.1 OR GPL-2.0-or-later licenseRalf Habacker2023-01-041-0/+2
| | | | | | | | | The full license texts are not added because they were already added in a previous commit. Signed-off-by: Ralf Habacker <ralf.habacker@freenet.de> see #394
* internals: Statically assert some things we assume about pointersSimon McVittie2022-11-291-0/+29
| | | | | | | | | | | | | Like many relatively-low-level codebases, dbus has historically assumed that data pointers are interchangeable with function pointers (which is implied by POSIX and also true on Windows, but not guaranteed by ISO C). Before dbus!335 was merged, we also assumed that size_t is the same size as a pointer (which is frequently assumed, but not guaranteed by ISO C, and notably not true on CHERI). dbus!335 is believed to have removed all uses of that assumption. Signed-off-by: Simon McVittie <smcv@collabora.com>
* dbus: move DBUS_IS_DIR_SEPARATOR to dbus-internals.hMarc-André Lureau2022-07-151-12/+1
| | | | Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
* Add unit tests for platform-specific mutex implementation.Ralf Habacker2022-05-011-0/+11
| | | | | | | | | | | | | | | | | | | | 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>
* _dbus_verbose_real: Use the Python convention for quoting potentially ↵Ralf Habacker2020-04-271-2/+2
| | | | multi-line strings when memory is unavailable on Windows
* In _dbus_verbose_real() avoid possible stack overflows on output to the ↵Ralf Habacker2020-02-201-8/+53
| | | | | | | | | | Windows debug port Instead of creating a fixed memory area on the stack that can lead to a stack overflow if exceeded, this configuration now uses a DBusString instance that dynamically manages memory. Resolves: https://gitlab.freedesktop.org/dbus/dbus/issues/45
* various: comment static variables that are locked or otherwise OKSimon McVittie2019-12-121-0/+7
|
* tests: Improve diagnostics for malloc-failure testsSimon McVittie2019-07-021-3/+3
| | | | | | | Some of these appear to hang, but making this diagnostic appear in the log reveals the truth: it's just very slow. Signed-off-by: Simon McVittie <smcv@collabora.com>
* test-spawn-oom: Separate single spawn tests from oom relatedRalf Habacker2019-03-151-1/+1
| | | | This makes it possible to run each test independent from oom condition.
* trivial: Remove trailing whitespace from copyright noticesSimon McVittie2018-12-171-2/+2
| | | | | | | | | | | | | | We don't usually mass-remove trailing whitespace from the actual source code because it would complicate cherry-picking bug fixes to older branches, but that reasoning doesn't really apply to the comments containing copyright and licensing notices. Removing trailing whitespace makes it much easier to move code around: we have a commit hook that rejects commits containing trailing whitespace, but that commit hook counts moving a file as a delete + add pair, so it objects to moving code that contains trailing whitespace. Signed-off-by: Simon McVittie <smcv@collabora.com>
* Don't do OOM testing under valgrind by defaultSimon McVittie2018-08-021-0/+9
| | | | | | | | | It's just painfully slow, particularly when we fork (as we do in test-bus to test service activation). Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=107194
* dbus-spawn-unix: Rename from dbus-spawnSimon McVittie2018-01-151-1/+1
| | | | | | | | | This file is the Unix counterpart of dbus-spawn-win.c, so it's less confusing for it to have an indicative name. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=104588
* _dbus_test_oom_handling: print TAP diagnosticsSimon McVittie2017-12-041-8/+14
| | | | | | | | | These aren't *that* verbose, so it seems OK to print them all the time, not just in the needlessly spammy verbose mode. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=100317 Reviewed-by: Philip Withnall <withnall@endlessm.com> Signed-off-by: Simon McVittie <smcv@collabora.com>
* bus: Silence most log messages when testing OOM handlingSimon McVittie2017-11-151-2/+2
| | | | | | | | | In parts of the OOM testing, our logging produces multiple megabytes of output. Let's not do that. Reviewed-by: Philip Withnall <withnall@endlessm.com> Signed-off-by: Simon McVittie <smcv@collabora.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=103601
* internals: Decouple logging an error from exiting unsuccessfullySimon McVittie2017-07-051-2/+2
| | | | | | | | | | | | This lets _dbus_warn() and _dbus_warn_check_failed() fall through to flushing stderr and calling _dbus_abort(), meaning that failed checks and warnings can result in a core dump as intended. By renaming the FATAL severity to ERROR, we ensure that any code contributions that assumed the old semantics will fail to compile. Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=101568
* Make _dbus_get_local_machine_uuid_encoded() properly failableSimon McVittie2017-06-081-19/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This function already raised an error, and all callers handled that error as gracefully as they could (because _dbus_generate_uuid() is failable, since 2015). Given that, it seems unnecessarily hostile to do a _dbus_warn_check_failed() unless we have no better alternative: yes, it indicates that dbus has not been installed correctly, but during build-time tests it's entirely reasonable that dbus has not yet been installed. Callers are: * DBusConnection, to implement Peer.GetMachineId() * The bus driver, to implement Peer.GetMachineId() * X11 autolaunching * dbus_get_local_machine_id() Of those, only the last one is not in a position to return an error gracefully, so move the _dbus_warn_check_failed() to there. Migrate the text about the D-Bus library being incorrectly set up into the error emitted by the Unix implementation, and to make it less misleading, include separate error messages for both the files we try to read: $ bwrap --ro-bind / / --dev /dev --tmpfs /etc --tmpfs /var \ ./tools/dbus-uuidgen --get D-Bus library appears to be incorrectly set up: see the manual page for dbus-uuidgen to correct this issue. (Failed to open "/var/lib/dbus/machine-id": No such file or directory; Failed to open "/etc/machine-id": No such file or directory) Signed-off-by: Simon McVittie <smcv@collabora.com> Reviewed-by: Philip Withnall <withnall@endlessm.com> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=13194
* Only print timestamps on stderr if verbose messages will go thereRalf Habacker2017-02-101-2/+2
| | | | | | | | | | On Windows, dbus can be configured to send DBUS_VERBOSE messages to the Windows debug port instead of stderr. If we're in that configuration, we already avoided printing thread information to stderr before each verbose message; do the same for timestamps. Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=99749
* Reimplement _dbus_warn_return_if_fail without -Wformat-nonliteralSimon McVittie2016-10-131-4/+11
| | | | | | | | | | | We can avoid duplicating the format string between translation units, without the compiler warning us that it can't check non-literal format strings for format-string security vulnerabilities based on %p, by breaking out the "assertion failed" case into a slow-path. Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Thomas Zimmermann <tdz@users.sourceforge.net> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97357
* internals: remove newline, pid from assertion failuresSimon McVittie2016-09-301-4/+4
| | | | | | | | | _dbus_warn() now calls _dbus_logv() which always logs the pid and prints a newline anyway. Signed-off-by: Simon McVittie <smcv@debian.org> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=97009
* _dbus_warn, _dbus_warn_check_failed: unify with _dbus_logvSimon McVittie2016-09-301-6/+12
| | | | | | | | | | | | | | | | | | | | | | | | | This means that dbus-daemon will log something like dbus-daemon[123]: Unable to add reload watch to main loop to syslog and/or stderr according to its configuration, while other libdbus users will print something like this to stderr: dbus[4567]: arguments to dbus_foo() were incorrect, assertion "connection != NULL" failed at file dbus-foo.c line 123. This is normally a bug in some application using the D-Bus library. This slightly changes the meaning of the argument to _dbus_warn() and _dbus_warn_check_failed. Previously, a trailing newline was expected, and a missing newline would have resulted in incorrect output. Now, a newline is supplied automatically by the library (like g_warning()), and messages that end with a newline will result in an unnecessary extra newline in output. This extra newline is harmless, so I'm not going to change all the callers immediately. Signed-off-by: Simon McVittie <smcv@debian.org>
* Prefix debug messages displayed with _dbus_verbose() with a timestamp.Ralf Habacker2016-05-131-0/+3
| | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=95191 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Display thread id in _dbus_verbose to be able to see threading issues.Ralf Habacker2016-05-131-11/+1
| | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=95191 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Rename function string_array_length() to _dbus_string_array_length() and ↵Ralf Habacker2016-02-121-0/+15
| | | | | | | move it to dbus-internals.c. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=92899 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* _dbus_test_oom_handling: allow disabling it as documentedSimon McVittie2015-12-021-0/+6
| | | | | | | | We documented DBUS_TEST_MALLOC_FAILURES=0 in HACKING, but it didn't actually work: we'd iterate from i=-1 to i=0. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=93194 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
* Fail to generate random bytes instead of falling back to rand()Simon McVittie2015-05-141-1/+13
| | | | | | | | | | This is more robust against broken setups where we run out of memory or cannot read /dev/urandom. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> [smcv: document @error] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Make UUID generation failableSimon McVittie2015-05-141-13/+32
| | | | | | | | | | | | | Previously, this would always succeed, but might use weak random numbers in rare failure cases. I don't think these UUIDs are security-sensitive, but if they're generated by a PRNG as weak as rand() (<= 32 bits of entropy), we certainly can't claim that they're universally unique. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90414 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> [smcv: document @error] Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* Merge branch 'dbus-1.8'Ralf Habacker2015-04-131-2/+2
|\ | | | | | | | | Conflicts: dbus/dbus-sysdeps-win.c
| * Add newline to verbose output in _dbus_trace_ref().Ralf Habacker2015-04-131-2/+2
| | | | | | | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=90004 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* | Add org.freedesktop.DBus.Verbose interface to dbus-daemon when compiled with ↵Ralf Habacker2015-02-131-0/+10
|/ | | | | | | | | | DBUS_ENABLE_VERBOSE_MODE. This interface contains methods 'EnableVerbose' and 'DisableVerbose' to control verbose mode on daemon runtime. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=88896 Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
* _dbus_write_uuid_file: factor out function to write a known UUIDSimon McVittie2014-04-281-7/+14
| | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=77941 Reviewed-by: Lennart Poettering
* _dbus_file_path_extract_elements_from_tail: don't misuse static variableSimon McVittie2013-08-301-14/+11
| | | | | | | | | If we _dbus_verbose() from more than one thread at the same time, we don't want to get into trouble with static variables (and I don't think micro-optimizing this function is really worth it anyway). Bug: https://bugs.freedesktop.org/show_bug.cgi?id=68610 Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de>
* tests to embedded tests: replaced in libdbusChengwei Yang2013-06-281-3/+3
| | | | | | Signed-off-by: Chengwei Yang <chengwei.yang@intel.com> Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=66291
* Make taking a global lock automatically initialize locking if neededSimon McVittie2013-06-171-2/+6
| | | | | | | | | | | | | | | | | | | This lets them be thread-safe by default, at the cost that they can now fail. init_uninitialized_locks() and init_global_locks() must now both reimplement the equivalent of _dbus_register_shutdown_func(), by using _dbus_platform_rmutex_lock() on the same underlying mutex around a call to _dbus_register_shutdown_func_unlocked(). This is because if they used the usual _DBUS_LOCK() API (as _dbus_register_shutdown_func() does), it would automatically try to initialize global locking, leading to infinite recursion. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk> Reviewed-by: Anas Nashif <anas.nashif@intel.com>
* Replace individual global-lock variables with an array of DBusRMutex *Simon McVittie2013-06-171-18/+1
| | | | | | | | | | | | | | | | | | | | | | This means we can use a much simpler code structure in data-slot allocators: instead of giving them a DBusRMutex ** at first-allocation, we can just give them an index into the array, which can be done statically. It doesn't make us any more thread-safe-by-default - the mutexes will only actually be used if threads were already initialized - but it's substantially better than nothing. These locks really do have to be recursive: for instance, internal_bus_get() calls dbus_bus_register() under the bus lock, and dbus_bus_register() can call _dbus_connection_close_possibly_shared(), which takes the bus lock. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=54972 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Alban Crequy <alban.crequy@collabora.co.uk> Reviewed-by: Ralf Habacker <ralf.habacker@freenet.de> Reviewed-by: Anas Nashif <anas.nashif@intel.com>
* Avoid using monotonic time in the DBUS_COOKIE_SHA1 authentication methodDavid Zeuthen2012-04-121-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | When libdbus-1 moved to using monotonic time support for the DBUS_COOKIE_SHA1 authentication was broken, in particular interoperability with non-libdbus-1 implementations such as GDBus. The problem is that if monotonic clocks are available in the OS, _dbus_get_current_time() will not return the number of seconds since the Epoch so using it for DBUS_COOKIE_SHA1 will violate the D-Bus specification. If both peers are using libdbus-1 it's not a problem since both ends will use the wrong time and thus agree. However, if the other end is another implementation and following the spec it will not work. First, we change _dbus_get_current_time() back so it always returns time since the Epoch and we then rename it _dbus_get_real_time() to make this clear. We then introduce _dbus_get_monotonic_time() and carefully make all current users of _dbus_get_current_time() use it, if applicable. During this audit, one of the callers, _dbus_generate_uuid(), was currently using monotonic time but it was decided to make it use real time instead. Signed-off-by: David Zeuthen <davidz@redhat.com> Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Bug: https://bugs.freedesktop.org/show_bug.cgi?id=48580
* _dbus_verbose_real: tidy conditional prototype to not break nestingSimon McVittie2012-02-211-4/+3
| | | | | | | | | The mismatched opening parenthesis caused vim syntax highlighting to consider every subsequent brace in the file to be an error, which was pretty annoying. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=46095 Reviewed-by: Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>
* Provide a hook to allow refcounting to be tracedSimon McVittie2012-02-131-0/+67
| | | | | | | | | | | | | | | | | | | | | This is designed to be used from a wrapper function, partly to supply the same arguments every time for a particular class of object, and partly to provide a more specific gdb breakpoint. It has several purposes: * when under gdb, provide a function which can be used in breakpoints * when not under valgrind and DBUS_MESSAGE_TRACE=1 is set, emit a _dbus_verbose when a message's refcount changes * when under valgrind and DBUS_MESSAGE_TRACE=1 is set, emit a VALGRIND_PRINTF_BACKTRACE when a message's refcount changes, which lets you see the complete history of each message to track down reference leaks Compile-time support is currently conditional on DBUS_ENABLE_VERBOSE_MODE, but could be separated out if desired. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=37286 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Lennart Poettering <lennart@poettering.net>
* _dbus_header_field_to_string: remove, unusedSimon McVittie2012-02-101-36/+0
| | | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39759 Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk> Reviewed-by: Lennart Poettering <lennart@poettering.net>
* Remove various never-used variablesSimon McVittie2011-08-051-1/+0
| | | | | Bug: https://bugs.freedesktop.org/show_bug.cgi?id=39231 Reviewed-by: Will Thompson <will.thompson@collabora.co.uk>
* Fixes for Visual Studio 2010 cmake generator - reported by Ray Satiro.Ralf Habacker2011-05-281-3/+0
|
* Make dbus-uuidgen atomicColin Walters2010-09-031-15/+1
| | | | | | | | | | | | | | | A Red Hat QA engineer hit in practice a race condition in dbus-uuidgen where it could leave an empty file. dbus-uuidgen (_dbus_create_uuid_file_exclusively) formerly created an empty file in the path to the uuid, then filled it in. At some point, the internal libdbus _dbus_string_save_to_file became atomic on Unix at least (doing the save to temp file, fsync(), rename() dance). So _dbus_create_uuid_file_exclusively doesn't need to create the file beforehand anymore. However, it *does* need the file to be world-readable, unlike all other consumers of _dbus_string_save_to_file. So add a "world_readable" argument.
* Wrap OutputDebugString for Windows CE builds, and add cast for MSVC.Marcus Brinkmann2010-07-191-1/+1
|
* Revert "Bug 28460 - Refactored dbus configuration access."Will Thompson2010-06-171-4/+3
| | | | | | This reverts commit 6f9077ee870ad02119facf83d1293301b4535c3b, which broke the build on Unix (see previous patch) and introduced a bunch of warnings.
* Bug 28460 - Refactored dbus configuration access.Ralf Habacker2010-06-141-3/+4
| | | | | | | | | | | | | | | | | | Libdbus uses several config variables. On unix these settings are read from environment variables by using _dbus_getenv. On other platforms like wince there are no environment variables available and _dbus_getenv needs an emulation for those plattforms (see dbus/dbus-sysdeps-wince-glue.c) To cleanup this emulation the appended patch adds a config api by adding _dbus_config_... functions. Also having all client config related functions listed in one header file provides a good overview about which config attributes are available. The default implementation retrieves the config values from environment variables. For other os this could be easily extended or replaced by.
* Consistently include <config.h> in all C source files and never in header files.Marcus Brinkmann2010-03-191-0/+2
|
* small fixes for DBUS_USE_OUTPUT_DEBUG_STRING codeRomain Pokrzywka2010-02-251-1/+2
|
* let dbus_verbose print file name, line number and function name if ↵Ralf Habacker2009-12-191-1/+55
| | | | available; this eases debugging.
* Avoid warnings on WindowsTor Lillqvist2009-12-011-9/+12
| | | | | | | | Remove unused functions, or put in #if 0 if potentially useful. Make internal functions used just in one file static. Use -Werror after all also on Windows. Construct the installation root from the location of the dbus DLL, not from the location of the program .exe of the process.
* dbus/dbus-internals.c: "#define inline" is only needed on MSVC, not mingw ↵Tor Lillqvist2009-11-301-1/+1
| | | | (cherry picked from commit 314e91e3ee2566477918a51dbddd9eb141b33a23)
* _dbus_verbose_real: (optionally) use OutputDebugString() (cherry picked from ↵Ralf Habacker2009-11-301-2/+29
| | | | commit fd6d354c47b4b8dc24ce32e31171568a8704e7d1)