-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
8299665: /proc/self/stat parsing in libmanagement broken by execname with spaces #14107
Conversation
👋 Welcome back kevinw! A progress list of the required criteria for merging this PR into |
@kevinjwalls The following labels will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command. |
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.
How do you test the issue is fixed now?
Is there any test case which fails without your fix and passes with it?
Hi - I tested manually, renaming the java executable to something with a space, then query the OperatingSystem MBean, and see something like: CommittedVirtualMemorySize = (java.lang.Long) 36202319872 (which is the same/similar to another run These are lines like: $ cat /proc/9496/stat That's a different run, where 36260237312 was the value we wanted. If "java" becomes "this is java" (with 2 spaces), then we read field 21, not field 23 from the line of data and show zero. It's quite a niche thing to do so I didn't add a test that copied the java binary under test to a new name with a space in it... |
Thank you for explanation! Looks good. |
@kevinjwalls This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 45 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
Thanks @sspitsyn and @alexmenkov for the reviews! |
/integrate |
Going to push as commit 17ef8a4.
Your commit was automatically rebased without conflicts. |
@kevinjwalls Pushed as commit 17ef8a4. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Code that parses /proc/self/stat may be broken if the executable name contains spaces.
We have code that does this correctly, and code that does not.
UnixOperatingSystem.c is Linux-specific OS code, and has vread_statdata which correctly uses strrchr to find the last ) and parses from there.
OperatingSystemImpl.c the generic, not Linux-specific code, is not OK, as Java_com_sun_management_internal_OperatingSystemImpl_getCommittedVirtualMemorySize0 has a problematic fscanf call.
But the problematic fscanf call is Linux-specific: we use ifdef to create OS-specific implementations.
Need to change the fscanf of /proc/self/stat to do the same buffered read as read_ticks in UnixOperatingSystem.c (the Linux-specific code), with strrchr to read past the ) of the execname.
Moving the actually-Linux-specific getCommittedVirtualMemorySize0 to be with the other Linux-specific code means it can just use the existing method for accessing /proc/self/stat.
It does however call throw_internal_error, which is then not accessible. So that function can be shared in the libmanagement_ext.h/.c for both uses.
The call to throw_internal_error is working: if I change the code to fail, it reports a java.lang.InternalError as it would before.
Existing tests still pass:
i.e. test/jdk/com/sun/management/OperatingSystemMXBean/GetCommittedVirtualMemorySize.java
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/14107/head:pull/14107
$ git checkout pull/14107
Update a local copy of the PR:
$ git checkout pull/14107
$ git pull https://git.openjdk.org/jdk.git pull/14107/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 14107
View PR using the GUI difftool:
$ git pr show -t 14107
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/14107.diff
Webrev
Link to Webrev Comment