gamemode: Convert game_mode_context_has_client() to return the client

Returning a bool is not useful if we want to create some log information
from this. It now returns NULL or a client pointer which is compatible
with all of the current users.

When dereferencing the returned pointer, a read lock must be acquired
around using the returned result as the client may be deallocated from
heap otherwise.

Signed-off-by: Kai Krakow <kai@kaishome.de>
This commit is contained in:
Kai Krakow 2018-10-03 17:04:24 +02:00
parent d023495a5d
commit fd4166279b

View File

@ -131,7 +131,7 @@ static volatile bool had_context_init = false;
static GameModeClient *game_mode_client_new(pid_t pid, char *exe);
static void game_mode_client_free(GameModeClient *client);
static bool game_mode_context_has_client(GameModeContext *self, pid_t client);
static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client);
static int game_mode_context_num_clients(GameModeContext *self);
static void *game_mode_context_reaper(void *userdata);
static void game_mode_context_enter(GameModeContext *self);
@ -439,15 +439,15 @@ static void game_mode_context_auto_expire(GameModeContext *self)
/**
* Determine if the client is already known to the context
*/
static bool game_mode_context_has_client(GameModeContext *self, pid_t client)
static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client)
{
bool found = false;
const GameModeClient *found = NULL;
pthread_rwlock_rdlock(&self->rwlock);
/* Walk all clients and find a matching pid */
for (GameModeClient *cl = self->client; cl; cl = cl->next) {
if (cl->pid == client) {
found = true;
found = cl;
break;
}
}