From 144854d2f447967a24de3386f6bf2a4ca1406aa0 Mon Sep 17 00:00:00 2001 From: Simon McVittie <smcv@collabora.com> Date: Mon, 4 Nov 2019 19:18:43 +0000 Subject: [PATCH] _srt_get_helper: Add support for wrapping executable in timeout(1) This is basically the same as !46. Signed-off-by: Simon McVittie <smcv@collabora.com> --- steam-runtime-tools/utils-internal.h | 2 ++ steam-runtime-tools/utils.c | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/steam-runtime-tools/utils-internal.h b/steam-runtime-tools/utils-internal.h index bac38725e..ca463b8f5 100644 --- a/steam-runtime-tools/utils-internal.h +++ b/steam-runtime-tools/utils-internal.h @@ -30,6 +30,8 @@ typedef enum { + SRT_HELPER_FLAGS_TIME_OUT = (1 << 1), + SRT_HELPER_FLAGS_TIME_OUT_SOONER = (1 << 2), SRT_HELPER_FLAGS_NONE = 0 } SrtHelperFlags; diff --git a/steam-runtime-tools/utils.c b/steam-runtime-tools/utils.c index 3908dd4f9..3d8e1651e 100644 --- a/steam-runtime-tools/utils.c +++ b/steam-runtime-tools/utils.c @@ -243,6 +243,27 @@ _srt_get_helper (const char *helpers_path, argv = g_ptr_array_new_with_free_func (g_free); + if (flags & SRT_HELPER_FLAGS_TIME_OUT) + { + g_ptr_array_add (argv, g_strdup ("timeout")); + g_ptr_array_add (argv, g_strdup ("--signal=TERM")); + + if (flags & SRT_HELPER_FLAGS_TIME_OUT_SOONER) + { + /* Speed up the failing case in automated testing */ + g_ptr_array_add (argv, g_strdup ("--kill-after=1")); + g_ptr_array_add (argv, g_strdup ("1")); + } + else + { + /* Kill the helper (if still running) 3 seconds after the TERM + * signal */ + g_ptr_array_add (argv, g_strdup ("--kill-after=3")); + /* Send TERM signal after 10 seconds */ + g_ptr_array_add (argv, g_strdup ("10")); + } + } + if (helpers_path == NULL) { helpers_path = _srt_get_helpers_path (error); -- GitLab