#define DBUS_REPLY_TIMEOUT (10000)
static GBusType g_default_bus_type = G_BUS_TYPE_SYSTEM;
-static gboolean g_default_priv = false;
pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
void gdbus_set_default_bus_type(GBusType bus_type)
static dbus_handle_s g_dh[2];
static dbus_handle_s *_gdbus_get_connection(GBusType bus_type);
-static dbus_handle_s *_gdbus_get_connection_private(GBusType bus_type);
dbus_handle_s * _gdbus_get_default_connection(void)
{
- if (g_default_priv)
- return _gdbus_get_connection_private(gdbus_get_default_bus_type());
-
return _gdbus_get_connection(gdbus_get_default_bus_type());
}
return strv;
}
-int _gdbus_free_connection(dbus_handle_h handle, gboolean close_any_connection)
+int gdbus_free_connection(dbus_handle_h handle)
{
dcl_gdbus();
dbus_handle_s *pdh = NULL;
}
/* close connection */
- if (pdh->priv || close_any_connection) {
- _E("close connection\n");
+ if (pdh->priv) {
+ _E("close private connection\n");
if (!g_dbus_connection_close_sync(pdh->conn, NULL, &err)) {
_E("Error closing connection %s\n", err->message);
// todo: signal ?
}
-int gdbus_free_connection(dbus_handle_h handle)
-{
- return _gdbus_free_connection(handle, false);
-}
-
-
#define buf_cal_free_space(size, nwrite) ((size - nwrite - 1) > 0 ? (size - nwrite - 1) : 0)
#define buf_block_size 8192
g_variant_builder_unref(builder);
return var;
}
-
-int gdbus_switch_to_private_connection(void)
-{
- // This function is called by launchpad during the application preparation
- // process. Launchpad is running with high privileges (label User). If a call
- // to dbus is made before the process privileges are changed to lower (wich is
- // what happens now), any method call sent with this connection will be
- // visible as a call from a privileged process.
- //
- // From outside glib we can't effectively close the current connection so as
- // to receive a new one (with application label), so this function forces to
- // use of a private connection.
-
- // Close current connection so that it can not be used.
- dbus_handle_s *connection = _gdbus_get_connection(gdbus_get_default_bus_type());
- int ret;
- if ((ret = _gdbus_free_connection(connection, true)) != 0)
- return ret;
-
- // Switch to a private connection.
- pthread_mutex_lock(&g_mutex);
- g_default_priv = true;
- pthread_mutex_unlock(&g_mutex);
-
- _I("Switched to private connection.");
-
- return 0;
-}