diff options
author | Thomas Haller <thaller@redhat.com> | 2023-03-30 15:24:25 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-03-30 15:36:16 +0200 |
commit | 342ee618c75b350cf5cccf49f2bade85c5dfa3ea (patch) | |
tree | c6d60cb936cff0a768b605026b27ba19ee771740 | |
parent | d533072962a494e701cdb81954c3cd52bd805eca (diff) | |
download | NetworkManager-342ee618c75b350cf5cccf49f2bade85c5dfa3ea.tar.gz |
client/tests: don't do dup2() dance to pass file descriptor to "tools/test-cloud-meta-mock.py"
"preexec_fn" is not great, because it is not generally safe in multi
threaded code (and we don't know whether the test didn't start other
threads already, like a GDBus worker thread). Well, it probably is safe,
if you only call async signal safe code, but it's not clear what os.dup2()
does under the hood.
Just avoid that. We can pass on the FD directly.
-rwxr-xr-x | src/tests/client/test-client.py | 6 | ||||
-rwxr-xr-x | tools/test-cloud-meta-mock.py | 6 |
2 files changed, 3 insertions, 9 deletions
diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index 82c2919963..b6f7cf00a4 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -2160,18 +2160,14 @@ class TestNmCloudSetup(TestNmClient): # hallucinogenic substances. s.listen(5) - def pass_socket(): - os.dup2(s.fileno(), 3) - service_path = PathConfiguration.test_cloud_meta_mock_path() env = os.environ.copy() - env["LISTEN_FDS"] = "1" + env["LISTEN_FD"] = str(s.fileno()) p = subprocess.Popen( [sys.executable, service_path], stdin=subprocess.PIPE, env=env, pass_fds=(s.fileno(),), - preexec_fn=pass_socket, ) self.md_url = "http://%s:%d" % s.getsockname() diff --git a/tools/test-cloud-meta-mock.py b/tools/test-cloud-meta-mock.py index 262dc2ffb3..392955b8ad 100755 --- a/tools/test-cloud-meta-mock.py +++ b/tools/test-cloud-meta-mock.py @@ -68,11 +68,9 @@ class SocketHTTPServer(HTTPServer): # See sd_listen_fds(3) -fileno = os.getenv("LISTEN_FDS") +fileno = os.getenv("LISTEN_FD") if fileno is not None: - if fileno != "1": - raise Exception("Bad LISTEN_FDS") - s = socket.socket(fileno=3) + s = socket.socket(fileno=int(fileno)) else: addr = ("localhost", 0) s = socket.socket() |