Bug 839080
| Summary: | ProcessInfoQuery does not properly handle pidfile with line ending or whitespace | ||||||||
|---|---|---|---|---|---|---|---|---|---|
| Product: | [Other] RHQ Project | Reporter: | Elias Ross <genman> | ||||||
| Component: | Agent | Assignee: | Heiko W. Rupp <hrupp> | ||||||
| Status: | CLOSED CURRENTRELEASE | QA Contact: | Mike Foley <mfoley> | ||||||
| Severity: | unspecified | Docs Contact: | |||||||
| Priority: | unspecified | ||||||||
| Version: | 4.4 | CC: | hrupp, mazz | ||||||
| Target Milestone: | --- | ||||||||
| Target Release: | RHQ 4.5.0 | ||||||||
| Hardware: | Unspecified | ||||||||
| OS: | Unspecified | ||||||||
| Whiteboard: | |||||||||
| Fixed In Version: | Doc Type: | Bug Fix | |||||||
| Doc Text: | Story Points: | --- | |||||||
| Clone Of: | Environment: | ||||||||
| Last Closed: | 2013-09-01 10:19:00 UTC | Type: | Bug | ||||||
| Regression: | --- | Mount Type: | --- | ||||||
| Documentation: | --- | CRM: | |||||||
| Verified Versions: | Category: | --- | |||||||
| oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||||
| Cloudforms Team: | --- | Target Upstream Version: | |||||||
| Embargoed: | |||||||||
| Attachments: |
|
||||||||
Elias, you are referring to org.rhq.core.system.pquery.ProcessInfoQuery#getPidfileContents ? Heiko Yes, ProcessInfoQuery.java
This is what I suggest:
private String getPidfileContents(String pidfileName) {
String contents;
try {
FileInputStream fis = new FileInputStream(pidfileName);
BufferedReader br = new BufferedReader(new InputStreamReader(fis));
try {
contents = br.readLine();
if (contents == null) {
throw new IOException("empty pid");
}
} finally {
fis.close();
}
} catch (FileNotFoundException e) {
log.trace("pid not found");
return "";
} catch (IOException e) {
log.warn("unable to read pid file " + pidfileName, e);
return "";
}
return contents.trim();
}
Master 4f7c64deab77 Created attachment 612646 [details]
fix and test for this issue
I know this has been mostly addressed already, although I think my fix also contains more logging and more testing. There's some other cleanup as well.
Created attachment 612649 [details]
fix rebased against master
i pushed elias' patch: git commit to master: 6887631b55d273e017257eea610dc5b0df8af1fa Bulk closing of items that are on_qa and in old RHQ releases, which are out for a long time and where the issue has not been re-opened since. |
Description of problem: If a pidfile is created with extra whitespace, like \r\n, then the PID is never matched. Version-Release number of selected component (if applicable): RHQ 4.4 How reproducible: Create a pid with 'echo' or something. RHQ can't find it. Needs to strip whitespace when reading. Test is roughly: File pidfile = File.createTempFile("test", ".pid"); try { FileWriter fw = new FileWriter(pidfile); fw.write(" 3\r\n"); fw.close(); results = query.query("process|pidfile|match=" + pidfile.getCanonicalPath()); assert results.size() == 1 : results; assertPidExists(3, results, "pidfile had pid #3 in it and should have matched pid 3"); Fixed code is roughly: FileInputStream fis = new FileInputStream(pidfileName); BufferedReader br = new BufferedReader(new InputStreamReader(fis)); contents = br.readLine(); if (contents == null) { throw new IOException("empty pid"); } return contents.trim(); Patch is pending, with test cases.