diff --git a/bus/config-parser-trivial.c b/bus/config-parser-trivial.c index fd016a8..8a1f504 100644 --- a/bus/config-parser-trivial.c +++ b/bus/config-parser-trivial.c @@ -131,6 +131,25 @@ bus_config_parser_unref (BusConfigParser *parser) } dbus_bool_t +bus_config_parser_check_doctype (BusConfigParser *parser, + const char *doctype, + DBusError *error) +{ + _DBUS_ASSERT_ERROR_IS_CLEAR (error); + + if (strcmp (doctype, "busconfig") != 0) + { + dbus_set_error (error, + DBUS_ERROR_FAILED, + "Configuration file has the wrong document type %s", + doctype); + return FALSE; + } + else + return TRUE; +} + +dbus_bool_t bus_config_parser_start_element (BusConfigParser *parser, const char *element_name, const char **attribute_names, diff --git a/bus/config-parser-trivial.h b/bus/config-parser-trivial.h index ce542bf..6733b1f 100644 --- a/bus/config-parser-trivial.h +++ b/bus/config-parser-trivial.h @@ -41,6 +41,9 @@ BusConfigParser* bus_config_parser_new (const DBusString *basedir, BusConfigParser* bus_config_parser_ref (BusConfigParser *parser); void bus_config_parser_unref (BusConfigParser *parser); +dbus_bool_t bus_config_parser_check_doctype (BusConfigParser *parser, + const char *doctype, + DBusError *error); dbus_bool_t bus_config_parser_start_element (BusConfigParser *parser, const char *element_name, const char **attribute_names, diff --git a/bus/dir-watch-kqueue.c b/bus/dir-watch-kqueue.c index 4a01b74..4e436eb 100644 --- a/bus/dir-watch-kqueue.c +++ b/bus/dir-watch-kqueue.c @@ -169,7 +169,7 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories) */ for (i = 0; new_dirs[i]; i++) { - for (j = 0; i < num_fds; j++) + for (j = 0; j < num_fds; j++) { if (dirs[j] && strcmp (new_dirs[i], dirs[j]) == 0) { diff --git a/bus/messagebus.in b/bus/messagebus.in index 1f1004b..3e2ee07 100755 --- a/bus/messagebus.in +++ b/bus/messagebus.in @@ -68,7 +68,7 @@ case "$1" in stop ;; status) - status $processname + status $servicename RETVAL=$? ;; restart) diff --git a/bus/rc.messagebus.in b/bus/rc.messagebus.in index b147503..c52ca77 100644 --- a/bus/rc.messagebus.in +++ b/bus/rc.messagebus.in @@ -61,7 +61,7 @@ case "$1" in stop ;; status) - status $processname + status $servicename RETVAL=$? ;; restart) diff --git a/dbus/dbus-connection-internal.h b/dbus/dbus-connection-internal.h index 721b5d7..cdf3f59 100644 --- a/dbus/dbus-connection-internal.h +++ b/dbus/dbus-connection-internal.h @@ -75,6 +75,7 @@ void _dbus_connection_toggle_timeout_unlocked (DBusConnection dbus_bool_t enabled); DBusConnection* _dbus_connection_new_for_transport (DBusTransport *transport); void _dbus_connection_do_iteration_unlocked (DBusConnection *connection, + DBusPendingCall *pending, unsigned int flags, int timeout_milliseconds); void _dbus_connection_close_possibly_shared (DBusConnection *connection); diff --git a/dbus/dbus-connection.c b/dbus/dbus-connection.c index 9526d3c..b3cfa3d 100644 --- a/dbus/dbus-connection.c +++ b/dbus/dbus-connection.c @@ -320,6 +320,8 @@ static void _dbus_connection_release_dispatch (DB static DBusDispatchStatus _dbus_connection_flush_unlocked (DBusConnection *connection); static void _dbus_connection_close_possibly_shared_and_unlock (DBusConnection *connection); static dbus_bool_t _dbus_connection_get_is_connected_unlocked (DBusConnection *connection); +static dbus_bool_t _dbus_connection_peek_for_reply_unlocked (DBusConnection *connection, + dbus_uint32_t client_serial); static DBusMessageFilter * _dbus_message_filter_ref (DBusMessageFilter *filter) @@ -1137,14 +1139,22 @@ _dbus_connection_release_io_path (DBusConnection *connection) * you specify DBUS_ITERATION_BLOCK; in that case the function * returns immediately. * + * If pending is not NULL then a check is made if the pending call + * is completed after the io path has been required. If the call + * has been completed nothing is done. This must be done since + * the _dbus_connection_acquire_io_path releases the connection + * lock for a while. + * * Called with connection lock held. * * @param connection the connection. + * @param pending the pending call that should be checked or NULL * @param flags iteration flags. * @param timeout_milliseconds maximum blocking time, or -1 for no limit. */ void _dbus_connection_do_iteration_unlocked (DBusConnection *connection, + DBusPendingCall *pending, unsigned int flags, int timeout_milliseconds) { @@ -1160,8 +1170,22 @@ _dbus_connection_do_iteration_unlocked (DBusConnection *connection, { HAVE_LOCK_CHECK (connection); - _dbus_transport_do_iteration (connection->transport, - flags, timeout_milliseconds); + if ( (pending != NULL) && _dbus_pending_call_get_completed_unlocked(pending)) + { + _dbus_verbose ("pending call completed while acquiring I/O path"); + } + else if ( (pending != NULL) && + _dbus_connection_peek_for_reply_unlocked (connection, + _dbus_pending_call_get_reply_serial_unlocked (pending))) + { + _dbus_verbose ("pending call completed while acquiring I/O path (reply found in queue)"); + } + else + { + _dbus_transport_do_iteration (connection->transport, + flags, timeout_milliseconds); + } + _dbus_connection_release_io_path (connection); } @@ -1989,6 +2013,7 @@ _dbus_connection_send_preallocated_unlocked_no_update (DBusConnection *con * out immediately, and otherwise get them queued up */ _dbus_connection_do_iteration_unlocked (connection, + NULL, DBUS_ITERATION_DO_WRITING, -1); @@ -2157,6 +2182,32 @@ generate_local_error_message (dbus_uint32_t serial, return message; } +/* + * Peek the incoming queue to see if we got reply for a specific serial + */ +static dbus_bool_t +_dbus_connection_peek_for_reply_unlocked (DBusConnection *connection, + dbus_uint32_t client_serial) +{ + DBusList *link; + HAVE_LOCK_CHECK (connection); + + link = _dbus_list_get_first_link (&connection->incoming_messages); + + while (link != NULL) + { + DBusMessage *reply = link->data; + + if (dbus_message_get_reply_serial (reply) == client_serial) + { + _dbus_verbose ("%s reply to %d found in queue\n", _DBUS_FUNCTION_NAME, client_serial); + return TRUE; + } + link = _dbus_list_get_next_link (&connection->incoming_messages, link); + } + + return FALSE; +} /* This is slightly strange since we can pop a message here without * the dispatch lock. @@ -2333,6 +2384,7 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending) /* Now we wait... */ /* always block at least once as we know we don't have the reply yet */ _dbus_connection_do_iteration_unlocked (connection, + pending, DBUS_ITERATION_DO_READING | DBUS_ITERATION_BLOCK, timeout_milliseconds); @@ -2399,6 +2451,7 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending) { /* block again, we don't have the reply buffered yet. */ _dbus_connection_do_iteration_unlocked (connection, + pending, DBUS_ITERATION_DO_READING | DBUS_ITERATION_BLOCK, timeout_milliseconds - elapsed_milliseconds); @@ -2426,6 +2479,7 @@ _dbus_connection_block_pending_call (DBusPendingCall *pending) { /* block again, we don't have the reply buffered yet. */ _dbus_connection_do_iteration_unlocked (connection, + NULL, DBUS_ITERATION_DO_READING | DBUS_ITERATION_BLOCK, timeout_milliseconds - elapsed_milliseconds); @@ -3403,6 +3457,7 @@ _dbus_connection_flush_unlocked (DBusConnection *connection) _dbus_verbose ("doing iteration in %s\n", _DBUS_FUNCTION_NAME); HAVE_LOCK_CHECK (connection); _dbus_connection_do_iteration_unlocked (connection, + NULL, DBUS_ITERATION_DO_READING | DBUS_ITERATION_DO_WRITING | DBUS_ITERATION_BLOCK, @@ -3489,6 +3544,7 @@ _dbus_connection_read_write_dispatch (DBusConnection *connection, { _dbus_verbose ("doing iteration in %s\n", _DBUS_FUNCTION_NAME); _dbus_connection_do_iteration_unlocked (connection, + NULL, DBUS_ITERATION_DO_READING | DBUS_ITERATION_DO_WRITING | DBUS_ITERATION_BLOCK, diff --git a/dbus/dbus-sysdeps-unix.c b/dbus/dbus-sysdeps-unix.c index ce3475a..b58d09a 100644 --- a/dbus/dbus-sysdeps-unix.c +++ b/dbus/dbus-sysdeps-unix.c @@ -623,6 +623,7 @@ _dbus_listen_unix_socket (const char *path, int listen_fd; struct sockaddr_un addr; size_t path_len; + unsigned int reuseaddr; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -696,7 +697,15 @@ _dbus_listen_unix_socket (const char *path, strncpy (addr.sun_path, path, path_len); } - + + reuseaddr = 1; + if (setsockopt (listen_fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr))==-1) + { + dbus_set_error (error, _dbus_error_from_errno (errno), + "Failed to set socket option\"%s\": %s", + path, _dbus_strerror (errno)); + } + if (bind (listen_fd, (struct sockaddr*) &addr, _DBUS_STRUCT_OFFSET (struct sockaddr_un, sun_path) + path_len) < 0) { dbus_set_error (error, _dbus_error_from_errno (errno), @@ -870,6 +879,7 @@ _dbus_listen_tcp_socket (const char *host, int nlisten_fd = 0, *listen_fd = NULL, res, i; struct addrinfo hints; struct addrinfo *ai, *tmp; + unsigned int reuseaddr; *fds_p = NULL; _DBUS_ASSERT_ERROR_IS_CLEAR (error); @@ -915,6 +925,14 @@ _dbus_listen_tcp_socket (const char *host, } _DBUS_ASSERT_ERROR_IS_CLEAR(error); + reuseaddr = 1; + if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr))==-1) + { + dbus_set_error (error, _dbus_error_from_errno (errno), + "Failed to set socket option \"%s:%s\": %s", + host ? host : "*", port, _dbus_strerror (errno)); + } + if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0) { _dbus_close(fd, NULL);