Skip to content

Commit 7c9c829

Browse files
committed
fix IndexOutOfBoundsException when waiting for child of a particular process group
1 parent e1f69c4 commit 7c9c829

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PosixModuleBuiltins.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1487,7 +1487,7 @@ PTuple waitpid(VirtualFrame frame, int pid, int options) {
14871487
} else {
14881488
throw raise(PythonBuiltinClassType.NotImplementedError, "Only 0 or WNOHANG are supported for waitpid");
14891489
}
1490-
} catch (ArrayIndexOutOfBoundsException e) {
1490+
} catch (IndexOutOfBoundsException e) {
14911491
throw raiseOSError(frame, OSErrorEnum.ESRCH.getNumber());
14921492
} catch (InterruptedException e) {
14931493
throw raiseOSError(frame, OSErrorEnum.EINTR.getNumber());
@@ -1969,7 +1969,7 @@ PNone kill(VirtualFrame frame, int pid, int signal,
19691969
if (isNode.execute(signal, value)) {
19701970
try {
19711971
context.getResources().sigterm(pid);
1972-
} catch (ArrayIndexOutOfBoundsException e) {
1972+
} catch (IndexOutOfBoundsException e) {
19731973
throw raiseOSError(frame, OSErrorEnum.ESRCH.getNumber());
19741974
}
19751975
return PNone.NONE;
@@ -1980,7 +1980,7 @@ PNone kill(VirtualFrame frame, int pid, int signal,
19801980
if (isNode.execute(signal, value)) {
19811981
try {
19821982
context.getResources().sigkill(pid);
1983-
} catch (ArrayIndexOutOfBoundsException e) {
1983+
} catch (IndexOutOfBoundsException e) {
19841984
throw raiseOSError(frame, OSErrorEnum.ESRCH.getNumber());
19851985
}
19861986
return PNone.NONE;
@@ -1990,7 +1990,7 @@ PNone kill(VirtualFrame frame, int pid, int signal,
19901990
if (isNode.execute(signal, dfl)) {
19911991
try {
19921992
context.getResources().sigdfl(pid);
1993-
} catch (ArrayIndexOutOfBoundsException e) {
1993+
} catch (IndexOutOfBoundsException e) {
19941994
throw raiseOSError(frame, OSErrorEnum.ESRCH.getNumber());
19951995
}
19961996
return PNone.NONE;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/runtime/PosixResources.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -393,34 +393,42 @@ private int nextFreePid() {
393393
}
394394
}
395395

396+
private Process getChild(int pid) throws IndexOutOfBoundsException {
397+
if (pid < 0) {
398+
return children.get(0); // we do not support process groups
399+
} else {
400+
return children.get(pid);
401+
}
402+
}
403+
396404
@TruffleBoundary(allowInlining = true)
397-
public void sigdfl(int pid) throws ArrayIndexOutOfBoundsException {
398-
children.get(pid); // just for the side-effect
405+
public void sigdfl(int pid) throws IndexOutOfBoundsException {
406+
getChild(pid); // just for the side-effect
399407
}
400408

401409
@TruffleBoundary(allowInlining = true)
402-
public void sigterm(int pid) throws ArrayIndexOutOfBoundsException {
403-
Process process = children.get(pid);
410+
public void sigterm(int pid) throws IndexOutOfBoundsException {
411+
Process process = getChild(pid);
404412
process.destroy();
405413
}
406414

407415
@TruffleBoundary(allowInlining = true)
408-
public void sigkill(int pid) throws ArrayIndexOutOfBoundsException {
409-
Process process = children.get(pid);
416+
public void sigkill(int pid) throws IndexOutOfBoundsException {
417+
Process process = getChild(pid);
410418
process.destroyForcibly();
411419
}
412420

413421
@TruffleBoundary(allowInlining = true)
414-
public int waitpid(int pid) throws ArrayIndexOutOfBoundsException, InterruptedException {
415-
Process process = children.get(pid);
422+
public int waitpid(int pid) throws IndexOutOfBoundsException, InterruptedException {
423+
Process process = getChild(pid);
416424
int exitStatus = process.waitFor();
417425
children.set(pid, null);
418426
return exitStatus;
419427
}
420428

421429
@TruffleBoundary(allowInlining = true)
422-
public int exitStatus(int pid) throws ArrayIndexOutOfBoundsException {
423-
Process process = children.get(pid);
430+
public int exitStatus(int pid) throws IndexOutOfBoundsException {
431+
Process process = getChild(pid);
424432
if (process.isAlive()) {
425433
return Integer.MIN_VALUE;
426434
} else {

0 commit comments

Comments
 (0)