From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/
Date: Wed, 7 Feb 2024 02:35:18 +0000 (UTC) [thread overview]
Message-ID: <1707267346.fa8e8f1895ed889aece2f67725df55d6ccf127fb.zmedico@gentoo> (raw)
commit: fa8e8f1895ed889aece2f67725df55d6ccf127fb
Author: Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sat Feb 3 23:41:45 2024 +0000
Commit: Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Wed Feb 7 00:55:46 2024 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fa8e8f18
socks5: Migrate to spawn returnproc parameter
Bug: https://bugs.gentoo.org/916566
Signed-off-by: Zac Medico <zmedico <AT> gentoo.org>
lib/portage/util/socks5.py | 36 +++++++++++++++++++-----------------
1 file changed, 19 insertions(+), 17 deletions(-)
diff --git a/lib/portage/util/socks5.py b/lib/portage/util/socks5.py
index fedb8599d5..6c68ff4106 100644
--- a/lib/portage/util/socks5.py
+++ b/lib/portage/util/socks5.py
@@ -1,10 +1,9 @@
# SOCKSv5 proxy manager for network-sandbox
-# Copyright 2015-2021 Gentoo Authors
+# Copyright 2015-2024 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2
import errno
import os
-import signal
import socket
import portage.data
@@ -22,7 +21,8 @@ class ProxyManager:
def __init__(self):
self.socket_path = None
- self._pids = []
+ self._proc = None
+ self._proc_waiter = None
def start(self, settings):
"""
@@ -51,9 +51,9 @@ class ProxyManager:
spawn_kwargs.update(
uid=portage_uid, gid=portage_gid, groups=userpriv_groups, umask=0o077
)
- self._pids = spawn(
+ self._proc = spawn(
[_python_interpreter, server_bin, self.socket_path],
- returnpid=True,
+ returnproc=True,
**spawn_kwargs,
)
@@ -61,12 +61,19 @@ class ProxyManager:
"""
Stop the SOCKSv5 server.
"""
- for p in self._pids:
- os.kill(p, signal.SIGINT)
- os.waitpid(p, 0)
+ if self._proc is not None:
+ self._proc.terminate()
+ loop = asyncio.get_event_loop()
+ if self._proc_waiter is None:
+ self._proc_waiter = asyncio.ensure_future(self._proc.wait(), loop)
+ if loop.is_running():
+ self._proc_waiter.add_done_callback(lambda future: future.result())
+ else:
+ loop.run_until_complete(self._proc_waiter)
self.socket_path = None
- self._pids = []
+ self._proc = None
+ self._proc_waiter = None
def is_running(self):
"""
@@ -80,16 +87,11 @@ class ProxyManager:
"""
Wait for the proxy socket to become ready. This method is a coroutine.
"""
+ if self._proc_waiter is None:
+ self._proc_waiter = asyncio.ensure_future(self._proc.wait())
while True:
- try:
- wait_retval = os.waitpid(self._pids[0], os.WNOHANG)
- except OSError as e:
- if e.errno == errno.EINTR:
- continue
- raise
-
- if wait_retval is not None and wait_retval != (0, 0):
+ if self._proc_waiter.done():
raise OSError(3, "No such process")
try:
next reply other threads:[~2024-02-07 2:35 UTC|newest]
Thread overview: 47+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-07 2:35 Zac Medico [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-08-15 17:30 [gentoo-commits] proj/portage:master commit in: lib/portage/util/ Mike Gilbert
2024-05-27 20:02 Zac Medico
2024-03-07 20:42 Mike Gilbert
2024-03-01 16:20 Mike Gilbert
2024-02-09 8:22 Zac Medico
2023-10-02 21:40 James Le Cuirot
2023-07-26 14:30 Mike Gilbert
2023-07-26 7:58 Sam James
2023-07-26 7:58 Sam James
2023-06-29 8:19 Sam James
2023-06-06 6:52 Sam James
2022-12-31 13:33 Sam James
2022-06-07 23:48 Mike Gilbert
2022-06-07 23:48 Mike Gilbert
2022-05-21 10:12 Michał Górny
2022-04-15 2:46 Sam James
2021-05-24 6:13 Zac Medico
2021-03-07 16:04 Zac Medico
2021-03-06 20:21 Zac Medico
2021-03-03 12:20 Zac Medico
2021-02-25 10:21 Zac Medico
2021-01-19 0:50 Zac Medico
2021-01-02 1:18 Zac Medico
2020-12-31 2:17 Zac Medico
2020-12-31 2:17 Zac Medico
2020-11-22 19:41 Zac Medico
2020-11-22 6:20 Zac Medico
2020-10-06 1:35 Zac Medico
2020-09-08 0:04 Zac Medico
2020-08-04 3:09 Zac Medico
2020-08-04 1:39 Zac Medico
2020-08-03 21:42 Zac Medico
2020-08-03 19:43 Ulrich Müller
2020-08-03 19:30 Zac Medico
2020-07-18 22:56 Zac Medico
2020-03-14 23:40 Zac Medico
2019-10-19 6:03 Zac Medico
2019-08-08 22:58 Zac Medico
2019-06-10 18:20 Zac Medico
2019-05-20 4:46 Zac Medico
2019-04-15 23:04 Zac Medico
2019-02-16 17:42 Robin H. Johnson
2019-02-16 16:48 Robin H. Johnson
2019-02-06 22:45 Zac Medico
2018-12-17 7:09 Zac Medico
2018-08-04 20:27 Zac Medico
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1707267346.fa8e8f1895ed889aece2f67725df55d6ccf127fb.zmedico@gentoo \
--to=zmedico@gentoo.org \
--cc=gentoo-commits@lists.gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox