* dbus/dbus-sysdeps.c (_dbus_user_at_console): fix memleak in OOM.
authorOlivier Andrieu <oliv__a@users.sourceforge.net>
Fri, 17 Sep 2004 09:14:49 +0000 (09:14 +0000)
committerOlivier Andrieu <oliv__a@users.sourceforge.net>
Fri, 17 Sep 2004 09:14:49 +0000 (09:14 +0000)
* doc/busconfig.dtd: update the DTD for the at_console attribute.

* bus/driver.c (bus_driver_handle_hello): correctly handle Hello
messages after the first one (bug #1389).

* bus/dispatch.c (check_double_hello_message): add a test case for the
double hello message bug.  (check_existent_service_activation): fix
check of spawning error.

ChangeLog
bus/dispatch.c
bus/driver.c
dbus/dbus-sysdeps.c
doc/busconfig.dtd

index 718218d..b96e8ae 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2004-09-17  Olivier Andrieu  <oliv__a@users.sourceforge.net>
+
+       * dbus/dbus-sysdeps.c (_dbus_user_at_console): fix memleak in OOM.
+
+       * doc/busconfig.dtd: update the DTD for the at_console attribute.
+
+       * bus/driver.c (bus_driver_handle_hello): correctly handle Hello
+       messages after the first one (bug #1389).
+       
+       * bus/dispatch.c (check_double_hello_message): add a test case for
+       the double hello message bug.
+       (check_existent_service_activation): fix check of spawning error.
+       
 2004-09-16  David Zeuthen  <david@fubar.dk>
 
        * python/dbus_bindings.pyx.in: Add support for int64 and uint64
index f808a8e..54e4583 100644 (file)
@@ -934,6 +934,96 @@ check_hello_message (BusContext     *context,
  * but the correct thing may include OOM errors.
  */
 static dbus_bool_t
+check_double_hello_message (BusContext     *context,
+                            DBusConnection *connection)
+{
+  DBusMessage *message;
+  dbus_uint32_t serial;
+  dbus_bool_t retval;
+  DBusError error;
+
+  retval = FALSE;
+  dbus_error_init (&error);
+  message = NULL;
+
+  _dbus_verbose ("check_double_hello_message for %p\n", connection);
+  
+  message = dbus_message_new_method_call (DBUS_SERVICE_ORG_FREEDESKTOP_DBUS,
+                                          DBUS_PATH_ORG_FREEDESKTOP_DBUS,
+                                          DBUS_INTERFACE_ORG_FREEDESKTOP_DBUS,
+                                          "Hello");
+
+  if (message == NULL)
+    return TRUE;
+
+  if (!dbus_connection_send (connection, message, &serial))
+    {
+      dbus_message_unref (message);
+      return TRUE;
+    }
+
+  dbus_message_unref (message);
+  message = NULL;
+
+  /* send our message */
+  bus_test_run_clients_loop (TRUE);
+
+  dbus_connection_ref (connection); /* because we may get disconnected */
+  block_connection_until_message_from_bus (context, connection);
+
+  if (!dbus_connection_get_is_connected (connection))
+    {
+      _dbus_verbose ("connection was disconnected\n");
+      
+      dbus_connection_unref (connection);
+      
+      return TRUE;
+    }
+
+  dbus_connection_unref (connection);
+  
+  message = pop_message_waiting_for_memory (connection);
+  if (message == NULL)
+    {
+      _dbus_warn ("Did not receive a reply to %s %d on %p\n",
+                  "Hello", serial, connection);
+      goto out;
+    }
+
+  verbose_message_received (connection, message);
+
+  if (!dbus_message_has_sender (message, DBUS_SERVICE_ORG_FREEDESKTOP_DBUS))
+    {
+      _dbus_warn ("Message has wrong sender %s\n",
+                  dbus_message_get_sender (message) ?
+                  dbus_message_get_sender (message) : "(none)");
+      goto out;
+    }
+  
+  if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_ERROR)
+    {
+      warn_unexpected (connection, message, "method return for Hello");
+      goto out;
+    }
+
+  if (!check_no_leftovers (context))
+    goto out;
+  
+  retval = TRUE;
+  
+ out:
+  dbus_error_free (&error);
+  
+  if (message)
+    dbus_message_unref (message);
+  
+  return retval;
+}
+
+/* returns TRUE if the correct thing happens,
+ * but the correct thing may include OOM errors.
+ */
+static dbus_bool_t
 check_get_connection_unix_user (BusContext     *context,
                                 DBusConnection *connection)
 {
@@ -2243,7 +2333,9 @@ check_existent_service_activation (BusContext     *context,
           ; /* good, this is a valid response */
         }
       else if (dbus_message_is_error (message,
-                                      DBUS_ERROR_SPAWN_CHILD_EXITED))
+                                      DBUS_ERROR_SPAWN_CHILD_EXITED) ||
+               dbus_message_is_error (message,
+                                      DBUS_ERROR_SPAWN_EXEC_FAILED))
         {
           ; /* good, this is expected also */
         }
@@ -2917,6 +3009,9 @@ bus_dispatch_test (const DBusString *test_data_dir)
   if (!check_hello_message (context, foo))
     _dbus_assert_not_reached ("hello message failed");
 
+  if (!check_double_hello_message (context, foo))
+    _dbus_assert_not_reached ("double hello message failed");
+
   if (!check_add_match_all (context, foo))
     _dbus_assert_not_reached ("AddMatch message failed");
   
index 90659cd..39d8b12 100644 (file)
@@ -278,6 +278,14 @@ bus_driver_handle_hello (DBusConnection *connection,
 
   _DBUS_ASSERT_ERROR_IS_CLEAR (error);
 
+  if (bus_connection_is_active (connection))
+    {
+      /* We already handled an Hello message for this connection. */
+      dbus_set_error (error, DBUS_ERROR_FAILED,
+                      "Already handled an Hello message");
+      return FALSE;
+    }
+
   /* Note that when these limits are exceeded we don't disconnect the
    * connection; we just sort of leave it hanging there until it times
    * out or disconnects itself or is dropped due to the max number of
index 629adb6..2b3ec51 100644 (file)
@@ -3359,26 +3359,29 @@ _dbus_user_at_console (const char *username,
   DBusString f;
   dbus_bool_t result;
 
+  result = FALSE;
   if (!_dbus_string_init (&f))
     {
-      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
+      _DBUS_SET_OOM (error);
       return FALSE;
     }
 
   if (!_dbus_string_append (&f, DBUS_CONSOLE_DIR))
     {
-      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-      return FALSE;
+      _DBUS_SET_OOM (error);
+      goto out;
     }
 
 
   if (!_dbus_string_append (&f, username))
     {
-      dbus_set_error (error, DBUS_ERROR_NO_MEMORY, NULL);
-      return FALSE;
+      _DBUS_SET_OOM (error);
+      goto out;
     }
 
   result = _dbus_file_exists (_dbus_string_get_const_data (&f));
+
+ out:
   _dbus_string_free (&f);
 
   return result;
index 8833cf6..2e8f577 100644 (file)
@@ -29,7 +29,8 @@
 <!ATTLIST policy 
           context (default|mandatory) #IMPLIED
           user CDATA #IMPLIED
-          group CDATA #IMPLIED>
+          group CDATA #IMPLIED
+          at_console (yes|no) #IMPLIED>
 
 <!ELEMENT allow EMPTY>
 <!ATTLIST allow