Skip to content

Commit

Permalink
kernel: kill subprocess before closing pipe to it (#5666)
Browse files Browse the repository at this point in the history
Otherwise we see issues like this on Linux:

    gap> d := DirectoryCurrent();;
    gap> f := Filename(DirectoriesSystemPrograms(), "rev");;
    gap> s := InputOutputLocalProcess(d,f,[]);;
    gap> Sleep(1);
    gap> CloseStream(s); Print("\n");
    rev: stdin
  • Loading branch information
fingolfin authored Mar 12, 2024
1 parent 335ed14 commit c8e9ab4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/iostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1010,10 +1010,10 @@ static Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)

// 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);
kill(PtyIOStreams[pty].childPID, SIGTERM);
// 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);
Expand Down
5 changes: 5 additions & 0 deletions tst/testspecial/child-process.g
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
d := DirectoryCurrent();;
f := Filename(DirectoriesSystemPrograms(), "rev");;
s := InputOutputLocalProcess(d,f,[]);;
Sleep(1);
CloseStream(s); Print("\n");
7 changes: 7 additions & 0 deletions tst/testspecial/child-process.g.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gap> d := DirectoryCurrent();;
gap> f := Filename(DirectoriesSystemPrograms(), "rev");;
gap> s := InputOutputLocalProcess(d,f,[]);;
gap> Sleep(1);
gap> CloseStream(s); Print("\n");

gap> QUIT;

0 comments on commit c8e9ab4

Please sign in to comment.