Skip to content

Commit 27a4c92

Browse files
committed
[GR-46660] Add support for geteuid in os module
PullRequest: graalpython/2836
2 parents b643ade + febbc4a commit 27a4c92

File tree

7 files changed

+42
-0
lines changed

7 files changed

+42
-0
lines changed

graalpython/com.oracle.graal.python.cext/posix/posix.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ int64_t call_getuid() {
549549
return getuid();
550550
}
551551

552+
int64_t call_geteuid() {
553+
return geteuid();
554+
}
555+
552556
int64_t call_getgid() {
553557
return getgid();
554558
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ public void postInitialize(Python3Core core) {
351351

352352
if (posixLib.getBackend(posixSupport).toJavaStringUncached().equals("java")) {
353353
posix.setAttribute(toTruffleStringUncached("statvfs"), PNone.NO_VALUE);
354+
posix.setAttribute(toTruffleStringUncached("geteuid"), PNone.NO_VALUE);
354355
}
355356
}
356357

@@ -559,6 +560,15 @@ long getUid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
559560
}
560561
}
561562

563+
@Builtin(name = "geteuid", minNumOfPositionalArgs = 0)
564+
@GenerateNodeFactory
565+
public abstract static class GetEUidNode extends PythonBuiltinNode {
566+
@Specialization
567+
long getUid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
568+
return posixLib.geteuid(getPosixSupport());
569+
}
570+
}
571+
562572
@Builtin(name = "getgid", minNumOfPositionalArgs = 0)
563573
@GenerateNodeFactory
564574
public abstract static class GetGidNode extends PythonBuiltinNode {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1947,6 +1947,13 @@ public long getuid() {
19471947
return 1000;
19481948
}
19491949

1950+
@ExportMessage
1951+
@SuppressWarnings("static-method")
1952+
@TruffleBoundary
1953+
public long geteuid() {
1954+
throw new UnsupportedPosixFeatureException("Emulated geteuid not supported");
1955+
}
1956+
19501957
@ExportMessage
19511958
@SuppressWarnings("static-method")
19521959
@TruffleBoundary

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,12 @@ final long getuid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary
629629
return nativeLib.getuid(nativePosixSupport);
630630
}
631631

632+
@ExportMessage
633+
final long geteuid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) {
634+
checkNotInImageBuildtime();
635+
return nativeLib.geteuid(nativePosixSupport);
636+
}
637+
632638
@ExportMessage
633639
final long getgid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) {
634640
checkNotInImageBuildtime();

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,13 @@ final long getuid(
805805
return logExit("getuid", "%d", lib.getuid(delegate));
806806
}
807807

808+
@ExportMessage
809+
final long geteuid(
810+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {
811+
logEnter("geteuid", "");
812+
return logExit("geteuid", "%d", lib.geteuid(delegate));
813+
}
814+
808815
@ExportMessage
809816
final long getgid(
810817
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ private enum PosixNativeFunction {
207207
call_wtermsig("(sint32):sint32"),
208208
call_wstopsig("(sint32):sint32"),
209209
call_getuid("():sint64"),
210+
call_geteuid("():sint64"),
210211
call_getgid("():sint64"),
211212
call_getppid("():sint64"),
212213
call_getpgid("(sint64):sint64"),
@@ -1105,6 +1106,11 @@ public long getuid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
11051106
return invokeNode.callLong(this, PosixNativeFunction.call_getuid);
11061107
}
11071108

1109+
@ExportMessage
1110+
public long geteuid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
1111+
return invokeNode.callLong(this, PosixNativeFunction.call_geteuid);
1112+
}
1113+
11081114
@ExportMessage
11091115
public long getgid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
11101116
return invokeNode.callLong(this, PosixNativeFunction.call_getgid);

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ public abstract class PosixSupportLibrary extends Library {
272272

273273
public abstract long getuid(Object receiver);
274274

275+
public abstract long geteuid(Object receiver);
276+
275277
public abstract long getgid(Object receiver);
276278

277279
public abstract long getppid(Object receiver);

0 commit comments

Comments
 (0)