25 #include "dbus-internals.h"
26 #include "dbus-protocol.h"
27 #include "dbus-marshal-basic.h"
28 #include "dbus-test.h"
33 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
215 fatal_warnings =
FALSE;
216 fatal_warnings_on_check_failed =
FALSE;
220 fatal_warnings =
TRUE;
221 fatal_warnings_on_check_failed =
TRUE;
225 fprintf(stderr,
"DBUS_FATAL_WARNINGS should be set to 0 or 1 if set, not '%s'",
252 va_start (args, format);
253 vfprintf (stderr, format, args);
282 va_start (args, format);
283 vfprintf (stderr, format, args);
286 if (fatal_warnings_on_check_failed)
293 #ifdef DBUS_ENABLE_VERBOSE_MODE
299 #define PTHREAD_IN_VERBOSE 0
300 #if PTHREAD_IN_VERBOSE
307 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
308 static char module_name[1024];
312 _dbus_verbose_init (
void)
314 if (!verbose_initted)
317 verbose = p !=
NULL && *p ==
'1';
318 verbose_initted =
TRUE;
319 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
321 char *last_period, *last_slash;
322 GetModuleFileName(0,module_name,
sizeof(module_name)-1);
323 last_period = _mbsrchr(module_name,
'.');
326 last_slash = _mbsrchr(module_name,
'\\');
328 strcpy(module_name,last_slash+1);
329 strcat(module_name,
": ");
341 #define DBUS_IS_DIR_SEPARATOR(c) (c == '\\' || c == '/')
343 #define DBUS_IS_DIR_SEPARATOR(c) (c == '/')
350 static char *_dbus_file_path_extract_elements_from_tail(
const char *file,
int level)
352 static int prefix = -1;
357 char *p = (
char *)file + strlen(file);
362 if (DBUS_IS_DIR_SEPARATOR(*p))
372 return (
char *)file+prefix;
381 _dbus_is_verbose_real (
void)
383 _dbus_verbose_init ();
396 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
397 _dbus_verbose_real (
const char *file,
399 const char *
function,
402 _dbus_verbose_real (
const char *format,
414 if (!_dbus_is_verbose_real())
417 #ifndef DBUS_USE_OUTPUT_DEBUG_STRING
421 #if PTHREAD_IN_VERBOSE
430 len = strlen (format);
431 if (format[len-1] ==
'\n')
436 va_start (args, format);
437 #ifdef DBUS_USE_OUTPUT_DEBUG_STRING
440 strcpy(buf,module_name);
441 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
442 sprintf (buf+strlen(buf),
"[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,
function);
444 vsprintf (buf+strlen(buf),format, args);
446 OutputDebugStringA(buf);
449 #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS
450 fprintf (stderr,
"[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,
function);
453 vfprintf (stderr, format, args);
467 _dbus_verbose_reset_real (
void)
469 verbose_initted =
FALSE;
497 memcpy (copy, str, len + 1);
520 memcpy (copy, mem, n_bytes);
543 for (len = 0; array[len] !=
NULL; ++len)
580 while (array[i] !=
NULL)
582 if (strcmp (array[i], str) == 0)
603 uuid->
as_uint32s[DBUS_UUID_LENGTH_WORDS - 1] = DBUS_UINT32_TO_BE (now);
625 _dbus_read_uuid_file_without_creating (
const DBusString *filename,
635 _DBUS_SET_OOM (error);
642 _DBUS_SET_OOM (error);
654 "UUID file '%s' should contain a hex string of length %d, not length %d, with no other text",
656 DBUS_UUID_LENGTH_HEX,
663 _DBUS_SET_OOM (error);
670 "UUID file '%s' contains invalid hex data",
678 "UUID file '%s' contains %d bytes of hex-encoded data instead of %d",
681 DBUS_UUID_LENGTH_BYTES);
690 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
695 _DBUS_ASSERT_ERROR_IS_SET (error);
702 _dbus_create_uuid_file_exclusively (
const DBusString *filename,
710 _DBUS_SET_OOM (error);
718 _DBUS_SET_OOM (error);
724 _DBUS_SET_OOM (error);
733 _DBUS_ASSERT_ERROR_IS_CLEAR (error);
737 _DBUS_ASSERT_ERROR_IS_SET (error);
760 if (_dbus_read_uuid_file_without_creating (filename, uuid, &read_error))
763 if (!create_if_not_found)
781 return _dbus_create_uuid_file_exclusively (filename, uuid, error);
786 static int machine_uuid_initialized_generation = 0;
812 #ifndef DBUS_BUILD_TESTS
818 "See the manual page for dbus-uuidgen to correct this issue.\n",
835 #ifdef DBUS_BUILD_TESTS
843 _dbus_header_field_to_string (
int header_field)
845 switch (header_field)
858 return "reply-serial";
860 return "destination";
871 #ifndef DBUS_DISABLE_CHECKS
874 "arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
875 "This is normally a bug in some application using the D-Bus library.\n";
878 #ifndef DBUS_DISABLE_ASSERT
893 const char *condition_text,
898 if (_DBUS_UNLIKELY (!condition))
900 _dbus_warn (
"%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n",
921 _dbus_warn (
"File \"%s\" line %d process %lu should not have been reached: %s\n",
927 #ifdef DBUS_BUILD_TESTS
929 run_failing_each_malloc (
int n_mallocs,
930 const char *description,
931 DBusTestMemoryFunction func,
936 while (n_mallocs >= 0)
938 _dbus_set_fail_alloc_counter (n_mallocs);
940 _dbus_verbose (
"\n===\n%s: (will fail malloc %d with %d failures)\n===\n",
941 description, n_mallocs,
942 _dbus_get_fail_alloc_failures ());
944 if (!(* func) (data))
969 _dbus_test_oom_handling (
const char *description,
970 DBusTestMemoryFunction func,
975 int max_failures_to_try;
982 _dbus_verbose (
"Running once to count mallocs\n");
984 if (!(* func) (data))
987 approx_mallocs =
_DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
989 _dbus_verbose (
"\n=================\n%s: about %d mallocs total\n=================\n",
990 description, approx_mallocs);
1000 _dbus_warn (
"couldn't parse '%s' as integer\n", setting);
1001 max_failures_to_try = v;
1005 max_failures_to_try = 4;
1008 i = setting ? max_failures_to_try - 1 : 1;
1009 while (i < max_failures_to_try)
1011 _dbus_set_fail_alloc_failures (i);
1012 if (!run_failing_each_malloc (approx_mallocs, description, func, data))
1017 _dbus_verbose (
"\n=================\n%s: all iterations passed\n=================\n",