mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-08 19:26:48 +00:00
The web app (wsgi.py), novncd and socketiod set SIGCHLD to SIG_IGN at
import. The kernel then reaps every child at once, so subprocess loses
the exit status and a failing command reports 0, in the server and in
anything else run in that process: the test suite had to reset the
signal in two tests.
It was added in 2023 against one defunct bash per gunicorn worker and
per novncd. That bash came from the settings template of the time,
which ran .dec_ldap_pwd.sh with Popen and never waited for it; the
template stopped doing that in 561fedf. A settings.py still holding
that line leaves at most one zombie per process, not a growing number.
- wsgi.py, novncd, socketiod: the global SIG_IGN is removed. subprocess
reaps its own children, websockify installs its own SIGCHLD reaper
for novncd's connection processes, and novncd's SSH tunnels wait for
their ssh process.
- socketiod: the pty child execs consolecallback instead of running it
and then returning into the server's code; disconnect reaps that
child (waitpid) instead of any child (wait).
- The settings template drops its unused subprocess import; the two
test workarounds are removed.
New tests load the web app and novncd in a fresh interpreter and check
that SIGCHLD is untouched and a failing command still returns 1; both
fail on the previous code. A patched novncd in the test container
served five connections and left no child behind.
42 lines
1.6 KiB
Python
42 lines
1.6 KiB
Python
import os
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
SOCKETIOD = ROOT / "console" / "socketiod"
|
|
|
|
|
|
class SocketiodDisabledTestCase(unittest.TestCase):
|
|
"""socketiod must refuse to start unless explicitly enabled."""
|
|
|
|
def test_socketiod_exits_when_serial_console_disabled(self):
|
|
# The settings module lives in a temporary directory, so the test does
|
|
# not write into the source tree (read-only checkouts, --parallel).
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
(Path(tmp) / "socketiod_disabled_settings.py").write_text(
|
|
"from webvirtcloud.settings import * # noqa\n"
|
|
"SERIAL_CONSOLE_ENABLED = False\n"
|
|
"SOCKETIO_HOST = '127.0.0.1'\n"
|
|
"SOCKETIO_PORT = 0\n"
|
|
)
|
|
env = dict(
|
|
os.environ,
|
|
DJANGO_SETTINGS_MODULE="socketiod_disabled_settings",
|
|
PYTHONPATH=os.pathsep.join([tmp, str(ROOT)]),
|
|
)
|
|
try:
|
|
result = subprocess.run(
|
|
[sys.executable, str(SOCKETIOD)],
|
|
cwd=ROOT,
|
|
env=env,
|
|
capture_output=True,
|
|
text=True,
|
|
timeout=20,
|
|
)
|
|
except subprocess.TimeoutExpired:
|
|
self.fail("socketiod kept running although SERIAL_CONSOLE_ENABLED=False")
|
|
self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr)
|
|
self.assertIn("SERIAL_CONSOLE_ENABLED", result.stderr)
|