Skip to content

Commit 7a0a55f

Browse files
committed
Implement os.setsid
1 parent 1c26308 commit 7a0a55f

File tree

7 files changed

+59
-2
lines changed

7 files changed

+59
-2
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,22 @@ long getSid(VirtualFrame frame, long pid,
673673
}
674674
}
675675

676+
@Builtin(name = "setsid")
677+
@GenerateNodeFactory
678+
public abstract static class SetSidNode extends PythonBuiltinNode {
679+
680+
@Specialization
681+
Object setsid(VirtualFrame frame,
682+
@CachedLibrary("getPosixSupport()") PosixSupportLibrary posixLib) {
683+
try {
684+
posixLib.setsid(getPosixSupport());
685+
} catch (PosixException e) {
686+
throw raiseOSErrorFromPosixException(frame, e);
687+
}
688+
return PNone.NONE;
689+
}
690+
}
691+
676692
@Builtin(name = "open", minNumOfPositionalArgs = 2, parameterNames = {"path", "flags", "mode"}, keywordOnlyNames = {"dir_fd"})
677693
@ArgumentClinic(name = "path", conversionClass = PathConversionNode.class, args = {"false", "false"})
678694
@ArgumentClinic(name = "flags", conversion = ClinicConversion.Int)

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1997,6 +1997,12 @@ public long getsid(long pid) {
19971997
throw new UnsupportedPosixFeatureException("Emulated getsid not supported");
19981998
}
19991999

2000+
@ExportMessage
2001+
@SuppressWarnings("static-method")
2002+
public long setsid() {
2003+
throw new UnsupportedPosixFeatureException("Emulated getsid not supported");
2004+
}
2005+
20002006
@ExportMessage
20012007
@SuppressWarnings("static-method")
20022008
public TruffleString ctermid() {

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,13 @@ final long getsid(long pid,
674674
return nativeLib.getsid(nativePosixSupport, pid);
675675
}
676676

677+
@ExportMessage
678+
final long setsid(
679+
@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) throws PosixException {
680+
checkNotInImageBuildtime();
681+
return nativeLib.setsid(nativePosixSupport);
682+
}
683+
677684
@ExportMessage
678685
final TruffleString ctermid(@CachedLibrary("this.nativePosixSupport") PosixSupportLibrary nativeLib) throws PosixException {
679686
checkNotInImageBuildtime();

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,17 @@ final long getsid(long pid,
866866
}
867867
}
868868

869+
@ExportMessage
870+
final long setsid(
871+
@CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException {
872+
logEnter("setsid", "");
873+
try {
874+
return logExit("getsid", "%d", lib.setsid(delegate));
875+
} catch (PosixException e) {
876+
throw logException("setsid", e);
877+
}
878+
}
879+
869880
@ExportMessage
870881
public int mmapReadBytes(Object mmap, long index, byte[] bytes, int length,
871882
@CachedLibrary("this.delegate") PosixSupportLibrary lib) throws PosixException {
@@ -1323,8 +1334,8 @@ private static <T> T logExit(Level level, String msg, String argFmt, T retVal) {
13231334
return retVal;
13241335
}
13251336

1326-
private static <T> T logExit(String msg, String argFtm, T retVal) {
1327-
return logExit(DEFAULT_LEVEL, msg, argFtm, retVal);
1337+
private static <T> T logExit(String msg, String argFmt, T retVal) {
1338+
return logExit(DEFAULT_LEVEL, msg, argFmt, retVal);
13281339
}
13291340

13301341
@TruffleBoundary

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ private enum PosixNativeFunction {
215215
call_setpgid("(sint64,sint64):sint32"),
216216
call_getpgrp("():sint64"),
217217
call_getsid("(sint64):sint64"),
218+
call_setsid("():sint64"),
218219
call_ctermid("([sint8]):sint32"),
219220
call_setenv("([sint8], [sint8], sint32):sint32"),
220221
call_unsetenv("([sint8]):sint32"),
@@ -1156,6 +1157,16 @@ public long getsid(long pid,
11561157
return res;
11571158
}
11581159

1160+
@ExportMessage
1161+
public long setsid(
1162+
@Shared("invoke") @Cached InvokeNativeFunction invokeNode) throws PosixException {
1163+
long res = invokeNode.callLong(this, PosixNativeFunction.call_setsid);
1164+
if (res < 0) {
1165+
throw getErrnoAndThrowPosixException(invokeNode);
1166+
}
1167+
return res;
1168+
}
1169+
11591170
@ExportMessage
11601171
public TruffleString ctermid(@Shared("invoke") @Cached InvokeNativeFunction invokeNode,
11611172
@Shared("tsFromBytes") @Cached TruffleString.FromByteArrayNode fromByteArrayNode,

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
@@ -286,6 +286,8 @@ public abstract class PosixSupportLibrary extends Library {
286286

287287
public abstract long getsid(Object receiver, long pid) throws PosixException;
288288

289+
public abstract long setsid(Object receiver) throws PosixException;
290+
289291
public abstract TruffleString ctermid(Object receiver) throws PosixException;
290292

291293
// note: this leaks memory in nfi backend and is not synchronized

graalpython/python-libposix/src/posix.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,10 @@ int64_t call_getsid(int64_t pid) {
577577
return getsid(pid);
578578
}
579579

580+
int64_t call_setsid() {
581+
return setsid();
582+
}
583+
580584
int32_t call_ctermid(char *buf) {
581585
return ctermid(buf) == NULL ? -1 : 0;
582586
}

0 commit comments

Comments
 (0)