Add "script_timeout" config value to control if a user wants to extend the script timeout before kill value

This commit is contained in:
Marc Di Luzio
2019-02-21 20:47:31 +00:00
parent 53d1700a68
commit c215626ccd
4 changed files with 24 additions and 7 deletions

View File

@ -71,6 +71,7 @@ struct GameModeConfig {
char whitelist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
char blacklist[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
long script_timeout;
char startscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
char endscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
@ -278,6 +279,8 @@ static int inih_handler(void *user, const char *section, const char *name, const
valid = append_value_to_list(name, value, self->values.startscripts);
} else if (strcmp(name, "end") == 0) {
valid = append_value_to_list(name, value, self->values.endscripts);
} else if (strcmp(name, "script_timeout") == 0) {
valid = get_long_value(name, value, &self->values.script_timeout);
}
}
@ -330,6 +333,7 @@ static void load_config_files(GameModeConfig *self)
self->values.reaper_frequency = DEFAULT_REAPER_FREQ;
self->values.gpu_device = -1; /* 0 is a valid device ID so use -1 to indicate no value */
self->values.nv_perf_level = -1;
self->values.script_timeout = 10; /* Default to 10 seconds for scripts */
/*
* Locations to load, in order
@ -506,6 +510,11 @@ void config_get_gamemode_end_scripts(GameModeConfig *self,
memcpy_locked_config(self, scripts, self->values.endscripts, sizeof(self->values.startscripts));
}
/*
* Get the script timemout value
*/
DEFINE_CONFIG_GET(script_timeout)
/*
* Get the chosen default governor
*/

View File

@ -105,6 +105,11 @@ void config_get_gamemode_start_scripts(GameModeConfig *self,
void config_get_gamemode_end_scripts(GameModeConfig *self,
char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX]);
/*
* Get the script timout value
*/
long config_get_script_timeout(GameModeConfig *self);
/*
* Get the chosen default governor
*/

View File

@ -360,6 +360,7 @@ static int run_cpu_governor_tests(struct GameModeConfig *config)
static int run_custom_scripts_tests(struct GameModeConfig *config)
{
int scriptstatus = 0;
long timeout = config_get_script_timeout(config);
/* Grab and test the start scripts */
char startscripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
@ -372,7 +373,7 @@ static int run_custom_scripts_tests(struct GameModeConfig *config)
LOG_MSG(":::: Running start script [%s]\n", startscripts[i]);
const char *args[] = { "/bin/sh", "-c", startscripts[i], NULL };
int ret = run_external_process(args, NULL, 10);
int ret = run_external_process(args, NULL, (int)timeout);
if (ret == 0)
LOG_MSG(":::: Passed\n");
@ -395,7 +396,7 @@ static int run_custom_scripts_tests(struct GameModeConfig *config)
LOG_MSG(":::: Running end script [%s]\n", endscripts[i]);
const char *args[] = { "/bin/sh", "-c", endscripts[i], NULL };
int ret = run_external_process(args, NULL, 10);
int ret = run_external_process(args, NULL, (int)timeout);
if (ret == 0)
LOG_MSG(":::: Passed\n");

View File

@ -93,7 +93,7 @@ static void *game_mode_context_reaper(void *userdata);
static void game_mode_context_enter(GameModeContext *self);
static void game_mode_context_leave(GameModeContext *self);
static char *game_mode_context_find_exe(pid_t pid);
static void game_mode_execute_scripts(char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX]);
static void game_mode_execute_scripts(char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX], int timeout);
void game_mode_context_init(GameModeContext *self)
{
@ -209,7 +209,8 @@ static void game_mode_context_enter(GameModeContext *self)
char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
memset(scripts, 0, sizeof(scripts));
config_get_gamemode_start_scripts(self->config, scripts);
game_mode_execute_scripts(scripts);
long timeout = config_get_script_timeout(self->config);
game_mode_execute_scripts(scripts, (int)timeout);
}
/**
@ -252,7 +253,8 @@ static void game_mode_context_leave(GameModeContext *self)
char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX];
memset(scripts, 0, sizeof(scripts));
config_get_gamemode_end_scripts(self->config, scripts);
game_mode_execute_scripts(scripts);
long timeout = config_get_script_timeout(self->config);
game_mode_execute_scripts(scripts, (int)timeout);
}
/**
@ -686,14 +688,14 @@ fail:
}
/* Executes a set of scripts */
static void game_mode_execute_scripts(char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX])
static void game_mode_execute_scripts(char scripts[CONFIG_LIST_MAX][CONFIG_VALUE_MAX], int timeout)
{
unsigned int i = 0;
while (*scripts[i] != '\0' && i < CONFIG_LIST_MAX) {
LOG_MSG("Executing script [%s]\n", scripts[i]);
int err;
const char *args[] = { "/bin/sh", "-c", scripts[i], NULL };
if ((err = run_external_process(args, NULL, 10)) != 0) {
if ((err = run_external_process(args, NULL, timeout)) != 0) {
/* Log the failure, but this is not fatal */
LOG_ERROR("Script [%s] failed with error %d\n", scripts[i], err);
}