Skip to content

Commit c4914bb

Browse files
authored
Merge pull request #6953 from cbridgha/CopeWNoPS
Tolerate missing ps
2 parents 6f873f2 + 798fbda commit c4914bb

File tree

5 files changed

+75
-85
lines changed

5 files changed

+75
-85
lines changed

dev/com.ibm.ws.kernel.boot.core/src/com/ibm/ws/kernel/boot/internal/FileShareLockProcessStatusImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,20 @@ public FileShareLockProcessStatusImpl(File file) {
2929
}
3030

3131
@Override
32-
public boolean isPossiblyRunning() {
32+
public ProcessStatus.State isPossiblyRunning() {
3333
if (file.exists()) {
3434
try {
3535
new FileOutputStream(file, true).close();
3636
} catch (FileNotFoundException e) {
3737
// "java.io.FileNotFoundException: C:\...\logs\console.log
3838
// (The process cannot access the file because it is being used
3939
// by another process.)"
40-
return true;
40+
return State.YES;
4141
} catch (IOException e) {
4242
Debug.printStackTrace(e);
4343
}
4444
}
4545

46-
return false;
46+
return State.NO;
4747
}
4848
}

dev/com.ibm.ws.kernel.boot.core/src/com/ibm/ws/kernel/boot/internal/PSProcessStatusImpl.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,19 +29,19 @@ public class PSProcessStatusImpl implements ProcessStatus {
2929

3030
/**
3131
* @param pid the pid, or the empty string if {@link #isPossiblyRunning} should
32-
* always return true
32+
* always return true
3333
*/
3434
public PSProcessStatusImpl(String pid) {
3535
this.pid = pid;
3636
}
3737

3838
@Override
39-
public boolean isPossiblyRunning() {
39+
public State isPossiblyRunning() {
4040
if (pid.isEmpty()) {
4141
// OS/400 shell does not support $!, so an empty PID is always
4242
// passed (unless native integration is enabled). Return true since
4343
// the process might be running.
44-
return true;
44+
return State.YES;
4545
}
4646

4747
ProcessBuilder pb = new ProcessBuilder();
@@ -68,8 +68,14 @@ public boolean isPossiblyRunning() {
6868
}
6969

7070
p.waitFor();
71-
return p.exitValue() == 0;
71+
if (p.exitValue() == 0)
72+
return State.YES;
73+
else
74+
return State.NO;
7275
} catch (IOException e) {
76+
if (e.getMessage().equals("No such file or directory")) // "ps" doesn't exist on this machine.
77+
// Return Undetermined since we can't poll the process
78+
return State.UNDETERMINED;
7379
Debug.printStackTrace(e);
7480
} catch (InterruptedException e) {
7581
Debug.printStackTrace(e);
@@ -78,6 +84,6 @@ public boolean isPossiblyRunning() {
7884
Utils.tryToClose(reader);
7985
}
8086

81-
return true;
87+
return State.YES;
8288
}
8389
}

dev/com.ibm.ws.kernel.boot.core/src/com/ibm/ws/kernel/boot/internal/ProcessStatus.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
* Monitors the status of a running process.
1515
*/
1616
public interface ProcessStatus {
17+
public enum State {
18+
YES, NO, UNDETERMINED
19+
}
20+
1721
/**
1822
* Returns true if the process is possibly running.
1923
*/
20-
boolean isPossiblyRunning();
24+
State isPossiblyRunning();
2125
}

0 commit comments

Comments
 (0)