-
-
Notifications
You must be signed in to change notification settings - Fork 550
Bugfix: Inappropriate truncate if argv[0] contains a '/' #1854
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
base: main
Are you sure you want to change the base?
Conversation
|
I think your change is added in the wrong place.
Technically htop does this. It was just in a different routine. |
|
Also, the pull request description look like it was generated by AI. The use of AI tool needs to be disclosed. |
I've inserted the change where
I just discovered that this actually happens in the functions
"Hey Siri, my htop isn't working properly. No, of course not. I confess that parts of the PR were written using Google If your suspicion stems from the fact that the PR looks like it came from an |
Your change there would apply to Linux only, and not other operating systems. And I suspect something is wrong.
The reasoning behind the change should be included in the commit description, not just on the PR description. Also, cut out literal explanations of the code. We all can read the patch content itself. An AI would often explain what's literally in the code in order to "fill the number of words" because otherwise it would have nothing else to draw information from. For programmers that are competent, such information is useless noise. That's why I can suspect about the AI use. |
That issue is some regression that came about when the code was refactored in preparation of other changes.
Half of the htop team is based in the heart of Europe; the remaining people are scattered around the globe. And regarding languages: I've seen projects where people regularly post in all kinds of languages. Not that I want to encourage testing how far you can stretch our ability to understand your PR, but in the end, code usually speaks for itself, and figuring out how to understand one another is rarely the real problem. ;-)
No problem with this long report. In fact, having a detailed list of steps to reproduce with a root cause analysis and all is really helpful evaluating the resulting PR. And while @Explorer09 is quite sensitive on the topic of AI/LLM use, the overall stand is a bit more liberal among the maintainers. The important part is that proper attribution of the code is possible (thus we ask to disclose if the actual code contribution was done using these tools and to what extend), but this does not translate/apply to purely accompanying material like issue/PR discussions¹. I'm part of some group reading code review for fun and profit and properly understanding the code enough to actually file helpful reports is quite some effort to do right² and takes sometime more time than only finding the issues³. I had a fight with this issue a while back myself, when I ported the command line code to be re-used across platforms in #388, #1365, and several other PRs touching that code. So it is kinda notorious for these kind of edge cases. I think a somewhat better heuristic for most cases is detection of ¹Though a code example demonstrating something should be marked as generated if applicable. |
This PR aims to fix the bug described in issue #1817.
To start, I want to present a small program that triggers the described issue.
Let's call it
issue1817testfile.c:The described issue occurs in the code of
LinuxProcessTable.c:When the option "Show program path" is not enabled, this program is displayed
as
"3]"inhtop, instead of showing the full text.Problem Explanation
The issue arises because we search for the
/character to split the commandline, which works fine in most cases. However, the command line in
/proc/<pid>/cmdlinecan have the following formats:/home/foobar/path/to/executable./relative/path/to/executablerelative/path/to/executableThe current implementation assumes that encountering a
/is always a validseparator for the path. This can cause problems when a program modifies
argv[0], leading to incomplete or truncated commands beingdisplayed in
htop.Proposed Fix
The most efficient approach is to filter out cases where we deal with absolute
(
/) or relative (./) paths. These are the most common command line formats.We can treat these as paths that should be split by the
/character.For case (3) where no leading
./is given (e.g.,path/to/executable),we can continue outputting the full string, acknowledging that this may occur
rarely. My argument is:
"It's better to show too much information than too little."
Alternatively, we could read the target from the symlink
/proc/<pid>/exeand compare it to the content of the first string in
/proc/<pid>/cmdline:For example, if
/proc/<pid>/exepoints to/home/foobar/path/to/exefile,we would need to locate
exefilein the first string of/proc/<pid>/cmdlineand set
tokenStartto that index (ifexefileis found in the string).However, this would only solve another special case that practically never
or extremely rarely occurs. Therefore, I have ignored these
type 3 paths ("path/to/executable") for now.
Edge Cases
There is still a small chance that a program path could sneak into the
output due to unusual cases, but this is rare. It’s important to note that even
with this fix, some edge cases might still result in full path being shown.
Therefore, the goal here is to minimize errors, but we can't guarantee 100%
coverage for all possible edge cases.
But I think my patch results in the displayed paths being more useful to the
user in individual cases than the original code.