prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Avocado crashed unexpectedly with the SIGINT
  When the SIGINT is sent to the avocado in the early stages the avocado will crash.
  This is happening on both runner legacy and nrunner. 
  
  ```
  avocado run /bin/true
  JOB ID     : ee66540de61211c164d9d9cb5b0e9aaf65dca8a2
  JOB LOG    : /home/jarichte/avocado/job-results/job-2021-05-25T16.36-ee66540/job.log
  ^CAvocado crashed unexpectedly:
  You can find details in /var/lib/avocado/data/crashes/avocado-traceback-2021-05-25_16:36:38-_m3ikjhl.log
  ```
  
  ```
  avocado run --test-runner=nrunner /bin/true
  JOB ID     : da09a60ab32ff647c79d919781f82db3543e107f
  JOB LOG    : /home/jarichte/avocado/job-results/job-2021-05-25T15.09-da09a60/job.log
  ^CAvocado crashed unexpectedly:
  You can find details in /var/lib/avocado/data/crashes/avocado-traceback-2021-05-25_15:09:37-my68_dsy.log
  ```
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `avocado/core/main.py`
  Content:
  ```
  1 # This program is free software; you can redistribute it and/or modify
  2 # it under the terms of the GNU General Public License as published by
  3 # the Free Software Foundation; specifically version 2 of the License.
  4 #
  5 # This program is distributed in the hope that it will be useful,
  6 # but WITHOUT ANY WARRANTY; without even the implied warranty of
  7 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8 #
  9 # See LICENSE for more details.
  10 #
  11 # Copyright: RedHat 2013-2014
  12 # Author: Lucas Meneghel Rodrigues <lmr@redhat.com>
  13 
  14 
  15 import os
  16 import sys
  17 import tempfile
  18 import time
  19 import traceback
  20 
  21 try:
  22     from avocado.core.settings import settings
  23 except ImportError:
  24     sys.stderr.write("Unable to import Avocado libraries, please verify "
  25                      "your installation, and if necessary reinstall it.\n")
  26     # This exit code is replicated from avocado/core/exit_codes.py and not
  27     # imported because we are dealing with import failures
  28     sys.exit(-1)
  29 
  30 
  31 def get_crash_dir():
  32     config = settings.as_dict()
  33     crash_dir_path = os.path.join(config.get('datadir.paths.data_dir'),
  34                                   "crashes")
  35     try:
  36         os.makedirs(crash_dir_path)
  37     except OSError:
  38         pass
  39     return crash_dir_path
  40 
  41 
  42 def handle_exception(*exc_info):
  43     # Print traceback if AVOCADO_LOG_DEBUG environment variable is set
  44     msg = "Avocado crashed:\n" + "".join(traceback.format_exception(*exc_info))
  45     msg += "\n"
  46     if os.environ.get("AVOCADO_LOG_DEBUG"):
  47         os.write(2, msg.encode('utf-8'))
  48     # Store traceback in data_dir or TMPDIR
  49     prefix = "avocado-traceback-"
  50     prefix += time.strftime("%F_%T") + "-"
  51     tmp, name = tempfile.mkstemp(".log", prefix, get_crash_dir())
  52     os.write(tmp, msg.encode('utf-8'))
  53     os.close(tmp)
  54     # Print friendly message in console-like output
  55     msg = ("Avocado crashed unexpectedly: %s\nYou can find details in %s\n"
  56            % (exc_info[1], name))
  57     os.write(2, msg.encode('utf-8'))
  58     # This exit code is replicated from avocado/core/exit_codes.py and not
  59     # imported because we are dealing with import failures
  60     sys.exit(-1)
  61 
  62 
  63 def main():
  64     sys.excepthook = handle_exception
  65     from avocado.core.app import AvocadoApp  # pylint: disable=E0611
  66 
  67     # Override tmp in case it's not set in env
  68     for attr in ("TMP", "TEMP", "TMPDIR"):
  69         if attr in os.environ:
  70             break
  71     else:   # TMP not set by user, use /var/tmp if exists
  72         # TMP not set by user in environment. Try to use /var/tmp to avoid
  73         # possible problems with "/tmp" being mounted as TMPFS without the
  74         # support for O_DIRECT
  75         if os.path.exists("/var/tmp"):
  76             os.environ["TMP"] = "/var/tmp"
  77     app = AvocadoApp()
  78     return app.run()
  79 
  80 
  81 if __name__ == '__main__':
  82     sys.exit(main())
  83
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/avocado/core/main.py b/avocado/core/main.py
  --- a/avocado/core/main.py
  +++ b/avocado/core/main.py
  @@ -19,6 +19,7 @@
   import traceback
   
   try:
  +    from avocado.core import exit_codes
       from avocado.core.settings import settings
   except ImportError:
       sys.stderr.write("Unable to import Avocado libraries, please verify "
  @@ -51,13 +52,16 @@
       tmp, name = tempfile.mkstemp(".log", prefix, get_crash_dir())
       os.write(tmp, msg.encode('utf-8'))
       os.close(tmp)
  -    # Print friendly message in console-like output
  -    msg = ("Avocado crashed unexpectedly: %s\nYou can find details in %s\n"
  -           % (exc_info[1], name))
  +    if exc_info[0] is KeyboardInterrupt:
  +        msg = "%s\nYou can find details in %s\n" % (exc_info[0].__doc__, name)
  +        exit_code = exit_codes.AVOCADO_JOB_INTERRUPTED
  +    else:
  +        # Print friendly message in console-like output
  +        msg = ("Avocado crashed unexpectedly: %s\nYou can find details in %s\n"
  +               % (exc_info[1], name))
  +        exit_code = exit_codes.AVOCADO_GENERIC_CRASH
       os.write(2, msg.encode('utf-8'))
  -    # This exit code is replicated from avocado/core/exit_codes.py and not
  -    # imported because we are dealing with import failures
  -    sys.exit(-1)
  +    sys.exit(exit_code)
   
   
   def main():
  
verification_info: {"golden_diff": "diff --git a/avocado/core/main.py b/avocado/core/main.py\n--- a/avocado/core/main.py\n+++ b/avocado/core/main.py\n@@ -19,6 +19,7 @@\n import traceback\n \n try:\n+    from avocado.core import exit_codes\n     from avocado.core.settings import settings\n except ImportError:\n     sys.stderr.write(\"Unable to import Avocado libraries, please verify \"\n@@ -51,13 +52,16 @@\n     tmp, name = tempfile.mkstemp(\".log\", prefix, get_crash_dir())\n     os.write(tmp, msg.encode('utf-8'))\n     os.close(tmp)\n-    # Print friendly message in console-like output\n-    msg = (\"Avocado crashed unexpectedly: %s\\nYou can find details in %s\\n\"\n-           % (exc_info[1], name))\n+    if exc_info[0] is KeyboardInterrupt:\n+        msg = \"%s\\nYou can find details in %s\\n\" % (exc_info[0].__doc__, name)\n+        exit_code = exit_codes.AVOCADO_JOB_INTERRUPTED\n+    else:\n+        # Print friendly message in console-like output\n+        msg = (\"Avocado crashed unexpectedly: %s\\nYou can find details in %s\\n\"\n+               % (exc_info[1], name))\n+        exit_code = exit_codes.AVOCADO_GENERIC_CRASH\n     os.write(2, msg.encode('utf-8'))\n-    # This exit code is replicated from avocado/core/exit_codes.py and not\n-    # imported because we are dealing with import failures\n-    sys.exit(-1)\n+    sys.exit(exit_code)\n \n \n def main():\n", "issue": "Avocado crashed unexpectedly with the SIGINT\nWhen the SIGINT is sent to the avocado in the early stages the avocado will crash.\r\nThis is happening on both runner legacy and nrunner. \r\n\r\n```\r\navocado run /bin/true\r\nJOB ID     : ee66540de61211c164d9d9cb5b0e9aaf65dca8a2\r\nJOB LOG    : /home/jarichte/avocado/job-results/job-2021-05-25T16.36-ee66540/job.log\r\n^CAvocado crashed unexpectedly:\r\nYou can find details in /var/lib/avocado/data/crashes/avocado-traceback-2021-05-25_16:36:38-_m3ikjhl.log\r\n```\r\n\r\n```\r\navocado run --test-runner=nrunner /bin/true\r\nJOB ID     : da09a60ab32ff647c79d919781f82db3543e107f\r\nJOB LOG    : /home/jarichte/avocado/job-results/job-2021-05-25T15.09-da09a60/job.log\r\n^CAvocado crashed unexpectedly:\r\nYou can find details in /var/lib/avocado/data/crashes/avocado-traceback-2021-05-25_15:09:37-my68_dsy.log\r\n```\n", "before_files": [{"content": "# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; specifically version 2 of the License.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n#\n# See LICENSE for more details.\n#\n# Copyright: RedHat 2013-2014\n# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>\n\n\nimport os\nimport sys\nimport tempfile\nimport time\nimport traceback\n\ntry:\n    from avocado.core.settings import settings\nexcept ImportError:\n    sys.stderr.write(\"Unable to import Avocado libraries, please verify \"\n                     \"your installation, and if necessary reinstall it.\\n\")\n    # This exit code is replicated from avocado/core/exit_codes.py and not\n    # imported because we are dealing with import failures\n    sys.exit(-1)\n\n\ndef get_crash_dir():\n    config = settings.as_dict()\n    crash_dir_path = os.path.join(config.get('datadir.paths.data_dir'),\n                                  \"crashes\")\n    try:\n        os.makedirs(crash_dir_path)\n    except OSError:\n        pass\n    return crash_dir_path\n\n\ndef handle_exception(*exc_info):\n    # Print traceback if AVOCADO_LOG_DEBUG environment variable is set\n    msg = \"Avocado crashed:\\n\" + \"\".join(traceback.format_exception(*exc_info))\n    msg += \"\\n\"\n    if os.environ.get(\"AVOCADO_LOG_DEBUG\"):\n        os.write(2, msg.encode('utf-8'))\n    # Store traceback in data_dir or TMPDIR\n    prefix = \"avocado-traceback-\"\n    prefix += time.strftime(\"%F_%T\") + \"-\"\n    tmp, name = tempfile.mkstemp(\".log\", prefix, get_crash_dir())\n    os.write(tmp, msg.encode('utf-8'))\n    os.close(tmp)\n    # Print friendly message in console-like output\n    msg = (\"Avocado crashed unexpectedly: %s\\nYou can find details in %s\\n\"\n           % (exc_info[1], name))\n    os.write(2, msg.encode('utf-8'))\n    # This exit code is replicated from avocado/core/exit_codes.py and not\n    # imported because we are dealing with import failures\n    sys.exit(-1)\n\n\ndef main():\n    sys.excepthook = handle_exception\n    from avocado.core.app import AvocadoApp  # pylint: disable=E0611\n\n    # Override tmp in case it's not set in env\n    for attr in (\"TMP\", \"TEMP\", \"TMPDIR\"):\n        if attr in os.environ:\n            break\n    else:   # TMP not set by user, use /var/tmp if exists\n        # TMP not set by user in environment. Try to use /var/tmp to avoid\n        # possible problems with \"/tmp\" being mounted as TMPFS without the\n        # support for O_DIRECT\n        if os.path.exists(\"/var/tmp\"):\n            os.environ[\"TMP\"] = \"/var/tmp\"\n    app = AvocadoApp()\n    return app.run()\n\n\nif __name__ == '__main__':\n    sys.exit(main())\n", "path": "avocado/core/main.py"}], "after_files": [{"content": "# This program is free software; you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation; specifically version 2 of the License.\n#\n# This program is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n#\n# See LICENSE for more details.\n#\n# Copyright: RedHat 2013-2014\n# Author: Lucas Meneghel Rodrigues <lmr@redhat.com>\n\n\nimport os\nimport sys\nimport tempfile\nimport time\nimport traceback\n\ntry:\n    from avocado.core import exit_codes\n    from avocado.core.settings import settings\nexcept ImportError:\n    sys.stderr.write(\"Unable to import Avocado libraries, please verify \"\n                     \"your installation, and if necessary reinstall it.\\n\")\n    # This exit code is replicated from avocado/core/exit_codes.py and not\n    # imported because we are dealing with import failures\n    sys.exit(-1)\n\n\ndef get_crash_dir():\n    config = settings.as_dict()\n    crash_dir_path = os.path.join(config.get('datadir.paths.data_dir'),\n                                  \"crashes\")\n    try:\n        os.makedirs(crash_dir_path)\n    except OSError:\n        pass\n    return crash_dir_path\n\n\ndef handle_exception(*exc_info):\n    # Print traceback if AVOCADO_LOG_DEBUG environment variable is set\n    msg = \"Avocado crashed:\\n\" + \"\".join(traceback.format_exception(*exc_info))\n    msg += \"\\n\"\n    if os.environ.get(\"AVOCADO_LOG_DEBUG\"):\n        os.write(2, msg.encode('utf-8'))\n    # Store traceback in data_dir or TMPDIR\n    prefix = \"avocado-traceback-\"\n    prefix += time.strftime(\"%F_%T\") + \"-\"\n    tmp, name = tempfile.mkstemp(\".log\", prefix, get_crash_dir())\n    os.write(tmp, msg.encode('utf-8'))\n    os.close(tmp)\n    if exc_info[0] is KeyboardInterrupt:\n        msg = \"%s\\nYou can find details in %s\\n\" % (exc_info[0].__doc__, name)\n        exit_code = exit_codes.AVOCADO_JOB_INTERRUPTED\n    else:\n        # Print friendly message in console-like output\n        msg = (\"Avocado crashed unexpectedly: %s\\nYou can find details in %s\\n\"\n               % (exc_info[1], name))\n        exit_code = exit_codes.AVOCADO_GENERIC_CRASH\n    os.write(2, msg.encode('utf-8'))\n    sys.exit(exit_code)\n\n\ndef main():\n    sys.excepthook = handle_exception\n    from avocado.core.app import AvocadoApp  # pylint: disable=E0611\n\n    # Override tmp in case it's not set in env\n    for attr in (\"TMP\", \"TEMP\", \"TMPDIR\"):\n        if attr in os.environ:\n            break\n    else:   # TMP not set by user, use /var/tmp if exists\n        # TMP not set by user in environment. Try to use /var/tmp to avoid\n        # possible problems with \"/tmp\" being mounted as TMPFS without the\n        # support for O_DIRECT\n        if os.path.exists(\"/var/tmp\"):\n            os.environ[\"TMP\"] = \"/var/tmp\"\n    app = AvocadoApp()\n    return app.run()\n\n\nif __name__ == '__main__':\n    sys.exit(main())\n", "path": "avocado/core/main.py"}]}