Skip to content

Commit 50b7be0

Browse files
committed
[GR-12628] Fix starting a Python process when all permissions are disabled
PullRequest: graalpython/286
2 parents 2bfb146 + cf18df7 commit 50b7be0

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/interop/JavaInteropTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@
4646

4747
import java.io.ByteArrayOutputStream;
4848
import java.io.IOException;
49+
import java.io.UnsupportedEncodingException;
4950
import java.util.Arrays;
5051
import java.util.List;
51-
import java.io.UnsupportedEncodingException;
5252

5353
import org.graalvm.polyglot.Context;
5454
import org.graalvm.polyglot.Context.Builder;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import java.util.Map.Entry;
4242
import java.util.ServiceLoader;
4343
import java.util.function.Supplier;
44+
import java.util.logging.Level;
4445

4546
import org.graalvm.nativeimage.ImageInfo;
4647

@@ -652,10 +653,14 @@ private Source getSource(String basename, String prefix) {
652653
Env env = ctxt.getEnv();
653654
TruffleFile file = env.getTruffleFile(prefix + suffix);
654655
try {
655-
return getLanguage().newSource(ctxt, file, basename);
656+
if (file.exists()) {
657+
return getLanguage().newSource(ctxt, file, basename);
658+
}
656659
} catch (SecurityException | IOException t) {
657-
throw new RuntimeException("Could not read core library from " + file);
660+
// fall through;
658661
}
662+
PythonLanguage.getLogger().log(Level.SEVERE, "Startup failed, could not read core library from " + file + ". Maybe you need to set python.CoreHome and python.StdLibHome.");
663+
throw new RuntimeException();
659664
}
660665
}
661666

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Object setInheritable(int fd, @SuppressWarnings("unused") Object inheritable) {
356356
@GenerateNodeFactory
357357
@TypeSystemReference(PythonArithmeticTypes.class)
358358
public abstract static class StatNode extends PythonBinaryBuiltinNode {
359-
private final ConditionProfile fileNotFound = ConditionProfile.createBinaryProfile();
359+
private final BranchProfile fileNotFound = BranchProfile.create();
360360

361361
private static final int S_IFIFO = 0010000;
362362
private static final int S_IFCHR = 0020000;
@@ -386,8 +386,12 @@ long fileTimeToSeconds(FileTime t) {
386386
Object stat(String path, boolean followSymlinks) {
387387
TruffleFile f = getContext().getEnv().getTruffleFile(path);
388388
LinkOption[] linkOptions = followSymlinks ? new LinkOption[0] : new LinkOption[]{LinkOption.NOFOLLOW_LINKS};
389-
if (fileNotFound.profile(!f.exists(linkOptions))) {
390-
throw raise(FileNotFoundError, "No such file or directory: '%s'", path);
389+
try {
390+
if (!f.exists(linkOptions)) {
391+
throw fileNoFound(path);
392+
}
393+
} catch (SecurityException e) {
394+
throw fileNoFound(path);
391395
}
392396
int mode = 0;
393397
long size = 0;
@@ -475,6 +479,11 @@ Object stat(String path, boolean followSymlinks) {
475479
});
476480
}
477481

482+
private PException fileNoFound(String path) {
483+
fileNotFound.enter();
484+
throw raise(FileNotFoundError, "No such file or directory: '%s'", path);
485+
}
486+
478487
@TruffleBoundary(allowInlining = true, transferToInterpreterOnException = false)
479488
private static long strToLong(String name) throws NumberFormatException {
480489
return new Long(name).longValue();

0 commit comments

Comments
 (0)