Skip to content

Commit

Permalink
Try harder to kill bad processes
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisJefferson authored and markuspf committed Oct 26, 2017
1 parent 1a4bee0 commit 6a721f7
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 16 deletions.
12 changes: 11 additions & 1 deletion src/iostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,17 @@ Obj FuncCLOSE_PTY_IOSTREAM(Obj self, Obj stream)
if (retcode)
Pr("Strange close return code %d\n", retcode, 0);
kill(PtyIOStreams[pty].childPID, SIGTERM);
retcode = waitpid(PtyIOStreams[pty].childPID, &status, 0);
retcode = waitpid(PtyIOStreams[pty].childPID, &status, WNOHANG);
if (retcode == 0) {
// Give process a second to quit
SySleep(1);
retcode = waitpid(PtyIOStreams[pty].childPID, &status, WNOHANG);
}
if (retcode == 0) {
// Hard kill process
kill(PtyIOStreams[pty].childPID, SIGKILL);
retcode = waitpid(PtyIOStreams[pty].childPID, &status, 0);
}
FreeStream(pty);
HashUnlock(PtyIOStreams);
return 0;
Expand Down
15 changes: 0 additions & 15 deletions tst/testbugfix/2006-01-11-t00130.tst

This file was deleted.

44 changes: 44 additions & 0 deletions tst/testbugfix/2017-10-20-runprocess.tst
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# This is based on an older fragile test - 2006/01/11 (MC)
# We want to check two cases:
# Firstly we ensure we read a whole line, by using a while loop
gap> d := DirectoryCurrent();;
gap> f := Filename(DirectoriesSystemPrograms(), "rev");;
gap> func1 := function()
> local line,s;
> if f <> fail then
> s := InputOutputLocalProcess(d,f,[]);;
> if PrintFormattingStatus(s) <> false then
> Print( "unexpected PrintFormattingStatus value\n" );
> fi;
> SetPrintFormattingStatus(s,false);
> AppendTo(s,"The cat sat on the mat\n");
> line := ReadLine(s);
> while line[Length(line)] <> '\n' do
> line := Concatenation(line, ReadLine(s));
> od;
> if line <> "tam eht no tas tac ehT\n" then
> Print( "There is a problem concerning a cat on a mat.\n" );
> fi;
> CloseStream(s);
> fi;
> end;;
gap> for i in [1..1000] do func1(); od;

# Here we might only get part of the line
# This is mainly to check we kill the process when it still has output
gap> func2 := function()
> local line,s;
> if f <> fail then
> s := InputOutputLocalProcess(d,f,[]);;
> if PrintFormattingStatus(s) <> false then
> Print( "unexpected PrintFormattingStatus value\n" );
> fi;
> SetPrintFormattingStatus(s,false);
> AppendTo(s,"The cat sat on the mat\n");
> if not StartsWith("tam eht no tas tac ehT\n", ReadLine(s)) then
> Print( "There is a problem concerning a cat on a mat.\n" );
> fi;
> CloseStream(s);
> fi;
> end;;
gap> for i in [1..1000] do func2(); od;

0 comments on commit 6a721f7

Please sign in to comment.