Skip to content

Commit

Permalink
lib: Improve cockpit.dbus() debug messages
Browse files Browse the repository at this point in the history
- Show the D-Bus client name, as we usually have lots of D-Bus clients,
  and it's otherwise impossible to know to which one the message
  applies.
- Stringify the JSON objects, so that they get printed properly in our
  test logs.
- Log calls to .close(), and log rejected outstanding calls.
  • Loading branch information
martinpitt committed Sep 13, 2023
1 parent bc3ed48 commit 45b389f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pkg/lib/cockpit.js
Original file line number Diff line number Diff line change
Expand Up @@ -3242,16 +3242,19 @@ function factory() {
this.notify = notify;

function close_perform(options) {
dbus_debug("dbus close_perform:", name, JSON.stringify(options));
closed = options.problem || "disconnected";
const outstanding = calls;
calls = { };
for (const id in outstanding) {
dbus_debug("... rejecting outstanding call", id);
outstanding[id].reject(new DBusError(closed, options.message));
}
self.dispatchEvent("close", options);
}

this.close = function close(options) {
dbus_debug("dbus close():", name, JSON.stringify(options), "have channel:", !!channel);
if (typeof options == "string")
options = { problem: options };
if (!options)
Expand All @@ -3263,12 +3266,12 @@ function factory() {
};

function on_ready(event, message) {
dbus_debug("dbus ready:", options);
dbus_debug("dbus on_ready:", name, JSON.stringify(options));
self.unique_name = message["unique-name"];
}

function on_close(event, options) {
dbus_debug("dbus close:", options);
dbus_debug("dbus on_close:", name, JSON.stringify(options));
channel.removeEventListener("ready", on_ready);
channel.removeEventListener("message", on_message);
channel.removeEventListener("close", on_close);
Expand Down

0 comments on commit 45b389f

Please sign in to comment.