]> git.eshelyaron.com Git - emacs.git/commitdiff
* net/dbus.el (dbus-name-owner-changed-handler): Make the function
authorMichael Albinus <michael.albinus@gmx.de>
Sun, 30 Dec 2007 15:51:18 +0000 (15:51 +0000)
committerMichael Albinus <michael.albinus@gmx.de>
Sun, 30 Dec 2007 15:51:18 +0000 (15:51 +0000)
resistent towards wrong parameters.
(dbus-handle-event): Propagate D-Bus errors only in the debug case.

lisp/ChangeLog
lisp/net/dbus.el

index 8ee6ac43f2ea307cd5073cd16e02b509a1a97084..5126ebe2d1029feca829f96bc150cf583fca48bd 100644 (file)
@@ -1,3 +1,9 @@
+2007-12-30  Michael Albinus  <michael.albinus@gmx.de>
+
+       * net/dbus.el (dbus-name-owner-changed-handler): Make the function
+       resistent towards wrong parameters.
+       (dbus-handle-event): Propagate D-Bus errors only in the debug case.
+
 2007-12-30  Richard Stallman  <rms@gnu.org>
 
        * cus-edit.el (custom-face-set): Call `face-spec-set' with FOR-DEFFACE.
index 75bcb8ed138edf30f372f565723041eb4ffe934f..1c1016aed97bc9e355e0e415e78562779019d2d9 100644 (file)
@@ -64,33 +64,50 @@ hash table."
      dbus-registered-functions-table)
     result))
 
-(defun dbus-name-owner-changed-handler (service old-owner new-owner)
+(defun dbus-name-owner-changed-handler (&rest args)
   "Reapplies all signal registrations to D-Bus.
 This handler is applied when a \"NameOwnerChanged\" signal has
 arrived.  SERVICE is the object name for which the name owner has
 been changed.  OLD-OWNER is the previous owner of SERVICE, or the
 empty string if SERVICE was not owned yet.  NEW-OWNER is the new
-owner of SERVICE, or the empty string if SERVICE looses any name owner."
+owner of SERVICE, or the empty string if SERVICE looses any name owner.
+
+usage: (dbus-name-owner-changed-handler service old-owner new-owner)"
   (save-match-data
-    ;; Check whether SERVICE is a known name.
-    (when (and (stringp service) (not (string-match "^:" service))
-              (stringp old-owner) (stringp new-owner))
-      (maphash
-       '(lambda (key value)
-         (dolist (elt value)
-           ;; key has the structure (BUS INTERFACE SIGNAL).
-           ;; elt has the structure (UNAME SERVICE PATH HANDLER).
-           (when (string-equal old-owner (car elt))
-             ;; Remove old key, and add new entry with changed name.
-             (dbus-unregister-signal (list key (cdr elt)))
-             ;; Maybe we could arrange the lists a little bit better
-             ;; that we don't need to extract every single element?
-             (dbus-register-signal
-              ;; BUS      SERVICE     PATH
-              (nth 0 key) (nth 1 elt) (nth 2 elt)
-              ;; INTERFACE SIGNAL     HANDLER
-              (nth 1 key) (nth 2 key) (nth 3 elt)))))
-       (copy-hash-table dbus-registered-functions-table)))))
+    ;; Check the arguments.  We should silently ignore it when they
+    ;; are wrong.
+    (if (and (= (length args) 3)
+            (stringp (car args))
+            (stringp (cadr args))
+            (stringp (caddr args)))
+       (let ((service (car args))
+             (old-owner (cadr args))
+             (new-owner (caddr args)))
+         ;; Check whether SERVICE is a known name.
+         (when (not (string-match "^:" service))
+           (maphash
+            '(lambda (key value)
+               (dolist (elt value)
+                 ;; key has the structure (BUS INTERFACE SIGNAL).
+                 ;; elt has the structure (UNAME SERVICE PATH HANDLER).
+                 (when (string-equal old-owner (car elt))
+                   ;; Remove old key, and add new entry with changed name.
+                   (dbus-unregister-signal (list key (cdr elt)))
+                   ;; Maybe we could arrange the lists a little bit better
+                   ;; that we don't need to extract every single element?
+                   (dbus-register-signal
+                    ;; BUS      SERVICE     PATH
+                    (nth 0 key) (nth 1 elt) (nth 2 elt)
+                    ;; INTERFACE SIGNAL     HANDLER
+                    (nth 1 key) (nth 2 key) (nth 3 elt)))))
+            (copy-hash-table dbus-registered-functions-table))))
+      ;; The error is reported only in debug mode.
+      (when  dbus-debug
+       (signal
+        'dbus-error
+        (cons
+         (format "Wrong arguments of %s.NameOwnerChanged" dbus-interface-dbus)
+         args))))))
 
 ;; Register the handler.
 (condition-case nil
@@ -148,11 +165,11 @@ part of the event, is called with arguments ARGS."
   (interactive "e")
   ;; We don't want to raise an error, because this function is called
   ;; in the event handling loop.
-  (condition-case nil
+  (condition-case err
       (progn
        (dbus-check-event event)
        (apply (nth 6 event) (nthcdr 7 event)))
-    (dbus-error)))
+    (dbus-error (when dbus-debug (signal (car err) (cdr err))))))
 
 (defun dbus-event-bus-name (event)
   "Return the bus name the event is coming from.