-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix 'is_process_running' returns an incorrect 'true' when process 'pid' exists, but whose process does not belong to the current application. #75
Conversation
2954800
to
82e2792
Compare
0712a27
to
917917f
Compare
…d' exists, but whose process does not belong to the current application. Effect on Aseprite: some recovery sessions do not appear in the Recovery menu.
917917f
to
bb1d53e
Compare
Ready for review. Linux version without modifications. |
59773cd
to
028e445
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! I have added the Linux part.
0a953fc
to
5dda814
Compare
I changed the approach. @martincapello could you please review it again and give me your opinion on the implementation? Could you try again on Linux? |
5dda814
to
ecd99f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks better than before! I tested this on Linux and it works. However I'm not sure why when compiling it doesn't complain as the github actions do...I left a comment with a possible fix that should make github actions happy.
@@ -16,7 +17,9 @@ namespace base { | |||
|
|||
pid get_current_process_id(); | |||
|
|||
bool is_process_running(pid pid); | |||
std::string get_process_name(pid pid); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should include <string>
to avoid the errors reported by Github actions.
cc0c002
to
943c3a4
Compare
943c3a4
to
689a7b9
Compare
@martincapello could you try it one more time? |
@dacap the PR is ready for your review. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made some comments, the commits are a little messy (including git descriptions), I can take this PR from here refactoring/rebasing/editing all the commits in some way (I have 3 platforms running right now to implement this ASAP).
bool running = false; | ||
|
||
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, TRUE, pid); | ||
HANDLE handle = CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From CreateToolhelp32Snapshot
docs it looks like it's recommended to use QueryFullProcessImageNameW to get the process name. Probably we don't need this full snapshot thing (not sure what is the work this function does).
wcstombs(buf, pe.szExeFile, 64); | ||
std::string str(buf); | ||
for (char& c : str) { | ||
c = tolower(c); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't tolower the name, we should return the process name as it's reported and then post-process the name from the Aseprite side (remember that laf should be as independent from Aseprite implementation/details as possible).
} | ||
CloseHandle(handle); | ||
} | ||
return ""; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always remember to return an empty string as std::string instead of "" when the return value is std::string:
return ""; | |
return std::string(); |
bool is_process_running(pid pid, std::string currentProcessName) | ||
{ | ||
std::string pidProcessName = get_process_name(pid); | ||
if (pidProcessName == "") | ||
return false; | ||
return pidProcessName == currentProcessName; | ||
} | ||
|
||
bool is_process_running(pid pid) | ||
{ | ||
return false; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like we have lost functionality from the laf side here: 1) the is_process_running does nothing (it should behave exactly as it was working), and 2) the new is_process_running(pid,name) looks like something could be done from the Aseprite side now that we have get_process_name.
Merged in: I'll see if I change the Windows impl later but the returned value should be the same. With this new get_process_name() function I think the original Aseprite bug could be fixed. |
Windows part not solved yet.
Linux not tested yet.
The current fix on all platforms might make aseprite/aseprite#4130 unnecessary.