daemon: add requester to GameModeClient

Record the requester process id in the GameModeClient struct and
add a getter for it.
This commit is contained in:
Christian Kellner 2019-07-14 22:15:06 +02:00 committed by Alex Smith
parent 288b3a005e
commit cfe0fb4f17
2 changed files with 19 additions and 3 deletions

View File

@ -57,6 +57,7 @@ POSSIBILITY OF SUCH DAMAGE.
struct GameModeClient { struct GameModeClient {
_Atomic int refcount; /**<Allow outside usage */ _Atomic int refcount; /**<Allow outside usage */
pid_t pid; /**< Process ID */ pid_t pid; /**< Process ID */
pid_t requester; /**< Process ID that requested it */
struct GameModeClient *next; /**<Next client in the list */ struct GameModeClient *next; /**<Next client in the list */
char executable[PATH_MAX]; /**<Process executable */ char executable[PATH_MAX]; /**<Process executable */
time_t timestamp; /**<When was the client registered */ time_t timestamp; /**<When was the client registered */
@ -90,7 +91,7 @@ static GameModeContext instance = { 0 };
*/ */
static volatile bool had_context_init = false; static volatile bool had_context_init = false;
static GameModeClient *game_mode_client_new(pid_t pid, char *exe); static GameModeClient *game_mode_client_new(pid_t pid, char *exe, pid_t req);
static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client); static const GameModeClient *game_mode_context_has_client(GameModeContext *self, pid_t client);
static void *game_mode_context_reaper(void *userdata); static void *game_mode_context_reaper(void *userdata);
static void game_mode_context_enter(GameModeContext *self); static void game_mode_context_enter(GameModeContext *self);
@ -464,7 +465,7 @@ int game_mode_context_register(GameModeContext *self, pid_t client, pid_t reques
} }
/* From now on we depend on the client, initialize it */ /* From now on we depend on the client, initialize it */
cl = game_mode_client_new(client, executable); cl = game_mode_client_new(client, executable, requester);
if (!cl) if (!cl)
goto error_cleanup; goto error_cleanup;
free(executable); /* we're now done with memory */ free(executable); /* we're now done with memory */
@ -652,13 +653,14 @@ int game_mode_context_query_status(GameModeContext *self, pid_t client, pid_t re
* *
* This is deliberately OOM safe * This is deliberately OOM safe
*/ */
static GameModeClient *game_mode_client_new(pid_t pid, char *executable) static GameModeClient *game_mode_client_new(pid_t pid, char *executable, pid_t requester)
{ {
/* This bit seems to be formatted differently by different clang-format versions */ /* This bit seems to be formatted differently by different clang-format versions */
/* clang-format off */ /* clang-format off */
GameModeClient c = { GameModeClient c = {
.next = NULL, .next = NULL,
.pid = pid, .pid = pid,
.requester = requester,
.timestamp = 0, .timestamp = 0,
}; };
/* clang-format on */ /* clang-format on */
@ -726,6 +728,15 @@ const char *game_mode_client_get_executable(GameModeClient *client)
return client->executable; return client->executable;
} }
/**
* The process identifier of the requester.
*/
pid_t game_mode_client_get_requester(GameModeClient *client)
{
assert(client != NULL);
return client->requester;
}
/** /**
* The time that game mode was requested for the client. * The time that game mode was requested for the client.
*/ */

View File

@ -70,6 +70,11 @@ pid_t game_mode_client_get_pid(GameModeClient *client);
*/ */
const char *game_mode_client_get_executable(GameModeClient *client); const char *game_mode_client_get_executable(GameModeClient *client);
/**
* The process identifier of the requester.
*/
pid_t game_mode_client_get_requester(GameModeClient *client);
/** /**
* The time that game mode was requested for the client. * The time that game mode was requested for the client.
*/ */