+void
+bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...) _DBUS_GNUC_PRINTF (3, 4);
+
+void
+bus_context_log (BusContext *context, DBusSystemLogSeverity severity, const char *msg, ...)
+{
+ va_list args;
+
+ if (!context->syslog)
+ {
+ /* we're not syslogging; just output to stderr */
+ va_start (args, msg);
+ vfprintf (stderr, msg, args);
+ fprintf (stderr, "\n");
+ va_end (args);
+ return;
+ }
+
+ va_start (args, msg);
+
+ if (context->log_prefix)
+ {
+ DBusString full_msg;
+
+ if (!_dbus_string_init (&full_msg))
+ goto out;
+ if (!_dbus_string_append (&full_msg, context->log_prefix))
+ goto oom_out;
+ if (!_dbus_string_append_printf_valist (&full_msg, msg, args))
+ goto oom_out;
+
+ _dbus_system_log (severity, "%s", _dbus_string_get_const_data (&full_msg));
+ oom_out:
+ _dbus_string_free (&full_msg);
+ }
+ else
+ _dbus_system_logv (severity, msg, args);
+
+out:
+ va_end (args);
+}
+
+static inline const char *
+nonnull (const char *maybe_null,
+ const char *if_null)
+{
+ return (maybe_null ? maybe_null : if_null);
+}
+
+/*
+ * Log something about a message, usually that it was rejected.
+ */
+static void
+complain_about_message (BusContext *context,
+ const char *error_name,
+ const char *complaint,
+ int matched_rules,
+ DBusMessage *message,
+ DBusConnection *sender,
+ DBusConnection *proposed_recipient,
+ dbus_bool_t requested_reply,
+ dbus_bool_t log,
+ DBusError *error)
+{
+ DBusError stack_error = DBUS_ERROR_INIT;
+ const char *sender_name;
+ const char *sender_loginfo;
+ const char *proposed_recipient_loginfo;
+
+ if (error == NULL && !log)
+ return;
+
+ if (sender != NULL)
+ {
+ sender_name = bus_connection_get_name (sender);
+ sender_loginfo = bus_connection_get_loginfo (sender);
+ }
+ else
+ {
+ sender_name = "(unset)";
+ sender_loginfo = "(bus)";
+ }
+
+ if (proposed_recipient != NULL)
+ proposed_recipient_loginfo = bus_connection_get_loginfo (proposed_recipient);
+ else
+ proposed_recipient_loginfo = "bus";
+
+ dbus_set_error (&stack_error, error_name,
+ "%s, %d matched rules; type=\"%s\", sender=\"%s\" (%s) "
+ "interface=\"%s\" member=\"%s\" error name=\"%s\" "
+ "requested_reply=\"%d\" destination=\"%s\" (%s)",
+ complaint,
+ matched_rules,
+ dbus_message_type_to_string (dbus_message_get_type (message)),
+ sender_name,
+ sender_loginfo,
+ nonnull (dbus_message_get_interface (message), "(unset)"),
+ nonnull (dbus_message_get_member (message), "(unset)"),
+ nonnull (dbus_message_get_error_name (message), "(unset)"),
+ requested_reply,
+ nonnull (dbus_message_get_destination (message), DBUS_SERVICE_DBUS),
+ proposed_recipient_loginfo);
+
+ /* If we hit OOM while setting the error, this will syslog "out of memory"
+ * which is itself an indication that something is seriously wrong */
+ if (log)
+ bus_context_log (context, DBUS_SYSTEM_LOG_SECURITY, "%s",
+ stack_error.message);
+
+ dbus_move_error (&stack_error, error);
+}
+