Add config file parsing

Checks for a gamemode.ini in /usr/share/gamemode/ (or in the cwd for debugging)

	Currently allows for blacklisting and whitelisting clients based on rudimentary needle-haystack executable name checks

	See the example/gamemode.ini file for expected syntax

	Using the BSD licensed inih library (with additional meson.build file)
This commit is contained in:
Marc Di Luzio
2018-03-23 13:30:25 +00:00
parent 142246366f
commit 759cbc3c40
10 changed files with 388 additions and 0 deletions

View File

@@ -32,6 +32,7 @@ POSSIBILITY OF SUCH DAMAGE.
#define _GNU_SOURCE
#include "gamemode.h"
#include "daemon_config.h"
#include "governors.h"
#include "logging.h"
@@ -56,6 +57,8 @@ struct GameModeContext {
_Atomic int refcount; /**<Allow cycling the game mode */
GameModeClient *client; /**<Pointer to first client */
GameModeConfig *config; /**<Pointer to config object */
bool performance_mode; /**<Only updates when we can */
/* Reaper control */
@@ -98,6 +101,10 @@ void game_mode_context_init(GameModeContext *self)
had_context_init = true;
self->refcount = ATOMIC_VAR_INIT(0);
/* Initialise the config */
self->config = config_create();
config_init(self->config);
/* Read current governer state before setting up any message handling */
update_initial_gov_state();
LOG_MSG("governor is set to [%s]\n", get_initial_governor());
@@ -139,6 +146,9 @@ void game_mode_context_destroy(GameModeContext *self)
pthread_cond_destroy(&self->reaper.condition);
pthread_mutex_destroy(&self->reaper.mutex);
/* Destroy the config object */
config_destroy(self->config);
pthread_rwlock_destroy(&self->rwlock);
}
@@ -253,6 +263,15 @@ bool game_mode_context_register(GameModeContext *self, pid_t client)
return false;
}
/* Check our blacklist and whitelist */
if (!config_get_client_whitelisted(self->config, cl->executable)) {
LOG_MSG("Client [%s] was rejected (not in whitelist)\n", cl->executable);
return false;
} else if (config_get_client_blacklisted(self->config, cl->executable)) {
LOG_MSG("Client [%s] was rejected (in blacklist)\n", cl->executable);
return false;
}
/* Begin a write lock now to insert our new client at list start */
pthread_rwlock_wrlock(&self->rwlock);