Browse Source

Handle SIGHUP so child process are terminated when a terminal is closed

pull/60/head
Eric Radman 3 months ago
parent
commit
1ee4655789
3 changed files with 16 additions and 0 deletions
  1. +1
    -0
      NEWS
  2. +2
    -0
      entr.c
  3. +13
    -0
      system_test.sh

+ 1
- 0
NEWS View File

@ -2,6 +2,7 @@
- Use system file descriptor limits when max_user_watches is not accessible
- Return the exit status of the child process when the '-z' option is used
- Handle SIGHUP so child process are terminated when a terminal is closed
= Release History


+ 2
- 0
entr.c View File

@ -148,6 +148,8 @@ main(int argc, char *argv[]) {
err(1, "Failed to set SIGINT handler");
if (sigaction(SIGTERM, &act, NULL) != 0)
err(1, "Failed to set SIGTERM handler");
if (sigaction(SIGHUP, &act, NULL) != 0)
err(1, "Failed to set SIGHUP handler");
/* notification used to combine the one-shot and restart options */
act.sa_flags = 0;


+ 13
- 0
system_test.sh View File

@ -300,6 +300,19 @@ try "ensure that all shell subprocesses are terminated in restart mode"
kill -INT $bgpid ; zz
assert "$(cat $tmp/exec.out)" "$(printf 'running\ncaught signal')"
try "ensure that all shell subprocesses are terminated when terminal is closed"
setup
cat <<-SCRIPT > $tmp/go.sh
#!/bin/sh
trap 'echo "caught signal"; exit' TERM
echo "running"; sleep 10
SCRIPT
chmod +x $tmp/go.sh
ls $tmp/file2 | ./entr -r sh -c "$tmp/go.sh" 2> /dev/null > $tmp/exec.out &
bgpid=$! ; zz
kill -HUP $bgpid ; zz
assert "$(cat $tmp/exec.out)" "$(printf 'running\ncaught signal')"
try "exit with no action when restart and dirwatch flags are combined"
setup
echo "started." > $tmp/file1


Loading…
Cancel
Save