Pārlūkot izejas kodu

Use run_external_process for the script execution

	This protects the main process against script exection and allows more detailed error handling
Marc Di Luzio 6 gadi atpakaļ
vecāks
revīzija
1665447350
2 mainītis faili ar 7 papildinājumiem un 3 dzēšanām
  1. 5 2
      daemon/gamemode-tests.c
  2. 2 1
      daemon/gamemode.c

+ 5 - 2
daemon/gamemode-tests.c

@@ -41,6 +41,7 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <unistd.h>
 
 #include "daemon_config.h"
+#include "external-helper.h"
 #include "gamemode_client.h"
 #include "governors-query.h"
 #include "gpu-control.h"
@@ -370,7 +371,8 @@ static int run_custom_scripts_tests(struct GameModeConfig *config)
 		while (*startscripts[i] != '\0' && i < CONFIG_LIST_MAX) {
 			LOG_MSG(":::: Running start script [%s]\n", startscripts[i]);
 
-			int ret = system(startscripts[i]);
+			const char *args[] = { "/bin/sh", "-c", startscripts[i], NULL };
+			int ret = run_external_process(args);
 
 			if (ret == 0)
 				LOG_MSG(":::: Passed\n");
@@ -392,7 +394,8 @@ static int run_custom_scripts_tests(struct GameModeConfig *config)
 		while (*endscripts[i] != '\0' && i < CONFIG_LIST_MAX) {
 			LOG_MSG(":::: Running end script [%s]\n", endscripts[i]);
 
-			int ret = system(endscripts[i]);
+			const char *args[] = { "/bin/sh", "-c", endscripts[i], NULL };
+			int ret = run_external_process(args);
 
 			if (ret == 0)
 				LOG_MSG(":::: Passed\n");

+ 2 - 1
daemon/gamemode.c

@@ -692,7 +692,8 @@ static void game_mode_execute_scripts(char scripts[CONFIG_LIST_MAX][CONFIG_VALUE
 	while (*scripts[i] != '\0' && i < CONFIG_LIST_MAX) {
 		LOG_MSG("Executing script [%s]\n", scripts[i]);
 		int err;
-		if ((err = system(scripts[i])) != 0) {
+		const char *args[] = { "/bin/sh", "-c", scripts[i], NULL };
+		if ((err = run_external_process(args)) != 0) {
 			/* Log the failure, but this is not fatal */
 			LOG_ERROR("Script [%s] failed with error %d\n", scripts[i], err);
 		}