From 53d1700a680a02576ada3b3f7d3cfd913d5a98d0 Mon Sep 17 00:00:00 2001 From: Marc Di Luzio Date: Thu, 21 Feb 2019 20:27:41 +0000 Subject: [PATCH] Add the timout to the call signature of run_external_process --- daemon/external-helper.c | 12 ++++++++++-- daemon/external-helper.h | 2 +- daemon/gamemode-gpu.c | 4 ++-- daemon/gamemode-tests.c | 4 ++-- daemon/gamemode.c | 6 +++--- daemon/gpuclockctl.c | 8 ++++---- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/daemon/external-helper.c b/daemon/external-helper.c index fcdcaa4..5bbc990 100644 --- a/daemon/external-helper.c +++ b/daemon/external-helper.c @@ -40,10 +40,12 @@ POSSIBILITY OF SUCH DAMAGE. #include #include +static const int default_timout = 5; + /** * Call an external process */ -int run_external_process(const char *const *exec_args, char buffer[EXTERNAL_BUFFER_MAX]) +int run_external_process(const char *const *exec_args, char buffer[EXTERNAL_BUFFER_MAX], int tsec) { pid_t p; int status = 0; @@ -54,6 +56,11 @@ int run_external_process(const char *const *exec_args, char buffer[EXTERNAL_BUFF return -1; } + /* Set the default timeout */ + if (tsec == -1) { + tsec = default_timout; + } + /* set up our signaling for the child and the timout */ sigset_t mask; sigset_t omask; @@ -88,7 +95,8 @@ int run_external_process(const char *const *exec_args, char buffer[EXTERNAL_BUFF /* Set up the timout */ struct timespec timeout; - timeout.tv_sec = 5; /* Magic timeout value of 5s for now - should be sane for most commands */ + timeout.tv_sec = tsec; /* Magic timeout value of 5s for now - should be sane for most commands + */ timeout.tv_nsec = 0; /* Wait for the child to finish up with a timout */ diff --git a/daemon/external-helper.h b/daemon/external-helper.h index 73d0a01..9d4e2e4 100644 --- a/daemon/external-helper.h +++ b/daemon/external-helper.h @@ -34,4 +34,4 @@ POSSIBILITY OF SUCH DAMAGE. #define EXTERNAL_BUFFER_MAX 1024 /* Run an external process and capture the return value */ -int run_external_process(const char *const *exec_args, char buffer[EXTERNAL_BUFFER_MAX]); +int run_external_process(const char *const *exec_args, char buffer[EXTERNAL_BUFFER_MAX], int tsec); diff --git a/daemon/gamemode-gpu.c b/daemon/gamemode-gpu.c index 9c5de33..0040b9c 100644 --- a/daemon/gamemode-gpu.c +++ b/daemon/gamemode-gpu.c @@ -229,7 +229,7 @@ int game_mode_apply_gpu(const GameModeGPUInfo *info, bool apply) NULL, }; - if (run_external_process(exec_args, NULL) != 0) { + if (run_external_process(exec_args, NULL, -1) != 0) { LOG_ERROR("Failed to call gpuclockctl, could not apply optimisations!\n"); return -1; } @@ -262,7 +262,7 @@ int game_mode_get_gpu(GameModeGPUInfo *info) }; char buffer[EXTERNAL_BUFFER_MAX] = { 0 }; - if (run_external_process(exec_args, buffer) != 0) { + if (run_external_process(exec_args, buffer, -1) != 0) { LOG_ERROR("Failed to call gpuclockctl, could get values!\n"); return -1; } diff --git a/daemon/gamemode-tests.c b/daemon/gamemode-tests.c index a65cbb2..9761f78 100644 --- a/daemon/gamemode-tests.c +++ b/daemon/gamemode-tests.c @@ -372,7 +372,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); + int ret = run_external_process(args, NULL, 10); if (ret == 0) LOG_MSG(":::: Passed\n"); @@ -395,7 +395,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); + int ret = run_external_process(args, NULL, 10); if (ret == 0) LOG_MSG(":::: Passed\n"); diff --git a/daemon/gamemode.c b/daemon/gamemode.c index 78fee5d..575a4c0 100644 --- a/daemon/gamemode.c +++ b/daemon/gamemode.c @@ -189,7 +189,7 @@ static void game_mode_context_enter(GameModeContext *self) }; LOG_MSG("Requesting update of governor policy to %s\n", desiredGov); - if (run_external_process(exec_args, NULL) != 0) { + if (run_external_process(exec_args, NULL, -1) != 0) { LOG_ERROR("Failed to update cpu governor policy\n"); /* if the set fails, clear the initial mode so we don't try and reset it back and fail * again, presumably */ @@ -242,7 +242,7 @@ static void game_mode_context_leave(GameModeContext *self) }; LOG_MSG("Requesting update of governor policy to %s\n", gov_mode); - if (run_external_process(exec_args, NULL) != 0) { + if (run_external_process(exec_args, NULL, -1) != 0) { LOG_ERROR("Failed to update cpu governor policy\n"); } @@ -693,7 +693,7 @@ static void game_mode_execute_scripts(char scripts[CONFIG_LIST_MAX][CONFIG_VALUE 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)) != 0) { + if ((err = run_external_process(args, NULL, 10)) != 0) { /* Log the failure, but this is not fatal */ LOG_ERROR("Script [%s] failed with error %d\n", scripts[i], err); } diff --git a/daemon/gpuclockctl.c b/daemon/gpuclockctl.c index 26e1d0a..001c07d 100644 --- a/daemon/gpuclockctl.c +++ b/daemon/gpuclockctl.c @@ -79,7 +79,7 @@ static int get_gpu_state_nv(struct GameModeGPUInfo *info) NV_CORE_OFFSET_ATTRIBUTE, info->nv_perf_level); const char *exec_args_core[] = { "/usr/bin/nvidia-settings", "-q", arg, "-t", NULL }; - if (run_external_process(exec_args_core, buf) != 0) { + if (run_external_process(exec_args_core, buf, -1) != 0) { LOG_ERROR("Failed to set %s!\n", arg); return -1; } @@ -98,7 +98,7 @@ static int get_gpu_state_nv(struct GameModeGPUInfo *info) NV_MEM_OFFSET_ATTRIBUTE, info->nv_perf_level); const char *exec_args_mem[] = { "/usr/bin/nvidia-settings", "-q", arg, "-t", NULL }; - if (run_external_process(exec_args_mem, buf) != 0) { + if (run_external_process(exec_args_mem, buf, -1) != 0) { LOG_ERROR("Failed to set %s!\n", arg); return -1; } @@ -145,7 +145,7 @@ static int set_gpu_state_nv(struct GameModeGPUInfo *info) info->nv_perf_level, info->core); const char *exec_args_core[] = { "/usr/bin/nvidia-settings", "-a", core_arg, NULL }; - if (run_external_process(exec_args_core, NULL) != 0) { + if (run_external_process(exec_args_core, NULL, -1) != 0) { LOG_ERROR("Failed to set %s!\n", core_arg); return -1; } @@ -160,7 +160,7 @@ static int set_gpu_state_nv(struct GameModeGPUInfo *info) info->nv_perf_level, info->mem); const char *exec_args_mem[] = { "/usr/bin/nvidia-settings", "-a", mem_arg, NULL }; - if (run_external_process(exec_args_mem, NULL) != 0) { + if (run_external_process(exec_args_mem, NULL, -1) != 0) { LOG_ERROR("Failed to set %s!\n", mem_arg); return -1; }