va_end (args);
}
+static dbus_bool_t verbose_initted = FALSE;
+
/**
* Prints a warning message to stderr
* if the user has enabled verbose mode.
{
va_list args;
static dbus_bool_t verbose = TRUE;
- static dbus_bool_t initted = FALSE;
-
+ static dbus_bool_t need_pid = TRUE;
+
/* things are written a bit oddly here so that
* in the non-verbose case we just have the one
* conditional and return immediately.
if (!verbose)
return;
- if (!initted)
+ if (!verbose_initted)
{
verbose = _dbus_getenv ("DBUS_VERBOSE") != NULL;
- initted = TRUE;
+ verbose_initted = TRUE;
if (!verbose)
return;
}
+
+ if (need_pid)
+ {
+ int len;
+
+ fprintf (stderr, "%lu: ", _dbus_getpid ());
+
+ len = strlen (format);
+ if (format[len-1] == '\n')
+ need_pid = TRUE;
+ else
+ need_pid = FALSE;
+ }
va_start (args, format);
vfprintf (stderr, format, args);
}
/**
+ * Reinitializes the verbose logging code, used
+ * as a hack in dbus-spawn.c so that a child
+ * process re-reads its pid
+ *
+ */
+void
+_dbus_verbose_reset_real (void)
+{
+ verbose_initted = FALSE;
+}
+
+/**
* Duplicates a string. Result must be freed with
* dbus_free(). Returns #NULL if memory allocation fails.
* If the string to be duplicated is #NULL, returns #NULL.
char*
_dbus_strdup (const char *str)
{
- int len;
+ size_t len;
char *copy;
if (str == NULL)
}
/**
+ * Duplicates a block of memory. Returns
+ * #NULL on failure.
+ *
+ * @param mem memory to copy
+ * @param n_bytes number of bytes to copy
+ * @returns the copy
+ */
+void*
+_dbus_memdup (const void *mem,
+ size_t n_bytes)
+{
+ void *copy;
+
+ copy = dbus_malloc (n_bytes);
+ if (copy == NULL)
+ return NULL;
+
+ memcpy (copy, mem, n_bytes);
+
+ return copy;
+}
+
+/**
* Duplicates a string array. Result may be freed with
* dbus_free_string_array(). Returns #NULL if memory allocation fails.
* If the array to be duplicated is #NULL, returns #NULL.
}
}
+/**
+ * Returns a string describing the given name.
+ *
+ * @param header_field the field to describe
+ * @returns a constant string describing the field
+ */
+const char *
+_dbus_header_field_to_string (int header_field)
+{
+ switch (header_field)
+ {
+ case DBUS_HEADER_FIELD_INVALID:
+ return "invalid";
+ case DBUS_HEADER_FIELD_PATH:
+ return "path";
+ case DBUS_HEADER_FIELD_INTERFACE:
+ return "interface";
+ case DBUS_HEADER_FIELD_MEMBER:
+ return "member";
+ case DBUS_HEADER_FIELD_ERROR_NAME:
+ return "error-name";
+ case DBUS_HEADER_FIELD_REPLY_SERIAL:
+ return "reply-serial";
+ case DBUS_HEADER_FIELD_SERVICE:
+ return "service";
+ case DBUS_HEADER_FIELD_SENDER_SERVICE:
+ return "sender-service";
+ default:
+ return "unknown";
+ }
+}
+
+#ifndef DBUS_DISABLE_CHECKS
+/** String used in _dbus_return_if_fail macro */
+const char _dbus_return_if_fail_warning_format[] =
+"Arguments to %s() were incorrect, assertion \"%s\" failed in file %s line %d.\n"
+"This is normally a bug in some application using the D-BUS library.\n";
+#endif
+
#ifndef DBUS_DISABLE_ASSERT
/**
* Internals of _dbus_assert(); it's a function
{
if (!condition)
{
- _dbus_warn ("Assertion failed \"%s\" file \"%s\" line %d\n",
- condition_text, file, line);
+ _dbus_warn ("Assertion failed \"%s\" file \"%s\" line %d process %lu\n",
+ condition_text, file, line, _dbus_getpid ());
_dbus_abort ();
}
}
const char *file,
int line)
{
- _dbus_warn ("File \"%s\" line %d should not have been reached: %s\n",
- file, line, explanation);
+ _dbus_warn ("File \"%s\" line %d process %lu should not have been reached: %s\n",
+ file, line, _dbus_getpid (), explanation);
_dbus_abort ();
}
#endif /* DBUS_DISABLE_ASSERT */
_dbus_set_fail_alloc_counter (_DBUS_INT_MAX);
+ _dbus_verbose ("Running once to count mallocs\n");
+
if (!(* func) (data))
return FALSE;
approx_mallocs = _DBUS_INT_MAX - _dbus_get_fail_alloc_counter ();
- _dbus_verbose ("=================\n%s: about %d mallocs total\n=================\n",
+ _dbus_verbose ("\n=================\n%s: about %d mallocs total\n=================\n",
description, approx_mallocs);
_dbus_set_fail_alloc_failures (1);
if (!run_failing_each_malloc (approx_mallocs, description, func, data))
return FALSE;
- _dbus_verbose ("=================\n%s: all iterations passed\n=================\n",
+ _dbus_verbose ("\n=================\n%s: all iterations passed\n=================\n",
description);
return TRUE;