mirror of
https://github.com/FeralInteractive/gamemode.git
synced 2025-06-06 23:57:22 +02:00
daemon: add creation timestamp to GameModeClient
Record the time a client was created, i.e. registered, in the GameModeClient struct and add a getter for it. (Alex Smith: Fixed up function documentation comments)
This commit is contained in:
parent
6f39ecbc9b
commit
52367772c8
@ -46,6 +46,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#include <stdatomic.h>
|
#include <stdatomic.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <sys/time.h>
|
||||||
#include <systemd/sd-daemon.h> /* TODO: Move usage to gamemode-dbus.c */
|
#include <systemd/sd-daemon.h> /* TODO: Move usage to gamemode-dbus.c */
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@ -58,6 +59,7 @@ struct GameModeClient {
|
|||||||
pid_t pid; /**< Process ID */
|
pid_t pid; /**< Process ID */
|
||||||
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 */
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GameModeContext {
|
struct GameModeContext {
|
||||||
@ -657,9 +659,18 @@ static GameModeClient *game_mode_client_new(pid_t pid, char *executable)
|
|||||||
GameModeClient c = {
|
GameModeClient c = {
|
||||||
.next = NULL,
|
.next = NULL,
|
||||||
.pid = pid,
|
.pid = pid,
|
||||||
|
.timestamp = 0,
|
||||||
};
|
};
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
GameModeClient *ret = NULL;
|
GameModeClient *ret = NULL;
|
||||||
|
struct timeval now = {
|
||||||
|
0,
|
||||||
|
};
|
||||||
|
int r;
|
||||||
|
|
||||||
|
r = gettimeofday(&now, NULL);
|
||||||
|
if (r == 0)
|
||||||
|
c.timestamp = now.tv_sec;
|
||||||
|
|
||||||
ret = calloc(1, sizeof(struct GameModeClient));
|
ret = calloc(1, sizeof(struct GameModeClient));
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
@ -668,6 +679,7 @@ static GameModeClient *game_mode_client_new(pid_t pid, char *executable)
|
|||||||
*ret = c;
|
*ret = c;
|
||||||
ret->refcount = ATOMIC_VAR_INIT(1);
|
ret->refcount = ATOMIC_VAR_INIT(1);
|
||||||
strncpy(ret->executable, executable, PATH_MAX - 1);
|
strncpy(ret->executable, executable, PATH_MAX - 1);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -714,6 +726,15 @@ const char *game_mode_client_get_executable(GameModeClient *client)
|
|||||||
return client->executable;
|
return client->executable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The time that game mode was requested for the client.
|
||||||
|
*/
|
||||||
|
uint64_t game_mode_client_get_timestamp(GameModeClient *client)
|
||||||
|
{
|
||||||
|
assert(client != NULL);
|
||||||
|
return (uint64_t)client->timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
/* Internal refresh config function (assumes no contention with reaper thread) */
|
/* Internal refresh config function (assumes no contention with reaper thread) */
|
||||||
static void game_mode_reload_config_internal(GameModeContext *self)
|
static void game_mode_reload_config_internal(GameModeContext *self)
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#define INVALID_PROCFD -1
|
#define INVALID_PROCFD -1
|
||||||
@ -69,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 time that game mode was requested for the client.
|
||||||
|
*/
|
||||||
|
u_int64_t game_mode_client_get_timestamp(GameModeClient *client);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the singleton instance
|
* Return the singleton instance
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user