mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Merge remote-tracking branch 'origin/topic/jsiwek/raw-exec-pgrp'
* origin/topic/jsiwek/raw-exec-pgrp: Kill raw input reader's child by process group. BIT-1081 #merged
This commit is contained in:
commit
97cb04aae2
4 changed files with 19 additions and 21891 deletions
1
Makefile
1
Makefile
|
@ -65,6 +65,7 @@ test:
|
||||||
|
|
||||||
test-all: test
|
test-all: test
|
||||||
test -d aux/broctl && ( cd aux/broctl && make test )
|
test -d aux/broctl && ( cd aux/broctl && make test )
|
||||||
|
test -d aux/btest && ( cd aux/btest && make test )
|
||||||
|
|
||||||
configured:
|
configured:
|
||||||
@test -d $(BUILD) || ( echo "Error: No build/ directory found. Did you run configure?" && exit 1 )
|
@test -d $(BUILD) || ( echo "Error: No build/ directory found. Did you run configure?" && exit 1 )
|
||||||
|
|
2
VERSION
2
VERSION
|
@ -1 +1 @@
|
||||||
2.1-1368
|
2.1-1370
|
||||||
|
|
|
@ -73,15 +73,15 @@ void Raw::DoClose()
|
||||||
|
|
||||||
if ( execute && childpid > 0 && kill(childpid, 0) == 0 )
|
if ( execute && childpid > 0 && kill(childpid, 0) == 0 )
|
||||||
{
|
{
|
||||||
// kill child process
|
// Kill child process group.
|
||||||
kill(childpid, SIGTERM);
|
kill(-childpid, SIGTERM);
|
||||||
|
|
||||||
if ( forcekill )
|
if ( forcekill )
|
||||||
{
|
{
|
||||||
usleep(200); // 200 msecs should be enough for anyone ;)
|
usleep(200); // 200 msecs should be enough for anyone ;)
|
||||||
|
|
||||||
if ( kill(childpid, 0) == 0 ) // perhaps it is already gone
|
if ( kill(childpid, 0) == 0 ) // perhaps it is already gone
|
||||||
kill(childpid, SIGKILL);
|
kill(-childpid, SIGKILL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -146,6 +146,11 @@ bool Raw::Execute()
|
||||||
else if ( childpid == 0 )
|
else if ( childpid == 0 )
|
||||||
{
|
{
|
||||||
// we are the child.
|
// we are the child.
|
||||||
|
|
||||||
|
// Obtain a process group w/ child's PID.
|
||||||
|
if ( setpgid(0, 0) == -1 )
|
||||||
|
_exit(251);
|
||||||
|
|
||||||
close(pipes[stdout_in]);
|
close(pipes[stdout_in]);
|
||||||
if ( dup2(pipes[stdout_out], stdout_fileno) == -1 )
|
if ( dup2(pipes[stdout_out], stdout_fileno) == -1 )
|
||||||
_exit(252);
|
_exit(252);
|
||||||
|
@ -180,6 +185,15 @@ bool Raw::Execute()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// we are the parent
|
// we are the parent
|
||||||
|
|
||||||
|
// Parent also sets child process group immediately to avoid a race.
|
||||||
|
if ( setpgid(childpid, childpid) == -1 )
|
||||||
|
{
|
||||||
|
char buf[256];
|
||||||
|
strerror_r(errno, buf, sizeof(buf));
|
||||||
|
Warning(Fmt("Could not set child process group: %s", buf));
|
||||||
|
}
|
||||||
|
|
||||||
if ( ! UnlockForkMutex() )
|
if ( ! UnlockForkMutex() )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue