int fd;
uint64_t id;
char *pool;
- int counter;
-} g_conn[2];
+} g_conn[2] = {
+ {.pool = MAP_FAILED},
+ {.pool = MAP_FAILED}
+};
struct udesc {
dbus_uid_t uid;
}
static bool init_once_done = false;
+static bool init_once[2] = {false, false};
DBUSPOLICY1_EXPORT void* dbuspolicy1_init(const char *bus_path)
{
unsigned int bus_type = -1;
char resolved_path[PATH_MAX] = { 0 };
int rp, rs;
- bool rb;
_Static_assert(SYSTEM_BUS == 0, "SYSTEM_BUS not 0");
_Static_assert(SESSION_BUS == 1, "SESSION_BUS not 0");
if (bus_type)
bus_type = SESSION_BUS;
- rb = false;
pthread_mutex_lock(&g_mutex);
if (!init_once_done) {
init_once_done = true;
- rb = dbuspolicy_init_once();
+ dbuspolicy_init_once();
}
- if (rb)
- goto err_close;
- if (g_conn[bus_type].counter == 0) {
+ if (!init_once[bus_type]) {
if ((g_conn[bus_type].fd = kdbus_open_bus(resolved_path)) < 0)
goto err;
if (rp < 0 && rs < 0) /* when both negative */
goto err_close;
+
+ init_once[bus_type] = true;
}
- g_conn[bus_type].counter++;
pthread_mutex_unlock(&g_mutex);
__internal_init_flush_logs();
return &g_conn[bus_type];
err_close:
+ if (g_conn[bus_type].pool != MAP_FAILED)
+ munmap(g_conn[bus_type].pool, KDBUS_POOL_SIZE);
close(g_conn[bus_type].fd);
err:
pthread_mutex_unlock(&g_mutex);
DBUSPOLICY1_EXPORT void dbuspolicy1_free(void* configuration)
{
- if (configuration) {
- struct kconn* k = (struct kconn*)configuration;
- pthread_mutex_lock(&g_mutex);
-
- --k->counter;
- if (k->counter <= 0) {
- munmap(k->pool, KDBUS_POOL_SIZE);
- close(k->fd);
- }
-
- pthread_mutex_unlock(&g_mutex);
- }
+ configuration = configuration;
}
#ifdef LIBDBUSPOLICY_TESTS_API