Skip to content
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

Process List incomplete on long names #1190

Closed
CryZe opened this issue Jan 3, 2024 · 1 comment · Fixed by #1196
Closed

Process List incomplete on long names #1190

CryZe opened this issue Jan 3, 2024 · 1 comment · Fixed by #1196

Comments

@CryZe
Copy link
Contributor

CryZe commented Jan 3, 2024

Describe the bug
This is on 0.30.3. The issue is that the stat file on Linux is parsed under the assumption that it contains valid UTF-8. This is not necessarily the case for two reasons:

  1. Process names don't need to be valid UTF-8 at all on Linux. They can contain invalid bytes.
  2. Even if the process name was valid UTF-8, the assumption breaks because the process name is limited to 15 characters, which can cut a valid code point in half.

This causes the stat file to not be parseable, causing the entire process not to show up in the list. So even if I wasn't using the name of the process at all, I can't find it as part of the list.

To Reproduce
I named an executable process-name-töööö, which cuts one of the ö in half.

I have a fixed branch locally, but I want to discuss what the best solution is before doing a PR. My branch lossily converts the process name to a string. However this means that the Unicode replacement character is now part of those process names. The character when encoded as UTF-8 is 3 bytes. This means that process names can now be longer than 15 bytes, or in other words, doing a name based comparison on the first 15 bytes, such as somewhat suggested in the documentation of the crate, is no longer easily possible. Maybe the solution instead is to just provide the name as an OsStr instead, keeping the bytes around as is. Rust recently made OsStr way more easily usable by allowing you to access its bytes directly.

@GuillaumeGomez
Copy link
Owner

Thanks for the detailed description! Using OsStr is the best solution here I think.

I see that you can get a process/thread name with pthread_getname_np or by reading the proc comm file. Not sure if it's worth it though.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants