mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 843361 - Clean up use of statics when enumerating procs r=blassey
This commit is contained in:
parent
43eda0fd9c
commit
c8dcdb08e2
@ -1502,12 +1502,11 @@ public class GeckoAppShell
|
|||||||
boolean callback(int pid);
|
boolean callback(int pid);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sPidColumn = -1;
|
|
||||||
static int sUserColumn = -1;
|
|
||||||
private static void EnumerateGeckoProcesses(GeckoProcessesVisitor visiter) {
|
private static void EnumerateGeckoProcesses(GeckoProcessesVisitor visiter) {
|
||||||
|
int pidColumn = -1;
|
||||||
|
int userColumn = -1;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// run ps and parse its output
|
// run ps and parse its output
|
||||||
java.lang.Process ps = Runtime.getRuntime().exec("ps");
|
java.lang.Process ps = Runtime.getRuntime().exec("ps");
|
||||||
BufferedReader in = new BufferedReader(new InputStreamReader(ps.getInputStream()),
|
BufferedReader in = new BufferedReader(new InputStreamReader(ps.getInputStream()),
|
||||||
@ -1516,30 +1515,28 @@ public class GeckoAppShell
|
|||||||
String headerOutput = in.readLine();
|
String headerOutput = in.readLine();
|
||||||
|
|
||||||
// figure out the column offsets. We only care about the pid and user fields
|
// figure out the column offsets. We only care about the pid and user fields
|
||||||
if (sPidColumn == -1 || sUserColumn == -1) {
|
StringTokenizer st = new StringTokenizer(headerOutput);
|
||||||
StringTokenizer st = new StringTokenizer(headerOutput);
|
|
||||||
|
int tokenSoFar = 0;
|
||||||
int tokenSoFar = 0;
|
while (st.hasMoreTokens()) {
|
||||||
while(st.hasMoreTokens()) {
|
String next = st.nextToken();
|
||||||
String next = st.nextToken();
|
if (next.equalsIgnoreCase("PID"))
|
||||||
if (next.equalsIgnoreCase("PID"))
|
pidColumn = tokenSoFar;
|
||||||
sPidColumn = tokenSoFar;
|
else if (next.equalsIgnoreCase("USER"))
|
||||||
else if (next.equalsIgnoreCase("USER"))
|
userColumn = tokenSoFar;
|
||||||
sUserColumn = tokenSoFar;
|
tokenSoFar++;
|
||||||
tokenSoFar++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// alright, the rest are process entries.
|
// alright, the rest are process entries.
|
||||||
String psOutput = null;
|
String psOutput = null;
|
||||||
while ((psOutput = in.readLine()) != null) {
|
while ((psOutput = in.readLine()) != null) {
|
||||||
String[] split = psOutput.split("\\s+");
|
String[] split = psOutput.split("\\s+");
|
||||||
if (split.length <= sPidColumn || split.length <= sUserColumn)
|
if (split.length <= pidColumn || split.length <= userColumn)
|
||||||
continue;
|
continue;
|
||||||
int uid = android.os.Process.getUidForName(split[sUserColumn]);
|
int uid = android.os.Process.getUidForName(split[userColumn]);
|
||||||
if (uid == android.os.Process.myUid() &&
|
if (uid == android.os.Process.myUid() &&
|
||||||
!split[split.length - 1].equalsIgnoreCase("ps")) {
|
!split[split.length - 1].equalsIgnoreCase("ps")) {
|
||||||
int pid = Integer.parseInt(split[sPidColumn]);
|
int pid = Integer.parseInt(split[pidColumn]);
|
||||||
boolean keepGoing = visiter.callback(pid);
|
boolean keepGoing = visiter.callback(pid);
|
||||||
if (keepGoing == false)
|
if (keepGoing == false)
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user