Skip to content

Commit

Permalink
kernel: kill subprocess before closing pipe to it
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 committed Mar 8, 2024
1 parent 768a20c commit f92de30
Showing 1 changed file with 1 addition 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

0 comments on commit f92de30

Please sign in to comment.