Skip to content
Snippets Groups Projects
Commit 204ad707 authored by Amador Pahim's avatar Amador Pahim
Browse files

Fix SIGINT/SIGTERM

The SIGINT/SIGTERM handlers are currently broken. When we execute a
SIMPLE TEST, which ignores SIGINT/SIGTERM, the test process will not
finish on SIGINT/SIGTERM, becoming orphan.

Reproducer::

    $ cat /tmp/test.py
    #!/usr/bin/env python
    import signal
    import time

    if __name__ == "__main__":
        signal.signal(signal.SIGINT, signal.SIG_IGN)
        signal.signal(signal.SIGTERM, signal.SIG_IGN)
        signal.signal(signal.SIGQUIT, signal.SIG_IGN)
        while True:
            time.sleep(0.1)

    $ avocado run /tmp/test.py

Then play with `Ctrl+C` (once and twice), with `kill -2 <pid>` and
`kill <pid>`. Check if Avocado hangs or whether any process is left
behind.

Also, the only test we have for those cases is supposed to catch the
issue with SIGINT (test_interrupt.InterruptTest.test_badly_behaved), but
it's not really working.

This patch fixes the SIGINT/SIGTERM actions, as follows:

- When a SIGINT is sent to the main main process, we send the same SIGINT
  to all the children hope for the best. This reproduces the behaviour
  on Ctrl+C.
- On a second SIGINT (after the 2s ignore period), meaning process is
  still running, we send a SIGKILL to all the children.
- When a SIGTERM is sent to the main process, we now send a SIGKILL to
  all the children (instead of a SIGTERM), so any subprocess ignoring
  SIGTERM will be terminated anyway.

Reference: https://trello.com/c/5RPZPH4F


Signed-off-by: default avatarAmador Pahim <apahim@redhat.com>
parent 27e4301f
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment