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
201 fatal_warnings =
FALSE;
202 fatal_warnings_on_check_failed =
FALSE;
206 fatal_warnings =
TRUE;
207 fatal_warnings_on_check_failed =
TRUE;
211 fprintf(stderr,
"DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'",
238 va_start (args, format);
239 vfprintf (stderr, format, args);
268 va_start (args, format);
269 vfprintf (stderr, format, args);
272 if (fatal_warnings_on_check_failed)
279 #ifdef DBUS_ENABLE_VERBOSE_MODE
285 #define PTHREAD_IN_VERBOSE 0
286 #if PTHREAD_IN_VERBOSE
290 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
291 static char module_name[1024];
295 _dbus_verbose_init (
void)
297 if (!verbose_initted)
300 verbose = p !=
NULL && *p ==
'1';
301 verbose_initted =
TRUE;
302 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
304 char *last_period, *last_slash;
305 GetModuleFileName(0,module_name,
sizeof(module_name)-1);
306 last_period = _mbsrchr(module_name,
'.');
309 last_slash = _mbsrchr(module_name,
'\\');
311 strcpy(module_name,last_slash+1);
312 strcat(module_name,
": ");
324 #define DBUS_IS_DIR_SEPARATOR(c) (c == '\\' || c == '/')
326 #define DBUS_IS_DIR_SEPARATOR(c) (c == '/')
333 static char *_dbus_file_path_extract_elements_from_tail(
const char *file,
int level)
336 char *p = (
char *)file + strlen(file);
341 if (DBUS_IS_DIR_SEPARATOR(*p))
351 return (
char *)file+prefix;
360 _dbus_is_verbose_real (
void)
362 _dbus_verbose_init ();
376 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
379 const char *
function,
392 if (!_dbus_is_verbose_real())
395 #ifndef DBUS_USE_OUTPUT_DEBUG_STRING
399 #if PTHREAD_IN_VERBOSE
408 len = strlen (format);
409 if (format[len-1] ==
'\n')
414 va_start (args, format);
415 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
418 strcpy(buf,module_name);
419 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
420 sprintf (buf+strlen(buf),
"[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,
function);
422 vsprintf (buf+strlen(buf),format, args);
424 OutputDebugStringA(buf);
427 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
428 fprintf (stderr,
"[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,
function);
431 vfprintf (stderr, format, args);
445 _dbus_verbose_reset_real (
void)
447 verbose_initted =
FALSE;
451 _dbus_trace_ref (
const char *obj_name,
464 if (old_refcount == -1)
492 _dbus_warn (
"%s should be 0 or 1 if set, not '%s'", env_var, s);
498 if (old_refcount == -1)
500 VALGRIND_PRINTF_BACKTRACE (
"%s %p ref stolen (%s)",
502 _dbus_verbose (
"%s %p ref stolen (%s)",
507 VALGRIND_PRINTF_BACKTRACE (
"%s %p %d -> %d refs (%s)",
509 old_refcount, new_refcount, why);
510 _dbus_verbose (
"%s %p %d -> %d refs (%s)",
511 obj_name, obj, old_refcount, new_refcount, why);
541 memcpy (copy, str, len + 1);
564 memcpy (copy, mem, n_bytes);
587 for (len = 0; array[len] !=
NULL; ++len)
624 while (array[i] !=
NULL)
626 if (strcmp (array[i], str) == 0)
650 uuid->
as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
672 _dbus_read_uuid_file_without_creating (
const DBusString *filename,
682 _DBUS_SET_OOM (error);
689 _DBUS_SET_OOM (error);
698 if (_dbus_string_get_length (&contents) != DBUS_UUID_LENGTH_HEX)
701 "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
702 _dbus_string_get_const_data (filename),
703 DBUS_UUID_LENGTH_HEX,
704 _dbus_string_get_length (&contents));
710 _DBUS_SET_OOM (error);
717 "UUID file '%s' contains invalid hex data",
718 _dbus_string_get_const_data (filename));
722 if (_dbus_string_get_length (&decoded) != DBUS_UUID_LENGTH_BYTES)
725 "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
726 _dbus_string_get_const_data (filename),
727 _dbus_string_get_length (&decoded),
728 DBUS_UUID_LENGTH_BYTES);
737 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
742 _DBUS_ASSERT_ERROR_IS_SET (error);
749 _dbus_create_uuid_file_exclusively (
const DBusString *filename,
757 _DBUS_SET_OOM (error);
765 _DBUS_SET_OOM (error);
771 _DBUS_SET_OOM (error);
780 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
784 _DBUS_ASSERT_ERROR_IS_SET (error);
807 if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error))
810 if (!create_if_not_found)
828 return _dbus_create_uuid_file_exclusively (filename, uuid, error);
833 static int machine_uuid_initialized_generation = 0;
861 #ifndef DBUS_ENABLE_EMBEDDED_TESTS
867 "See the manual page for dbus-uuidgen to correct this issue.\n",
884 #ifndef DBUS_DISABLE_CHECKS
887 "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
888 "This is normally a bug in some application using the D-Bus library.\n";
891 #ifndef DBUS_DISABLE_ASSERT
906 const char *condition_text,
911 if (_DBUS_UNLIKELY (!condition))
913 _dbus_warn (
"%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n",
934 _dbus_warn (
"File \"%s\" line %d process %lu should not have been reached: %s\n",
940 #ifdef DBUS_ENABLE_EMBEDDED_TESTS
942 run_failing_each_malloc (
int n_mallocs,
943 const char *description,
944 DBusTestMemoryFunction func,
949 while (n_mallocs >= 0)
951 _dbus_set_fail_alloc_counter (n_mallocs);
953 _dbus_verbose (
"\n===\n%s: (will fail malloc %d with %d failures)\n===\n",
954 description, n_mallocs,
955 _dbus_get_fail_alloc_failures ());
957 if (!(* func) (data))
982 _dbus_test_oom_handling (
const char *description,
983 DBusTestMemoryFunction func,
988 int max_failures_to_try;
995 _dbus_verbose (
"Running once to count mallocs\n");
997 if (!(* func) (data))
1000 approx_mallocs =
_DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
1002 _dbus_verbose (
"\n=================\n%s: about %d mallocs total\n=================\n",
1003 description, approx_mallocs);
1006 if (setting !=
NULL)
1013 _dbus_warn (
"couldn't parse '%s' as integer\n", setting);
1014 max_failures_to_try = v;
1018 max_failures_to_try = 4;
1021 i = setting ? max_failures_to_try - 1 : 1;
1022 while (i < max_failures_to_try)
1024 _dbus_set_fail_alloc_failures (i);
1025 if (!run_failing_each_malloc (approx_mallocs, description, func, data))
1030 _dbus_verbose (
"\n=================\n%s: all iterations passed\n=================\n",