/** * Prints a warning message to stderr * if the user has enabled verbose mode. * This is the real function implementation, * use _dbus_verbose() macro in code. * * @param format printf-style format string. */ void _dbus_verbose_real (const char *format, ...) { va_list args; static dbus_bool_t need_pid = TRUE; int len; /* things are written a bit oddly here so that * in the non-verbose case we just have the one * conditional and return immediately. */ if (!_dbus_is_verbose_real()) return; #ifndef DBUS_USE_OUTPUT_DEBUG_STRING /* Print out pid before the line */ if (need_pid) { #if PTHREAD_IN_VERBOSE fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), pthread_self ()); #else fprintf (stderr, "%lu: ", _dbus_pid_for_log ()); #endif } #endif /* Only print pid again if the next line is a new line */ len = strlen (format); if (format[len-1] == '\n') need_pid = TRUE; else need_pid = FALSE; va_start (args, format); #ifdef DBUS_USE_OUTPUT_DEBUG_STRING { char buf[1024]; strcpy(buf,module_name); vsprintf (buf+strlen(buf),format, args); va_end (args); OutputDebugString(buf); } #else vfprintf (stderr, format, args); va_end (args); fflush (stderr); #endif }
/** * Internals of _dbus_assert_not_reached(); it's a function * rather than a macro with the inline code so * that the assertion failure blocks don't show up * in test suite coverage, and to shrink code size. * * @param explanation what was reached that shouldn't have been * @param file file the assertion is in * @param line line the assertion is in */ void _dbus_real_assert_not_reached (const char *explanation, const char *file, int line) { _dbus_warn ("File \"%s\" line %d process %lu should not have been reached: %s\n", file, line, _dbus_pid_for_log (), explanation); _dbus_abort (); }
/** * Prints a warning message to stderr * if the user has enabled verbose mode. * This is the real function implementation, * use _dbus_verbose() macro in code. * * @param format printf-style format string. */ void _dbus_verbose_real (const char *format, ...) { va_list args; static dbus_bool_t need_pid = TRUE; int len; /* things are written a bit oddly here so that * in the non-verbose case we just have the one * conditional and return immediately. */ if (!_dbus_is_verbose_real()) return; /* Print out pid before the line */ if (need_pid) { #if PTHREAD_IN_VERBOSE fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), pthread_self ()); #else fprintf (stderr, "%lu: ", _dbus_pid_for_log ()); #endif } /* Only print pid again if the next line is a new line */ len = strlen (format); if (format[len-1] == '\n') need_pid = TRUE; else need_pid = FALSE; va_start (args, format); vfprintf (stderr, format, args); va_end (args); fflush (stderr); }
/** * Internals of _dbus_assert(); it's a function * rather than a macro with the inline code so * that the assertion failure blocks don't show up * in test suite coverage, and to shrink code size. * * @param condition TRUE if assertion succeeded * @param condition_text condition as a string * @param file file the assertion is in * @param line line the assertion is in * @param func function the assertion is in */ void _dbus_real_assert (dbus_bool_t condition, const char *condition_text, const char *file, int line, const char *func) { if (_DBUS_UNLIKELY (!condition)) { _dbus_warn ("%lu: assertion failed \"%s\" file \"%s\" line %d function %s\n", _dbus_pid_for_log (), condition_text, file, line, func); _dbus_abort (); } }
/** * Aborts the program with SIGABRT (dumping core). */ void _dbus_abort (void) { const char *s; _dbus_print_backtrace (); s = _dbus_getenv ("DBUS_BLOCK_ON_ABORT"); if (s && *s) { /* don't use _dbus_warn here since it can _dbus_abort() */ fprintf (stderr, " Process %lu sleeping for gdb attach\n", _dbus_pid_for_log ()); _dbus_sleep_milliseconds (1000 * 180); } abort (); _dbus_exit (1); /* in case someone manages to ignore SIGABRT ? */ }
/** * Prints a "critical" warning to stderr when an assertion fails; * differs from _dbus_warn primarily in that it prefixes the pid and * defaults to fatal. This should be used only when a programming * error has been detected. (NOT for unavoidable errors that an app * might handle - those should be returned as DBusError.) Calling this * means "there is a bug" */ void _dbus_warn_check_failed(const char *format, ...) { va_list args; if (!warn_initted) init_warnings (); fprintf (stderr, "process %lu: ", _dbus_pid_for_log ()); va_start (args, format); vfprintf (stderr, format, args); va_end (args); if (fatal_warnings_on_check_failed) { fflush (stderr); _dbus_abort (); } }
/** * Prints a warning message to stderr * if the user has enabled verbose mode. * This is the real function implementation, * use _dbus_verbose() macro in code. * * @param format printf-style format string. */ void _dbus_verbose_real ( #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS const char *file, const int line, const char *function, #endif const char *format, ...) { va_list args; static dbus_bool_t need_pid = TRUE; int len; /* things are written a bit oddly here so that * in the non-verbose case we just have the one * conditional and return immediately. */ if (!_dbus_is_verbose_real()) return; #ifndef DBUS_USE_OUTPUT_DEBUG_STRING /* Print out pid before the line */ if (need_pid) { #if PTHREAD_IN_VERBOSE fprintf (stderr, "%lu: 0x%lx: ", _dbus_pid_for_log (), pthread_self ()); #else fprintf (stderr, "%lu: ", _dbus_pid_for_log ()); #endif } #endif /* Only print pid again if the next line is a new line */ len = strlen (format); if (format[len-1] == '\n') need_pid = TRUE; else need_pid = FALSE; va_start (args, format); #ifdef DBUS_USE_OUTPUT_DEBUG_STRING { char buf[1024]; strcpy(buf,module_name); #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS sprintf (buf+strlen(buf), "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function); #endif vsprintf (buf+strlen(buf),format, args); va_end (args); OutputDebugStringA(buf); } #else #ifdef DBUS_CPP_SUPPORTS_VARIABLE_MACRO_ARGUMENTS fprintf (stderr, "[%s(%d):%s] ",_dbus_file_path_extract_elements_from_tail(file,2),line,function); #endif vfprintf (stderr, format, args); va_end (args); fflush (stderr); #endif }