From 4ce5b7d163e14783cc874dbf978d25baf7eb2cf4 Mon Sep 17 00:00:00 2001 From: Jan Luca Naumann Date: Tue, 25 May 2021 08:37:37 +0200 Subject: [PATCH] Fix matching of Proc::check_args if cmdline contains non-exe path In the current version Proc::check_args matches all arguments of the cmdline to the needle to check if a program is already running. This check returns wrong result if for example the path `/home/root/.local/share/remarkable/xochitl` is somewhere in the cmdline arguments. The new version just matches the first argument of the cmdline and only checks for further args if the first program is a known interpreter (sh, bash, python). Signed-off-by: Jan Luca Naumann --- src/shared/proc.cpy | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/shared/proc.cpy b/src/shared/proc.cpy index 807e7a73..a54e103f 100644 --- a/src/shared/proc.cpy +++ b/src/shared/proc.cpy @@ -11,6 +11,7 @@ #include #include #include +#include #define PID 1 #define PGROUP 4 @@ -54,6 +55,8 @@ namespace proc: int used = 0 ; + std::set known_interpreters {"python", "python3", "bash", "sh"} + string join_path(vector v): ostringstream s; for const auto& i : v: @@ -110,13 +113,16 @@ namespace proc: base = basename((char *) base) base_str := string(base) + auto search_interpreter = known_interpreters.find(base_str) + if search_interpreter != known_interpreters.end(): + continue + for auto needle : args: if base_str == needle || full_str == needle: found = true break - if found: - break + break return found