From: Michael Albinus Date: Tue, 9 Jul 2024 15:37:50 +0000 (+0200) Subject: Warn if D-Bus error "InteractiveAuthorizationRequired" occurs X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=885b834aa3644fcad2541f4aaddc52cc4cf60710;p=emacs.git Warn if D-Bus error "InteractiveAuthorizationRequired" occurs * lisp/net/dbus.el (dbus-error-interactive-authorization-required): New defconst. (dbus-warn-interactive-authorization-required): New defun. (dbus-event-error-functions): Add it. (cherry picked from commit acfc3884bf58f7b407c42c8751affbcb365eb105) --- diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el index a50f3a93938..8426d04fefd 100644 --- a/lisp/net/dbus.el +++ b/lisp/net/dbus.el @@ -192,6 +192,10 @@ See /usr/include/dbus-1.0/dbus/dbus-protocol.h.") (defconst dbus-error-failed (concat dbus-error-dbus ".Failed") "A generic error; \"something went wrong\" - see the error message for more.") +(defconst dbus-error-interactive-authorization-required + (concat dbus-error-dbus ".InteractiveAuthorizationRequired") + "Interactive authentication required.") + (defconst dbus-error-invalid-args (concat dbus-error-dbus ".InvalidArgs") "Invalid arguments passed to a method call.") @@ -243,7 +247,9 @@ Otherwise, return result of last form in BODY, or all other errors." (progn ,@body) (dbus-error (when dbus-debug (signal (car err) (cdr err)))))) -(defvar dbus-event-error-functions '(dbus-notice-synchronous-call-errors) +(defvar dbus-event-error-functions + '(dbus-notice-synchronous-call-errors + dbus-warn-interactive-authorization-required) "Functions to be called when a D-Bus error happens in the event handler. Every function must accept two arguments, the event and the error variable caught in `condition-case' by `dbus-error'.") @@ -282,6 +288,18 @@ The result will be made available in `dbus-return-values-table'." (setcar result :error) (setcdr result er)))) +(defun dbus-warn-interactive-authorization-required (ev er) + "Detect `dbus-error-interactive-authorization-required'." + (when (string-equal (cadr er) dbus-error-interactive-authorization-required) + (lwarn 'dbus :warning "%S" (cdr er)) + (let* ((key (list :serial + (dbus-event-bus-name ev) + (dbus-event-serial-number ev))) + (result (gethash key dbus-return-values-table))) + (when (consp result) + (setcar result :complete) + (setcdr result nil))))) + (defun dbus-call-method (bus service path interface method &rest args) "Call METHOD on the D-Bus BUS.