From 7955b2ae94ef6da1a37147291fe542b365710a68 Mon Sep 17 00:00:00 2001 From: Leonid Usov Date: Tue, 17 Oct 2023 13:37:27 +0300 Subject: [PATCH] install/bin/stdin-killer: macOs (Darwin) compatibility Signed-off-by: Leonid Usov --- teuthology/task/install/bin/stdin-killer | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/teuthology/task/install/bin/stdin-killer b/teuthology/task/install/bin/stdin-killer index d5ff230b2..d1c9ba4ec 100755 --- a/teuthology/task/install/bin/stdin-killer +++ b/teuthology/task/install/bin/stdin-killer @@ -42,7 +42,7 @@ NAME = "stdin-killer" log = logging.getLogger(NAME) PAGE_SIZE = 4096 -POLL_HANGUP = select.POLLHUP | select.POLLRDHUP | select.POLLERR +POLL_HANGUP = select.POLLHUP | (select.POLLRDHUP if hasattr(select, 'POLLRDHUP') else 0) | select.POLLERR def handle_event(poll, buffer, fd, event, p): @@ -149,7 +149,17 @@ def listen_for_events(sigfdr, p, timeout): if __name__ == "__main__": signal.signal(signal.SIGPIPE, signal.SIG_IGN) - (sigfdr, sigfdw) = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) + try: + (sigfdr, sigfdw) = os.pipe2(os.O_NONBLOCK | os.O_CLOEXEC) + except AttributeError: + # pipe2 is only available on "some flavors of Unix" + # https://docs.python.org/3.10/library/os.html?highlight=pipe2#os.pipe2 + pipe_ends = os.pipe() + for fd in pipe_ends: + flags = fcntl.fcntl(fd, fcntl.F_GETFL) + fcntl.fcntl(fd, fcntl.F_SETFL, flags | os.O_NONBLOCK | os.O_CLOEXEC) + (sigfdr, sigfdw) = pipe_ends + signal.set_wakeup_fd(sigfdw) def do_nothing(signum, frame):