PATCH: get unix user speed up
Michael Krivoruchko
misha at sun.com
Mon Oct 17 16:56:38 PDT 2005
Hi,
the attached patch reduces round trip time for GetConnectionUnixUser by
avoiding repetitive calls to system specific authentication API behind
dbus_connection_get_unix_user.
Misha
--
-------------- next part --------------
diff -ruN dbus/bus/connection.c dbus-get-unix-user/bus/connection.c
--- dbus/bus/connection.c 2005-08-03 18:42:56.000000000 +0100
+++ dbus-get-unix-user/bus/connection.c 2005-10-18 00:27:45.000000000 +0100
@@ -71,6 +71,7 @@
DBusList *match_rules;
int n_match_rules;
char *name;
+ dbus_uid_t unix_user;
DBusList *transaction_messages; /**< Stuff we need to send as part of a transaction */
DBusMessage *oom_message;
DBusPreallocatedSend *oom_preallocated;
@@ -377,7 +378,9 @@
d = BUS_CONNECTION_DATA (connection);
_dbus_assert (d != NULL);
-
+
+ d->unix_user = uid;
+
return bus_context_allow_user (d->connections->context, uid);
}
@@ -550,7 +553,9 @@
d->connections = connections;
d->connection = connection;
-
+
+ d->unix_user = DBUS_UID_UNSET;
+
_dbus_get_current_time (&d->connection_tv_sec,
&d->connection_tv_usec);
@@ -1042,6 +1047,27 @@
}
/**
+ * Retrives unix user id of the connection.
+ *
+ * @param connection the connection
+ * @returns unix user id or #DBUS_UID_UNSET if the connection has not been authenticated.
+ */
+dbus_uid_t
+bus_connection_get_unix_user (DBusConnection *connection)
+{
+ BusConnectionData *d;
+
+ d = BUS_CONNECTION_DATA (connection);
+
+ _dbus_assert (d != NULL);
+
+ if (d->unix_user == DBUS_UID_UNSET)
+ dbus_connection_get_unix_user (connection, &(d->unix_user));
+
+ return d->unix_user;
+}
+
+/**
* Checks whether the connection is registered with the message bus.
*
* @param connection the connection
diff -ruN dbus/bus/connection.h dbus-get-unix-user/bus/connection.h
--- dbus/bus/connection.h 2004-08-10 04:06:59.000000000 +0100
+++ dbus-get-unix-user/bus/connection.h 2005-10-17 22:57:56.000000000 +0100
@@ -51,6 +51,7 @@
BusActivation* bus_connection_get_activation (DBusConnection *connection);
BusMatchmaker* bus_connection_get_matchmaker (DBusConnection *connection);
BusSELinuxID* bus_connection_get_selinux_id (DBusConnection *connection);
+dbus_uid_t bus_connection_get_unix_user (DBusConnection *connection);
dbus_bool_t bus_connections_check_limits (BusConnections *connections,
DBusConnection *requesting_completion,
DBusError *error);
diff -ruN dbus/bus/driver.c dbus-get-unix-user/bus/driver.c
--- dbus/bus/driver.c 2005-10-03 20:55:56.000000000 +0100
+++ dbus-get-unix-user/bus/driver.c 2005-10-17 23:23:23.000000000 +0100
@@ -907,7 +907,8 @@
if (reply == NULL)
goto oom;
- if (!dbus_connection_get_unix_user (conn, &uid))
+ uid = bus_connection_get_unix_user (conn);
+ if (uid == DBUS_UID_UNSET)
{
dbus_set_error (error,
DBUS_ERROR_FAILED,
diff -ruN dbus/dbus/dbus-transport.c dbus-get-unix-user/dbus/dbus-transport.c
--- dbus/dbus/dbus-transport.c 2005-05-05 23:02:11.000000000 +0100
+++ dbus-get-unix-user/dbus/dbus-transport.c 2005-10-17 22:13:23.000000000 +0100
@@ -967,7 +967,7 @@
{
DBusCredentials auth_identity;
- *uid = _DBUS_INT32_MAX; /* better than some root or system user in
+ *uid = DBUS_UID_UNSET; /* better than some root or system user in
* case of bugs in the caller. Caller should
* never use this value on purpose, however.
*/
More information about the dbus
mailing list