Skip to content

Commit

Permalink
[GAP] Patch CLOSE_PTY_IOSTREAM
Browse files Browse the repository at this point in the history
... to avoid hang when calling StopSingular(). See also
<oscar-system/Oscar.jl#4136>
  • Loading branch information
fingolfin committed Sep 25, 2024
1 parent ae07d56 commit 47ae579
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions G/GAP/bundled/patches/kill-then-wait.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
From 2253127bd7648a4f2dba3e2e800a0cbcb818c918 Mon Sep 17 00:00:00 2001
From: Max Horn <[email protected]>
Date: Tue, 24 Sep 2024 22:27:09 +0200
Subject: [PATCH] kernel: wait for child process to die before closing pty

---
src/iostream.c | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/iostream.c b/src/iostream.c
index 18db09901..68bdf6a4d 100644
--- a/src/iostream.c
+++ b/src/iostream.c
@@ -1007,13 +1007,11 @@ static Obj FuncSIGNAL_CHILD_IOSTREAM(Obj self, Obj stream, Obj sig)
static Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)
{
UInt pty = HashLockStreamIfAvailable(stream);
+ int status, retcode;

// Close down the child
- int status;
kill(PtyIOStreams[pty].childPID, SIGTERM);
- int retcode = close(PtyIOStreams[pty].ptyFD);
- if (retcode)
- Pr("Strange close return code %d\n", retcode, 0);
+
// GAP (or another library) might wait on this PID before
// we handle it. If that happens, waitpid will return -1.
retcode = waitpid(PtyIOStreams[pty].childPID, &status, WNOHANG);
@@ -1028,6 +1026,10 @@ static Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)
retcode = waitpid(PtyIOStreams[pty].childPID, &status, 0);
}

+ retcode = close(PtyIOStreams[pty].ptyFD);
+ if (retcode)
+ Pr("Strange close return code %d\n", retcode, 0);
+
PtyIOStreams[pty].inuse = 0;

FreeStream(pty);
--
2.46.0

0 comments on commit 47ae579

Please sign in to comment.