25 #include "dbus-internals.h"
26 #include "dbus-protocol.h"
27 #include "dbus-marshal-basic.h"
28 #include "dbus-test.h"
29 #include "dbus-valgrind-internal.h"
34 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
216 fatal_warnings =
FALSE;
217 fatal_warnings_on_check_failed =
FALSE;
221 fatal_warnings =
TRUE;
222 fatal_warnings_on_check_failed =
TRUE;
226 fprintf(stderr,
"DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'",
253 va_start (args, format);
254 vfprintf (stderr, format, args);
283 va_start (args, format);
284 vfprintf (stderr, format, args);
287 if (fatal_warnings_on_check_failed)
294 #ifdef DBUS_ENABLE_VERBOSE_MODE
300 #define PTHREAD_IN_VERBOSE 0
301 #if PTHREAD_IN_VERBOSE
305 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
306 static char module_name[1024];
310 _dbus_verbose_init (
void)
312 if (!verbose_initted)
315 verbose = p !=
NULL && *p ==
'1';
316 verbose_initted =
TRUE;
317 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
319 char *last_period, *last_slash;
320 GetModuleFileName(0,module_name,
sizeof(module_name)-1);
321 last_period = _mbsrchr(module_name,
'.');
324 last_slash = _mbsrchr(module_name,
'\\');
326 strcpy(module_name,last_slash+1);
327 strcat(module_name,
": ");
339 #define DBUS_IS_DIR_SEPARATOR(c) (c == '\\' || c == '/')
341 #define DBUS_IS_DIR_SEPARATOR(c) (c == '/')
348 static char *_dbus_file_path_extract_elements_from_tail(
const char *file,
int level)
350 static int prefix = -1;
354 char *p = (
char *)file + strlen(file);
359 if (DBUS_IS_DIR_SEPARATOR(*p))
369 return (
char *)file+prefix;
378 _dbus_is_verbose_real (
void)
380 _dbus_verbose_init ();
394 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
397 const char *
function,
410 if (!_dbus_is_verbose_real())
413 #ifndef DBUS_USE_OUTPUT_DEBUG_STRING
417 #if PTHREAD_IN_VERBOSE
426 len = strlen (format);
427 if (format[len-1] ==
'\n')
432 va_start (args, format);
433 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
436 strcpy(buf,module_name);
437 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
438 sprintf (buf+strlen(buf),
"[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,
function);
440 vsprintf (buf+strlen(buf),format, args);
442 OutputDebugStringA(buf);
445 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
446 fprintf (stderr,
"[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,
function);
449 vfprintf (stderr, format, args);
463 _dbus_verbose_reset_real (
void)
465 verbose_initted =
FALSE;
469 _dbus_trace_ref (
const char *obj_name,
482 if (old_refcount == -1)
510 _dbus_warn (
"%s should be 0 or 1 if set, not '%s'", env_var, s);
516 if (old_refcount == -1)
518 VALGRIND_PRINTF_BACKTRACE (
"%s %p ref stolen (%s)",
520 _dbus_verbose (
"%s %p ref stolen (%s)",
525 VALGRIND_PRINTF_BACKTRACE (
"%s %p %d -> %d refs (%s)",
527 old_refcount, new_refcount, why);
528 _dbus_verbose (
"%s %p %d -> %d refs (%s)",
529 obj_name, obj, old_refcount, new_refcount, why);
559 memcpy (copy, str, len + 1);
582 memcpy (copy, mem, n_bytes);
605 for (len = 0; array[len] !=
NULL; ++len)
642 while (array[i] !=
NULL)
644 if (strcmp (array[i], str) == 0)
668 uuid->
as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
690 _dbus_read_uuid_file_without_creating (
const DBusString *filename,
700 _DBUS_SET_OOM (error);
707 _DBUS_SET_OOM (error);
719 "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
721 DBUS_UUID_LENGTH_HEX,
728 _DBUS_SET_OOM (error);
735 "UUID file '%s' contains invalid hex data",
743 "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
746 DBUS_UUID_LENGTH_BYTES);
755 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
760 _DBUS_ASSERT_ERROR_IS_SET (error);
767 _dbus_create_uuid_file_exclusively (
const DBusString *filename,
775 _DBUS_SET_OOM (error);
783 _DBUS_SET_OOM (error);
789 _DBUS_SET_OOM (error);
798 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
802 _DBUS_ASSERT_ERROR_IS_SET (error);
825 if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error))
828 if (!create_if_not_found)
846 return _dbus_create_uuid_file_exclusively (filename, uuid, error);
851 static int machine_uuid_initialized_generation = 0;
877 #ifndef DBUS_BUILD_TESTS
883 "See the manual page for dbus-uuidgen to correct this issue.\n",
900 #ifndef DBUS_DISABLE_CHECKS
903 "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
904 "This is normally a bug in some application using the D-Bus library.\n";
907 #ifndef DBUS_DISABLE_ASSERT
922 const char *condition_text,
927 if (_DBUS_UNLIKELY (!condition))
929 _dbus_warn (
"%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n",
950 _dbus_warn (
"File \"%s\" line %d process %lu should not have been reached: %s\n",
956 #ifdef DBUS_BUILD_TESTS
958 run_failing_each_malloc (
int n_mallocs,
959 const char *description,
960 DBusTestMemoryFunction func,
965 while (n_mallocs >= 0)
967 _dbus_set_fail_alloc_counter (n_mallocs);
969 _dbus_verbose (
"\n===\n%s: (will fail malloc %d with %d failures)\n===\n",
970 description, n_mallocs,
971 _dbus_get_fail_alloc_failures ());
973 if (!(* func) (data))
998 _dbus_test_oom_handling (
const char *description,
999 DBusTestMemoryFunction func,
1003 const char *setting;
1004 int max_failures_to_try;
1011 _dbus_verbose (
"Running once to count mallocs\n");
1013 if (!(* func) (data))
1016 approx_mallocs =
_DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
1018 _dbus_verbose (
"\n=================\n%s: about %d mallocs total\n=================\n",
1019 description, approx_mallocs);
1022 if (setting !=
NULL)
1029 _dbus_warn (
"couldn't parse '%s' as integer\n", setting);
1030 max_failures_to_try = v;
1034 max_failures_to_try = 4;
1037 i = setting ? max_failures_to_try - 1 : 1;
1038 while (i < max_failures_to_try)
1040 _dbus_set_fail_alloc_failures (i);
1041 if (!run_failing_each_malloc (approx_mallocs, description, func, data))
1046 _dbus_verbose (
"\n=================\n%s: all iterations passed\n=================\n",