From 05f58fcd71aa15e54c386ab8517ea20d98b75515 Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Tue, 26 Dec 2023 16:56:23 -0300 Subject: [PATCH] Fix 'is_process_running' returns an incorrect 'true' when process 'pid' exists, but whose process does not belong to the current application. Effect on Aseprite: some recovery sessions do not appear in the Recovery menu. --- base/process.cpp | 14 ++++++++++---- base/process.h | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/base/process.cpp b/base/process.cpp index 887f2d475..9a2fa83cd 100644 --- a/base/process.cpp +++ b/base/process.cpp @@ -1,5 +1,5 @@ // LAF Base Library -// Copyright (c) 2021 Igara Studio S.A. +// Copyright (c) 2021-2023 Igara Studio S.A. // Copyright (c) 2015-2016 David Capello // // This file is released under the terms of the MIT license. @@ -14,7 +14,9 @@ #if LAF_WINDOWS #include #else + #include #include + #include #include #include #endif @@ -28,7 +30,7 @@ pid get_current_process_id() return (pid)GetCurrentProcessId(); } -bool is_process_running(pid pid) +bool is_process_running(pid pid, const char* pname) { bool running = false; @@ -51,9 +53,13 @@ pid get_current_process_id() return (pid)getpid(); } -bool is_process_running(pid pid) +bool is_process_running(pid pid, const char* pname) { - return (kill(pid, 0) == 0); + std::string proc_name = pname; + struct proc_bsdinfo process; + proc_pidinfo(pid, PROC_PIDTBSDINFO, 0, + &process, PROC_PIDTBSDINFO_SIZE); + return (strcmp(proc_name.c_str(), process.pbi_name) == 0); } #endif diff --git a/base/process.h b/base/process.h index 445b87cd6..8085ffe20 100644 --- a/base/process.h +++ b/base/process.h @@ -1,4 +1,5 @@ // LAF Base Library +// Copyright (c) 2023 Igara Studio S.A. // Copyright (c) 2015-2016 David Capello // // This file is released under the terms of the MIT license. @@ -16,7 +17,7 @@ namespace base { pid get_current_process_id(); - bool is_process_running(pid pid); + bool is_process_running(pid pid, const char* pname); } // namespace base