Explorar o código

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>
Kai Krakow %!s(int64=6) %!d(string=hai) anos
pai
achega
fd4166279b
Modificáronse 1 ficheiros con 4 adicións e 4 borrados
  1. 4 4
      daemon/gamemode.c

+ 4 - 4
daemon/gamemode.c

@@ -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;
 		}
 	}