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.
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.