Skip to content

Commit 0258c25

Browse files
committed
Native implementation of getsid() and getppid()
1 parent ad5d891 commit 0258c25

File tree

6 files changed

+88
-0
lines changed

6 files changed

+88
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,14 @@ int64_t call_getuid() {
471471
return getuid();
472472
}
473473

474+
int64_t call_getppid() {
475+
return getppid();
476+
}
477+
478+
int64_t call_getsid(int64_t pid) {
479+
return getsid(pid);
480+
}
481+
474482
int32_t get_errno() {
475483
return errno;
476484
}

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,35 @@ long getUid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
419419
}
420420
}
421421

422+
@Builtin(name = "getppid", minNumOfPositionalArgs = 0)
423+
@GenerateNodeFactory
424+
public abstract static class GetPpidNode extends PythonBuiltinNode {
425+
@Specialization
426+
long getPpid(@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
427+
return posixLib.getppid(getPosixSupport());
428+
}
429+
}
430+
431+
@Builtin(name = "getsid", minNumOfPositionalArgs = 1, parameterNames = {"pid"})
432+
@ArgumentClinic(name = "pid", conversionClass = PidtConversionNode.class)
433+
@GenerateNodeFactory
434+
public abstract static class GetSidNode extends PythonUnaryClinicBuiltinNode {
435+
@Override
436+
protected ArgumentClinicProvider getArgumentClinic() {
437+
return PosixModuleBuiltinsClinicProviders.GetSidNodeClinicProviderGen.INSTANCE;
438+
}
439+
440+
@Specialization
441+
long getSid(VirtualFrame frame, long pid,
442+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
443+
try {
444+
return posixLib.getsid(getPosixSupport(), pid);
445+
} catch (PosixException e) {
446+
throw raiseOSErrorFromPosixException(frame, e);
447+
}
448+
}
449+
}
450+
422451
@Builtin(name = "open", minNumOfPositionalArgs = 2, parameterNames = {"path", "flags", "mode"}, keywordOnlyNames = {"dir_fd"})
423452
@ArgumentClinic(name = "path", conversionClass = PathConversionNode.class, args = {"false", "false"})
424453
@ArgumentClinic(name = "flags", conversion = ClinicConversion.Int)

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1572,6 +1572,18 @@ public long getuid() {
15721572
return 1000;
15731573
}
15741574

1575+
@ExportMessage
1576+
@SuppressWarnings("static-method")
1577+
public long getppid() {
1578+
throw new UnsupportedPosixFeatureException("Emulated getppid not supported");
1579+
}
1580+
1581+
@ExportMessage
1582+
@SuppressWarnings("static-method")
1583+
public long getsid(long pid) {
1584+
throw new UnsupportedPosixFeatureException("Emulated getsid not supported");
1585+
}
1586+
15751587
@ExportMessage
15761588
@TruffleBoundary
15771589
public int forkExec(Object[] executables, Object[] args, Object cwd, Object[] env, int stdinReadFd, int stdinWriteFd, int stdoutReadFd, int stdoutWriteFd, int stderrReadFd, int stderrWriteFd,

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,6 +668,24 @@ final long getuid(
668668
return logExit("getuid", "%d", lib.getuid(delegate));
669669
}
670670

671+
@ExportMessage
672+
final long getppid(
673+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) {
674+
logEnter("getppid", "");
675+
return logExit("getppid", "%d", lib.getuid(delegate));
676+
}
677+
678+
@ExportMessage
679+
final long getsid(long pid,
680+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException {
681+
logEnter("getsid", "%d", pid);
682+
try {
683+
return logExit("getsid", "%d", lib.getsid(delegate, pid));
684+
} catch (PosixException e) {
685+
throw logException("getsid", e);
686+
}
687+
}
688+
671689
@ExportMessage
672690
final int forkExec(Object[] executables, Object[] args, Object cwd, Object[] env, int stdinReadFd, int stdinWriteFd, int stdoutReadFd, int stdoutWriteFd, int stderrReadFd, int stderrWriteFd,
673691
int errPipeReadFd, int errPipeWriteFd, boolean closeFds, boolean restoreSignals, boolean callSetsid, int[] fdsToKeep,

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ private enum PosixNativeFunction {
149149
call_wtermsig("(sint32):sint32"),
150150
call_wstopsig("(sint32):sint32"),
151151
call_getuid("():sint64"),
152+
call_getppid("():sint64"),
153+
call_getsid("(sint64):sint64"),
152154
fork_exec("([sint8], [sint64], sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, sint32, [sint32], sint64):sint32");
153155

154156
private final String signature;
@@ -896,6 +898,21 @@ public long getuid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
896898
return invokeNode.callLong(this, PosixNativeFunction.call_getuid);
897899
}
898900

901+
@ExportMessage
902+
public long getppid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode) {
903+
return invokeNode.callLong(this, PosixNativeFunction.call_getppid);
904+
}
905+
906+
@ExportMessage
907+
public long getsid(long pid,
908+
@Shared("invoke") @Cached InvokeNativeFunction invokeNode) throws PosixException {
909+
long res = invokeNode.callLong(this, PosixNativeFunction.call_getsid, pid);
910+
if (res < 0) {
911+
throw getErrnoAndThrowPosixException(invokeNode);
912+
}
913+
return res;
914+
}
915+
899916
@ExportMessage
900917
public int forkExec(Object[] executables, Object[] args, Object cwd, Object[] env, int stdinReadFd, int stdinWriteFd, int stdoutReadFd, int stdoutWriteFd, int stderrReadFd, int stderrWriteFd,
901918
int errPipeReadFd, int errPipeWriteFd, boolean closeFds, boolean restoreSignals, boolean callSetsid, int[] fdsToKeep,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ public abstract class PosixSupportLibrary extends Library {
267267

268268
public abstract long getuid(Object receiver);
269269

270+
public abstract long getppid(Object receiver);
271+
272+
public abstract long getsid(Object receiver, long pid) throws PosixException;
273+
270274
public abstract int forkExec(Object receiver, Object[] executables, Object[] args, Object cwd, Object[] env, int stdinReadFd, int stdinWriteFd, int stdoutReadFd, int stdoutWriteFd,
271275
int stderrReadFd, int stderrWriteFd, int errPipeReadFd, int errPipeWriteFd, boolean closeFds, boolean restoreSignals, boolean callSetsid, int[] fdsToKeep) throws PosixException;
272276

0 commit comments

Comments
 (0)