try harder to get a number out of the pid file, trim whitespace, etc.
This commit is contained in:
parent
4c4a13570b
commit
4c7b451f69
|
@ -36,15 +36,31 @@ public class PidFileQuery extends PidQuery {
|
||||||
try {
|
try {
|
||||||
BufferedReader in =
|
BufferedReader in =
|
||||||
new BufferedReader(new FileReader(this.file));
|
new BufferedReader(new FileReader(this.file));
|
||||||
line = in.readLine();
|
while ((line = in.readLine()) != null) {
|
||||||
|
line = line.trim();
|
||||||
|
if (line.length() != 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
throw new SigarException(e.getMessage());
|
throw new SigarException(e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new SigarException(e.getMessage());
|
throw new SigarException(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int len = line.length();
|
||||||
|
StringBuffer number = new StringBuffer(len);
|
||||||
|
char[] chars = line.toCharArray();
|
||||||
|
for (int i=0; i<len; i++) {
|
||||||
|
char c = chars[i];
|
||||||
|
if (!Character.isDigit(c)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
number.append(c);
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.pid = Long.parseLong(line);
|
this.pid = Long.parseLong(number.toString());
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
throw new SigarException("Not a number: " + line);
|
throw new SigarException("Not a number: " + line);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue